Skip to content

crate-type = ["staticlib"] prevents build metadata from being passed #4814

@Twey

Description

@Twey

It appears that marking a crate as crate-type = ["staticlib"] causes the dependency metadata generated by the package to be dropped on the floor.

[twey@uruz:/tmp/mwe]$ find . -type f | while read -r i; do echo $i; cat $i; echo ---; done
./bar/Cargo.toml
[package]
name = "bar"
version = "0.1.0"
authors = []

[dependencies]
foo = {path = "../foo"}
---
./bar/src/lib.rs
---
./bar/build.rs
fn main() {
    let _ = std::env::var("DEP_FOO_INCLUDE").unwrap();
}
---
./foo/Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = []
links = "foo"

[lib]
crate-type = ["staticlib"]
---
./foo/src/lib.rs
---
./foo/build.rs
fn main() {
    println!("cargo:include=foo_include");
}
---

Attempting to build this gives:

[twey@uruz:/tmp/mwe]$ cargo --version
cargo 0.25.0-nightly (930f9d949 2017-12-05)
[twey@uruz:/tmp/mwe/bar]$ cargo build --verbose
   Compiling bar v0.1.0 (file:///tmp/mwe/bar)
   Compiling foo v0.1.0 (file:///tmp/mwe/foo)
     Running `rustc --crate-name build_script_build build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=9d7440d88b76b1df -C extra-filename=-9d7440d88b76b1df --out-dir /tmp/mwe/bar/target/debug/build/bar-9d7440d88b76b1df -L dependency=/tmp/mwe/bar/target/debug/deps`
     Running `rustc --crate-name build_script_build /tmp/mwe/foo/build.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=1989f1c3f6a74e80 -C extra-filename=-1989f1c3f6a74e80 --out-dir /tmp/mwe/bar/target/debug/build/foo-1989f1c3f6a74e80 -L dependency=/tmp/mwe/bar/target/debug/deps`
     Running `/tmp/mwe/bar/target/debug/build/foo-1989f1c3f6a74e80/build-script-build`
     Running `rustc --crate-name foo /tmp/mwe/foo/src/lib.rs --crate-type staticlib --emit=dep-info,link -C debuginfo=2 -C metadata=a8d8421aee24b709 -C extra-filename=-a8d8421aee24b709 --out-dir /tmp/mwe/bar/target/debug/deps -L dependency=/tmp/mwe/bar/target/debug/deps`
     Running `/tmp/mwe/bar/target/debug/build/bar-9d7440d88b76b1df/build-script-build`
error: failed to run custom build command for `bar v0.1.0 (file:///tmp/mwe/bar)`
process didn't exit successfully: `/tmp/mwe/bar/target/debug/build/bar-9d7440d88b76b1df/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotPresent', /checkout/src/libcore/result.rs:916:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed

But after commenting out the crate-type line this project builds fine.

A tarball of this MWE can be found here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsA-crate-typesArea: crate-type declaration (lib, staticlib, dylib, cdylib, etc.)S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions