Local dependency cannot be resolved

385 Views Asked by At

I know there is a similiar question right below this one but the answer does not solve my issue. I have a published package and would like to refer to it from another one. The dependency is defined locally (not git), however the build command returns 'Failed to build Move modules: "Unable to resolve packages for package 'Parent'".' thus I'm doing something wrong with the linking.

the project structure looks like this:

folder structure

Parent Move.toml

[package]
name = "Parent"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet-0.10.0" }
Child = { local = "child" }

[addresses]
parent = "0x0"
child = "0x08f5f5f4101e9c4b2d2b3f212b6e909b48acd02c"

Child Move.toml

[package]
name = "Child"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet-0.10.0" }

[addresses]
child =  "0x0"

foo.Move

module child::foo {
    use sui::tx_context::{TxContext};

    fun init(_: &mut TxContext) {}
    public fun test(): u8 {
        10
    }
}

bar.Move

module parent::bar {
    use sui::tx_context::{TxContext};
    use child::foo::{Self};
    
    fun init(_: &mut TxContext) {
        let value_from_child = foo::test();
     }
}

I am on Windows.

1

There are 1 best solutions below

3
On BEST ANSWER

The issue is that module child is bound to address 0x0 in package Child, but bound to your published address in package Parent. Currently, there are a couple of ways you could get things building.

1. Assign child the same address (its published address) in both packages:

(Recommended if Child is intended to be published in one place and then reused by everyone there)

./Move.toml

[package]
name = "Parent"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet-0.10.0" }
Child = { local = "child" }

[addresses]
parent = "0x0"
child = "0x08f5f5f4101e9c4b2d2b3f212b6e909b48acd02c"

./child/Move.toml

[package]
name = "Child"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet-0.10.0" }

[addresses]
child = "0x08f5f5f4101e9c4b2d2b3f212b6e909b48acd02c"

2. Assign child a placeholder address in Child and substitute it in Parent.

(Recommended if Child is a library that you expect to re-publish along with the packages that use it)

./Move.toml

[package]
name = "Parent"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet-0.10.0" }
Child = { local = "child", addr_subst = { "child" = "0x08f5f5f4101e9c4b2d2b3f212b6e909b48acd02c" } }

[addresses]
parent = "0x0"

./child/Move.toml

[package]
name = "Child"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet-0.10.0" }

[addresses]
child = "_"