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

Default musl compiler binary names are dodgy #105

Closed
raphaelcohn opened this issue Oct 3, 2016 · 9 comments
Closed

Default musl compiler binary names are dodgy #105

raphaelcohn opened this issue Oct 3, 2016 · 9 comments

Comments

@raphaelcohn
Copy link

raphaelcohn commented Oct 3, 2016

An installation of musl does not supply a musl-g++, but this crate assumes that it exists for C++ code. This is a bit a of a quandry to solve. It also assumes things like musl-gcc exist, which isn't really true unless musl has been installed alongside glibc on an existing system as a system compiler - not a cross compiler. Since most build.rs scripts are often targeting a cross-compilation, rather than deployment on the host (especially so if --target has been passed to cargo), using a reference to the system compiler seems wrong.

A slightly better approach might be to support the names used by musl-cross-make, eg x86_64-linux-musl-cc. This allows installation of multiple copies of musl targeting gcc (or clang) at different architectures to co-exist. These names are also the ones available by default if installing musl-cross-make on Mac OS X using Homebrew (https://github.com/FiloSottile/homebrew-musl-cross/)

Sadly, it's very difficult trying to overcome the mess of C compilation, and particularly C cross compilation using gcc, which doesn't understand how to compile for more than target. We're also trying to accommodate scenarios ranging from install and run locally to deployment. Personally, I'd make cross compilation my primary focus, and make local install and run secondary; that way, when cross compilation's sorted, local install should just work. This is the approach taken by most from-scratch toolchains and the like (eg Linux from Scratch).

@raphaelcohn
Copy link
Author

Actually, could the name of the compiler used default to that in Cargo's --target eg via TARGET?

@alexcrichton
Copy link
Member

Thanks for the report! In general all the compiler names used in this crate are dodgy as none of them are verified to exist, they're just hopefully a reasonable set of defaults. I've seen musl-gcc as being more common than other musl compilers, but that's just my own personal experience! Where does the x86_64-linux-musl-cc compiler come from?

Also, it should be noted that these are just attempts at being reasonable defaults. That is, it's expected they're ~60% accurate which is better than the 0% accurate cc at least! In other words, the compiler should always be very easily overridable via a number of means.

@pmarks
Copy link

pmarks commented Nov 11, 2016

I'm hitting a similar issue. My project depends on flate2. Compiling with cargo build --release --target x86_64-unknown-linux-musl

yields:
failed to execute command: No such file or directory (os error 2)
Is musl-gcc not installed?`

Should a musl installation always be required if any dependent projects does a gcc compile? Or should the gcc crate & musl toolchain should handle this automatically?

@alexcrichton
Copy link
Member

@pmarks ah yeah to compile code for musl you'll need musl-gcc installed locally. The gcc crate doesn't currently manage toolchains, but do you have the musl toolchain and the gcc crate isn't detecting it?

@pmarks
Copy link

pmarks commented Nov 11, 2016

@alexcrichton i tried initially without musl-gcc installed. After I installed musl-gcc it worked.

It might be worth a disclaimer on the musl toolchain that musl-gcc is required if you have any dependencies w/ C code / build.rs steps.

@alexcrichton
Copy link
Member

Certainly yeah! Makes sense to me

@Roba1993
Copy link

Hi guys,

what about musl-g++ ? I use clux/muslrust to cross-compile everything so far. But for muja/unrar.rs which depends on a c++ library I got the error, that must-g++ is not available.

As far as I know, there is not special musl-g++ compiler... Just the gcc one. Has someone done something like this already?

Thanks,
Robert

@alexcrichton
Copy link
Member

I'm going to close this since the default binary names are basically always just best-effort. PRs to improve the logic are always welcome but otherwise it's typically common to have to configure the name anyway since there's so many names for C compilers.

@Timmmm
Copy link

Timmmm commented Feb 7, 2022

I ran into the exact same issue as @archseer when trying to cross-compile Tree-Sitter.

See this for the solution.

In my experience x86_64-linux-musl-gcc is a pretty standard name for the cross-compiler. It's used by that compiler, and also the ones at https://musl.cc/. Can we just change the "musl"s in prefix_for_target() to "x86_64-linux-musl" and so on?

Timmmm added a commit to Timmmm/cc-rs that referenced this issue Feb 7, 2022
Timmmm added a commit to Timmmm/cc-rs that referenced this issue Feb 7, 2022
This should fix cross-compilation to musl when you haven't manually set the compiler name. It's also more consistent with the existing musl targets (e.g. mips).

See rust-lang#105 and https://github.com/FiloSottile/homebrew-musl-cross#:~:text=If%20you%20encounter%20issues
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

5 participants