cargo-contract icon indicating copy to clipboard operation
cargo-contract copied to clipboard

Building a contract fails if contract is referenced through symlink

Open cmichi opened this issue 4 years ago • 2 comments

Can be reproduced like this:

$ cargo contract new foo
        Created contract foo
$ ls
foo
$ ln -s foo link_to_foo
$ ls
foo  link_to_foo
$ cargo +nightly contract build --manifest-path=link_to_foo/Cargo.toml
...
 [3/5] Optimizing wasm file
ERROR: The workspace root package should be a workspace member

Expected behavior is that the contract builds without error.

The workaround is to cd link_to_foo && cargo +nightly contract build.

cmichi avatar Apr 13 '21 14:04 cmichi

i haven't looked into this issue, but i experienced similar doing this line that was able to support symlinks https://github.com/paritytech/substrate/blob/master/docker/build.sh#L6, so now i use it all the time https://github.com/ltfschoen/InkTemplate/blob/main/docker/quickstart.sh#L8

ltfschoen avatar May 28 '23 21:05 ltfschoen

i just reproduced it the way you did but got a longer error:

ERROR: Error invoking `cargo metadata` for link_to_foo/Cargo.toml

Caused by:
    `cargo metadata` exited with an error: error: current package believes it's in a workspace when it's not:
    current:   /opt/cargo-contract/link_to_foo/Cargo.toml
    workspace: /opt/cargo-contract/Cargo.toml
    
    this may be fixable by adding `link_to_foo` to the `workspace.members` array of the manifest located at: /opt/cargo-contract/Cargo.toml
    Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.

so might work if add it with the following in outer Cargo.toml:

members = ["crates/*", "link_to_foo/"]

and run with

cargo +nightly contract build --manifest-path=link_to_foo/Cargo.toml

as long as versions match

ltfschoen avatar May 28 '23 23:05 ltfschoen