Skip to content

#![cfg_attr(not(test), no_std)] doesn't work when building multiple crate-types #48665

Open
@glandium

Description

@glandium
$ cargo create --lib foo
$ cd foo
$ cat >> Cargo.toml <<EOF
[lib]
crate-type = ["rlib", "staticlib"]
[profile.dev]
panic="abort"
EOF
$ cat > src/lib.rs <<EOF
#![cfg_attr(not(test), no_std)]
#![feature(lang_items)]

#[cfg(not(test))]
#[lang = "panic_fmt"]
#[no_mangle]
pub fn panic_fmt(_: core::fmt::Arguments, _: &'static str, _: u32, _: u32) -> ! {
    loop {}
}
EOF
$ cargo +nightly build
   Compiling foo v0.1.0 (file:///tmp/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.13 secs
$ cargo +nightly test
   Compiling foo v0.1.0 (file:///tmp/foo)
error: language item required, but not found: `eh_personality`

error: aborting due to previous error

That is an error that is expected with no_std, but the code is supposed to be essentially empty in the test configuration.

It works when crate-type contains only one value (either one).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions