diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index 8ed2b7dac..1ad435fad 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -48,6 +48,16 @@ jobs: - name: Compile without the standard library run: cargo clean && cargo +nightly build -Zbuild-std=core,alloc --no-default-features + musl-rust-lld-link-test: + runs-on: ubuntu-latest + # This test checks if binaries using libloading can be linked using rust-lld linker for target environments that + # provide a unified libc (e.g. musl) without needing to provide additional library paths to the linker. + steps: + - uses: actions/checkout@v4 + - run: rustup install stable --profile=minimal + - run: rustup target add x86_64-unknown-linux-musl + - run: RUSTFLAGS="-Clinker=rust-lld" cargo build --target=x86_64-unknown-linux-musl --example e1 + windows-test: runs-on: windows-latest strategy: diff --git a/examples/e1.rs b/examples/e1.rs new file mode 100644 index 000000000..f5235a499 --- /dev/null +++ b/examples/e1.rs @@ -0,0 +1,5 @@ +fn main() { + unsafe { + libloading::Library::new("libc.so").unwrap(); + } +} diff --git a/src/os/unix/mod.rs b/src/os/unix/mod.rs index d727c622f..529bb1d5f 100644 --- a/src/os/unix/mod.rs +++ b/src/os/unix/mod.rs @@ -479,7 +479,14 @@ impl fmt::Debug for Symbol { } // Platform specific things -#[cfg_attr(any(target_os = "linux", target_os = "android"), link(name = "dl"))] +#[cfg_attr( + any( + all(target_os = "linux", not(target_env = "musl")), + target_os = "android" + ), + link(name = "dl") +)] +#[cfg_attr(all(target_os = "linux", target_env = "musl"), link(name = "c"))] #[cfg_attr(any(target_os = "freebsd", target_os = "dragonfly"), link(name = "c"))] extern "C" { fn dlopen(