houseabsolute / actions-rust-cross

GitHub Action to compile Rust with cross
Apache License 2.0
111 stars 12 forks source link

Unable to find 'musl-g++' on 'x86_64-unknown-linux-musl' target #22

Open RaulTrombin opened 1 month ago

RaulTrombin commented 1 month ago

Hello guys, I'm having some issues building the musl version for linux amd64 target.

warning: tracy-client-sys@0.24.0: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is musl-g++ installed? details

On my computer it works fine with: cross build --release --target="x86_64-unknown-linux-musl"

Any ideas?

autarch commented 1 month ago

Are you using the latest version of this action? I just updated it to install the musl-tools package when this is needed.

RaulTrombin commented 1 month ago

Hi @autarch , thks for fast reply,

in fact it's installing the musl-tools, line where it happens image

I'm using the relase: "v0.0.14 - Install musl-tools if needed" Other musl targets ( armv7, aarch64 ) worked fine.

autarch commented 1 month ago

I spent some time trying to find a solution for this, but I'm a bit stuck. I've tried the following:

Make a musl-g++ symlink to musl-gcc

This doesn't work because the musl-dev package doesn't include C++ headers, only C. So the build gets slightly further but then fails because it can't load the headers it needs.

Install a toolchain from https://musl.cc

This includes the C++ headers, but it's missing libraries that are needed, so it ends up with an error like this:

/opt/x86_64-linux-musl-native/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so: error loading plugin: Dynamic loading not supported

I think the best fix would be for the Ubuntu musl-dev package to include C++ headers. There's a bug report requesting this for the Debian package, but it's from 2021 and there hasn't been any response to it.

RaulTrombin commented 1 month ago

I spent some time trying to find a solution for this, but I'm a bit stuck. I've tried the following:

Make a musl-g++ symlink to musl-gcc

This doesn't work because the musl-dev package doesn't include C++ headers, only C. So the build gets slightly further but then fails because it can't load the headers it needs.

Install a toolchain from https://musl.cc

This includes the C++ headers, but it's missing libraries that are needed, so it ends up with an error like this:

/opt/x86_64-linux-musl-native/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so: error loading plugin: Dynamic loading not supported

I think the best fix would be for the Ubuntu musl-dev package to include C++ headers. There's a bug report requesting this for the Debian package, but it's from 2021 and there hasn't been any response to it.

Hmmm, maybe we could try something like they did on cross-rs's dockers images? Seems they have a workaround for the c++ missing headers here: https://github.com/cross-rs/cross/blob/d8631fe4f4e8bb4c4b24417a35544857fb42ee22/docker/musl-symlink.sh#L54

autarch commented 4 weeks ago

I gave it a shot using something based on the cross script, but then I encountered even more issues where the compiler couldn't find C++ header, for example for #include <algorithm>. I gave up at this point but I pushed a branch with my work in progress named musl-g++ if you're interested in working on this.

autarch commented 2 weeks ago

I dug into this more and found this project - https://github.com/musl-cross/musl-cross

If I make a musl-g++ symlink to the x86_64-multilib-linux-musl-g++ binary it provides, then compilation succeeds. However, it has a dynamic link to libstc++.so and it segfaults at runtime because it seems like the default libstdc++.so is incompatible with the binary that gets compiled.

I tried to figure out how to get it to statically link the libstdc++.a provided by musl-cross instead, but I really don't understand C or C++ compilation all that well, and having to filter this all through directives emitted by the build.rs left me pretty confused.

So while I think making this all work is possible, I'm a bit lost at how to do so for now.