nervosnetwork / capsule

Capsule is an out-of-box development framework for creating smart contract on Nervos' CKB.
MIT License
60 stars 34 forks source link

The setting of .cargo/config.toml is not used #148

Closed XuJiandong closed 5 months ago

XuJiandong commented 5 months ago
  1. capsule new a project

  2. set a wrong .cargo/config for this project. Like following:

    ❯ cat contracts/test-cargo-config/.cargo/config.toml
    [target.riscv64imac-unknown-none-elf]
    rustflags = [
    "-C", "target-feature=-a0000"
    ]

    This config is wrong: there is no such target-feature.

  3. run capsule build. There is no error output. Some error like this should appear:

    '-a0000' is not a recognized feature for this target (ignoring feature)

    It seems that .cargo/config.toml isn't used.

blckngm commented 5 months ago

Is contracts/test-cargo-config the direcotry for the member crate? It should work if you put the .cargo dir in project/workspace root.

XuJiandong commented 5 months ago

It works if .cargo dir is moved to the root. But this will affect all projects.

blckngm commented 5 months ago

I think it's just how cargo works, i.e. .cargo/config.toml in a member crate dir is ignored unless you run cargo from the particular dir.

XuJiandong commented 5 months ago

https://doc.rust-lang.org/cargo/reference/config.html

At present, when being invoked from a workspace, Cargo does not read config files from crates within the workspace. i.e. if a workspace has two crates in it, named /projects/foo/bar/baz/mylib and /projects/foo/bar/baz/mybin, and there are Cargo configs at /projects/foo/bar/baz/mylib/.cargo/config.toml and /projects/foo/bar/baz/mybin/.cargo/config.toml, Cargo does not read those configuration files if it is invoked from the workspace root (/projects/foo/bar/baz/).

It's possible that the cargo command(or cross) isn't invoked in proper directory. In a capsule project, there are multiple script projects whichs don't share config.toml.