Cargo flags `-zbuild-std=core,alloc` and rustc flag `--crate-type=staticlib` incompatible?

⚓ Rust    📅 2025-08-13    👤 surdeus    👁️ 2      

surdeus

I would like to specify crate type on the command line because I need to use the crate both as a c-lib and a rust-lib. However, I also cross-compile and I want to compile core/alloc.

How can I do this?

I get the following compilation error:

cargo rustc -Zbuild-std=core,alloc -Zbuild-std-features=optimize_for_size --target=thumbv7em-none-eabi -- --crate-type=staticlib
   Compiling foo v0.1.0 (/Users/niklas/projects/niklas/test-crate-type/foo)
error: crate `core` required to be available in rlib format, but was not found in this form

error: crate `compiler_builtins` required to be available in rlib format, but was not found in this form

error: could not compile `foo` (lib) due to 2 previous errors

My test-crate only contains:

#![no_std]

use core::panic::PanicInfo;

pub fn add(left: u64, right: u64) -> u64 {
    left + right
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

Using crate-type = ["staticlib"] in the toml-file works fine.

4 posts - 2 participants

Read full topic

🏷️ Rust_feed