-
Notifications
You must be signed in to change notification settings - Fork 13
Description
UPDATE (7th Oct 2024):
- For build reproductions of static glibc, musl, eyra (with "hello world" std and
no_stdexamples) a revised unified reference example can be found at: docs:hello-world-smallexample size update #50 - Extracted to separate issues from discussions in this issue:
- Reducing
no_stdadditions specific to eyra forpanic = "abort"usage via theunwindingcrate (avoid theeh_personalityrequirement)
- Reducing
libc + no_std:
Unlike the static no_std example below, the revised variant instead avoids the libc crate calls - which removes the need for glibc/musl targets to include:
// Uses the internal rust libc (glibc/musl) for static builds instead? For this to work:
// - `Cargo.toml` should not have a `libc` dependency specified.
// - Do not build std via the `-Z build-std=std` option, which would replace the prebuilt private copy.
#![feature(rustc_private)]
extern crate libc;Alternatively with cargo add libc --no-default-features instead you do not need those two lines in src/main.rs.
With libc crate in Cargo.toml, now -Z build-std will be compatible to build with (redundant for no_std?), but doing so requires additional RUSTFLAGS depending on glibc or musl target (just like the above linked revised no_std example):
--target x86_64-unknown-linux-gnuwill need:-C link-arg=/usr/lib64/libc.a -C link-arg=/usr/lib/gcc/x86_64-redhat-linux/14/libgcc_eh.a. These locations for*.astatic libs are specific to Fedora 41 from theglibc-staticpackage.- Alternatively could be expressed as
-L /usr/lib64 -L link-arg=/usr/lib/gcc/x86_64-redhat-linux/14 -C link-arg=-lgcc_eh(-C link-arg=-lcis implicit fromlibccrate?). The-Lhints don't seem necessary in this case,-C link-arg=-lgcc_ehalone works.
--target x86_64-unknown-linux-muslwill need-C link-arg=-lcwhich pairs with the implicit-C link-self-contained=yesfor this target (without=yesthat-lcmay unintentionally dynamically link the host libc library, update: may vary by environment/linker?).
NOTE: Related to these caveats for libc usage, if considering the optimizations detailed in the sunfishcode/origin tiny example README, the -N / --omagic link arg introduces a segfault with -musl target and the implicit -C link-self-contained=yes, but not when set to =no explicitly (or using -Z build-std which has roughly the same effect).
Original message
I am used to building with the *-musl target, but noticed that eyra is not compatible (default hello world example generated from cargo init).
--target :
- ✔️
x86_64-unknown-linux-gnu - ❌
x86_64-unknown-linux-musl
I know the README clarifies the support constraints to linux, but doesn't highlight the -gnu vs -musl target compatibility? I didn't think it would matter with eyra?
Might be worthwhile to convey that incompatibility in the README too?
Reproduction
$ cargo init
$ cargo add eyra
# Prepend to `src/main.rs`:
$ echo 'extern crate eyra;' | cat - src/main.rs | sponge src/main.rs
# Build with `*-musl` target (fail):
$ RUSTFLAGS="-C link-arg=-nostartfiles -C relocation-model=static -C target-feature=+crt-static" cargo +nightly build --target x86_64-unknown-linux-musl --release
# Build with `*-gnu` target (success):
$ RUSTFLAGS="-C link-arg=-nostartfiles -C relocation-model=static -C target-feature=+crt-static" cargo +nightly build --target x86_64-unknown-linux-gnu --releaseSome error messages from -musl target attempt:
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/c-scape-0.15.23/src/use_libc.rs:22:17
|
22 | core::mem::transmute(crate::use_libc::Pad::new(core::ptr::read(src_ptr)));
| ^^^^^^^^^^^^^^^^^^^^
|
::: /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/c-scape-0.15.23/src/thread/mod.rs:653:44
|
653 | libc!(libc::pthread_rwlockattr_destroy(checked_cast!(_attr)));
| -------------------- in this macro invocation
|
= note: source type: `Pad<PthreadRwlockattrT>` (128 bits)
= note: target type: `Pad<pthread_rwlockattr_t>` (96 bits)
= note: this error originates in the macro `checked_cast` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/c-scape-0.15.23/src/time/mod.rs:104:33
|
104 | libc!(libc::gettimeofday(t, _tz));
| ------------------ ^^^ expected `*mut c_void`, found `*mut timezone`
| |
| arguments to this function are incorrect
|
= note: expected raw pointer `*mut c_void`
found raw pointer `*mut timezone`
note: function defined here
--> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.150/src/unix/linux_like/linux/musl/mod.rs:740:12
|
740 | pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
Potentially related to?:
libccrate musl compatibility (may be resolved forlibc 0.3release)-C link-arg=-nostartfileson musl target