Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: allow static linking to libasound #10

Open
ssssam opened this issue Nov 2, 2021 · 7 comments
Open

Feature request: allow static linking to libasound #10

ssssam opened this issue Nov 2, 2021 · 7 comments

Comments

@ssssam
Copy link

ssssam commented Nov 2, 2021

I am trying to build an embedded audio project using cpal, alsa-rs and alsa-sys. The target OS has an old GLibc and it might be tricky to upgrade. Building a static linked binary would be ideal.

At present alsa-sys hardwires statik(false) in build.rs so there's no way to static link.

I experimented with changing this to static(true) and building with armv7-unknown-linux-musleabihf toolchain. Something goes wrong with the link at this point, and various link errors appear like these:

  = note: /home/sam/src/organelle-ports-musl/output/host/lib/gcc/arm-buildroot-linux-musleabihf/10.3.0/../../../../arm-buildroot-linux-musleabihf/bin/ld: /home/sam/src/alsa-rs/synth-example/target/armv7-unknown-linux-musleabihf/debug/deps/libalsa_sys-aae2be964235592b.rlib(conf.o): in function `config_file_load':
          conf.c:(.text+0x4fa0): undefined reference to `__stat_time64'
          /home/sam/src/organelle-ports-musl/output/host/lib/gcc/arm-buildroot-linux-musleabihf/10.3.0/../../../../arm-buildroot-linux-musleabihf/bin/ld: /home/sam/src/alsa-rs/synth-example/target/armv7-unknown-linux-musleabihf/debug/deps/libalsa_sys-aae2be964235592b.rlib(conf.o): in function `snd_config_update_r':
          conf.c:(.text+0xc130): undefined reference to `__stat_time64'
          /home/sam/src/organelle-ports-musl/output/host/lib/gcc/arm-buildroot-linux-musleabihf/10.3.0/../../../../arm-buildroot-linux-musleabihf/bin/ld: /home/sam/src/alsa-rs/synth-example/target/armv7-unknown-linux-musleabihf/debug/deps/libalsa_sys-aae2be964235592b.rlib(pcm_dmix.o): in function `snd_pcm_dmix_status':
          pcm_dmix.c:(.text+0xe0c): undefined reference to `__clock_gettime64'

I experimented with adding -lc or removing -nodefaultlibs from the generated linkline and got other errors suggesting double linking against libc.

This is the limit of my expertise, just reporting the issue in case someone else has been looking into the same thing.

@diwic
Copy link
Owner

diwic commented Nov 2, 2021

@ssssam
Copy link
Author

ssssam commented Nov 2, 2021

Thanks for the pointer! This suggests that changing .statik(true) should just work, and something about my toolchain / sysroot is broken.

I am building with Buildroot 2021.08, which has Musl 1.22 and Rust 1.54. I have just spotted that Buildroot doesn't build the rust-std libraries itself, it downloads them from https://static.rust-lang.org/dist/rust-std-1.54.0-armv7-unknown-linux-musleabihf.tar.xz and looking at the contained liblibc-e1ae72f87d6a487b.rlib file, this might indeed contain a statically linked copy of Musl 1.1.

In which case, while alsa-sys could add support for static linking now, it might not be useful until rust-lang/rust#72274 is completed.

@diwic
Copy link
Owner

diwic commented Nov 3, 2021

Feel free to add a PR that adds support for static linking, I suppose this would be implemented as a feature not enabled by default?

@ssssam
Copy link
Author

ssssam commented Nov 4, 2021

Right, I wasn't sure how to do this, but a feature flag makes sense. When I get some time I will do a PR.

@cybersoulK
Copy link

cybersoulK commented Sep 6, 2023

@ssssam @diwic does this mean that i cannot manually compile alsa lib on an ubuntu machine and link it with cargo-zigbuild on my mac??
I have been trying for days to make it work. and it compiles and links successfuly, just to segfault on my players...

(the target is x86_64-unknown-linux-gnu)

@AnthonyMichaelTDM
Copy link

any updates on this?

AnthonyMichaelTDM added a commit to AnthonyMichaelTDM/mecomp that referenced this issue Jun 21, 2024
abandon trying to compile to musl, the alsa-sys crate does not support static linking so that's a bust diwic/alsa-sys#10
@diwic
Copy link
Owner

diwic commented Jun 21, 2024

@AnthonyMichaelTDM Not to my knowledge. The other binding I maintain - https://github.com/diwic/dbus-rs - someone contributed a way to download the libdbus C code and cross compile it with the rest of the code. That might be an option here as well, if someone wants to do the work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants