Skip to content

--crate-type does not override lib properties on manifest #6160

Closed
@bltavares

Description

@bltavares

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions