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.
AFAIK, your target platform needs to have the rust-srccomponent present for Cargo to be able to build the standard library from source. According to rustup, the rust-src component is not available for thumbv7em-none-eabi.