Skip to content

cargo check --examples shouldn't link binaries #4529

Closed
@japaric

Description

@japaric

I believe.

cargo check on a binary crate doesn't do the linking step so I think examples shouldn't be linked either.

STR

$ cargo new --bin hello && cd $_

$ mkdir .cargo && cat >.cargo/config <<EOF
[target.x86_64-unknown-linux-gnu]
linker = "false"
EOF

$ cargo check -v && echo OK
   Compiling hello v0.1.0 (file:///home/arch/tmp/hello)
     Running `rustc --crate-name hello src/main.rs --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=20d2e2d706bd0a6e -C extra-filename=-20d2e2d706bd0a6e --out-dir /home/arch/tmp/hello/target/debug/deps -C linker=false -L dependency=/home/arch/tmp/hello/target/debug/deps`
    Finished dev [unoptimized + debuginfo] target(s) in 0.28 secs
OK

$ mkdir examples && cp src/main.rs examples/foo.rs

$ cargo check --examples -v
   Compiling hello v0.1.0 (file:///home/arch/tmp/hello)
     Running `rustc --crate-name foo examples/foo.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=774cc6e534532462 -C extra-filename=-774cc6e534532462 --out-dir /home/arch/tmp/hello/target/debug/examples -C linker=false -L dependency=/home/arch/tmp/hello/target/debug/deps`
error: linking with `false` failed: exit code: 1

That example is contrived. My use case is cross cargo checking: cargo check --examples --target arm-unknown-linux-gnueabi.

Meta

$ rustc -V
rustc 1.22.0-nightly (0701b37d9 2017-09-18)

(Apologies if this has already been reported / fixed; I didn't look too hard)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions