Skip to content

It’s possible to build optional dependencies not listed in Cargo.lock #3629

@SimonSapin

Description

@SimonSapin

Test case: (run in a temporary directory)

cargo new a
cd a
echo 'b = {path = "b"}' >> Cargo.toml
cargo new b
cd b
echo 'c = {path = "c", optional = true}' >> Cargo.toml
cargo new c
cd c
echo 'd = {path = "d"}' >> Cargo.toml
cargo new d
cd ..
cd ..
cargo build --features b/c --verbose
cat Cargo.lock
cd ..
rm -rf a

Output in cargo 0.17.0-nightly (67e4ef1 2017-01-25)

     Created library `a` project
     Created library `b` project
     Created library `c` project
     Created library `d` project
   Compiling d v0.1.0 (file:///tmp/lol/a/b/c/d)
     Running `rustc --crate-name d b/c/d/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=d1f001e6c4277757 -C extra-filename=-d1f001e6c4277757 --out-dir /tmp/lol/a/target/debug/deps -L dependency=/tmp/lol/a/target/debug/deps`
   Compiling c v0.1.0 (file:///tmp/lol/a/b/c)
     Running `rustc --crate-name c b/c/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=d3fb71d0c424d062 -C extra-filename=-d3fb71d0c424d062 --out-dir /tmp/lol/a/target/debug/deps -L dependency=/tmp/lol/a/target/debug/deps --extern d=/tmp/lol/a/target/debug/deps/libd-d1f001e6c4277757.rlib`
   Compiling b v0.1.0 (file:///tmp/lol/a/b)
     Running `rustc --crate-name b b/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="c"' -C metadata=bf9fdaf735940263 -C extra-filename=-bf9fdaf735940263 --out-dir /tmp/lol/a/target/debug/deps -L dependency=/tmp/lol/a/target/debug/deps --extern c=/tmp/lol/a/target/debug/deps/libc-d3fb71d0c424d062.rlib`
   Compiling a v0.1.0 (file:///tmp/lol/a)
     Running `rustc --crate-name a src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="b"' -C metadata=50db5a511b950de6 -C extra-filename=-50db5a511b950de6 --out-dir /tmp/lol/a/target/debug/deps -L dependency=/tmp/lol/a/target/debug/deps --extern b=/tmp/lol/a/target/debug/deps/libb-bf9fdaf735940263.rlib`
    Finished dev [unoptimized + debuginfo] target(s) in 2.22 secs
[root]
name = "a"
version = "0.1.0"
dependencies = [
 "b 0.1.0",
]

[[package]]
name = "b"
version = "0.1.0"

Crates c and d were compiled and used, but are not listed in Cargo.lock.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cliArea: Command-line interface, option parsing, etc.A-featuresArea: features — conditional compilationA-optional-dependenciesArea: dependencies with optional=trueC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions