-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
I've faced this recently, and I was surprised by the --crate-type flag behavior. I'm trying to work on a cross-platform library building script to be added on projects on crossgen and it would be really nice if we could contain all the cross-platform bits on the build script.
The Cargo.toml was a default --lib project:
[project]
name = "example"
version = "0.0.1"
[lib]
[dependencies]When compiling with cargo rustc --lib --release -- --crate-type staticlib I expected this to take over the manifest and add the extra output type. To my surprise, no libexample.a was produced tho.
During the experiments, passing in an invalid crate type as RUSTFLAGS seems to show that cargo is passing multiple --crate-type options down to rustc:
$ RUSTFLAGS="--crate-type example" cargo rustc --lib --release
error: failed to run `rustc` to learn about target-specific information
Caused by:
process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --crate-type example --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)
--- stderr
error: unknown crate type: `example`
Should the --crate-type override what is defined on cargo manifest? Is this something to add on the cargo rustc argument list instead of the other side of --?
This would help a lot to output different targets, such as C libs and wasm.
There are related issues: