-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 target triple baked into compiler fails on musl #7196
Comments
Yes, it is. We just ask this from LLVM via the C API, which should be equivalent of running If you run that on that machine, what's the output? |
It doesn't. The LLVM default target triple is baked in too, and doesn't change at all when the binary is moved from machine to machine. LLVM is statically linked for the compiler binary, which is what we want. We need to do what C compilers have always done and have a |
@asterite I literally replaced the one occurence of |
I suggest defining a host triple in |
The issue is that " I think it shouldn't matter what target triple the compiler was built with, only what it's running on. This needs to read from the system environment like |
You're right, sorry. Both the host and default target need to be configurable. There's no way to read the host triple from the environment. It must be compiled-in. |
Having the host baked into the binary is usually not an issue, because most targets won't run on any other system anyway. Can't we just parse the output of |
I guess we can copy |
It would certainly be nice, but I don't think we currently need to identify all platforms. The relevant part for now is really just telling appart glibc and musl and that comes from evaluating |
I actually want to fix Crystal's target triple handing, so I'll assign myself. |
#7282 has been a great improvement but that alone doesn't bring us closer to solving this issue. What do you think about adding something along this to target = Crystal::Codegen::Target.new {{env("CRYSTAL_CONFIG_TARGET")}} || LLVM.default_target_triple
if target.linux?
musl_environment = `ldd --version`.starts_with?("musl")
if musl_environment && target.gnu?
return target.to_s.sub("-gnu", "-musl")
elsif !musl_environment && target.musl?
return target.to_s.sub("-musl", "-gnu")
end
end |
That it doesn't take |
In which sense? This snippet should work with |
Oh sorry, I misread. |
Linux builds of the Crystal compiler produced by crystal-lang/distribution-scripts (such as the ones provided for releases and nightlies) have a default target triple
x86_64-unknown-linux-gnu
. This seems to be hard coded into the binary.Binaries are statically linked and run as well on linux-gnu as on linux-musl. When running on Alpine however, this default target triple is incorrect and results in linker errors (e.g.
undefined reference to `errno'
). This makes it pretty much unusable. The correct target triple would bex86_64-alpine-linux-musl
. This can be mitigated by explicitly passing--cross-compile --target x86_64-alpine-linux-musl
, but that's not very user-friendly and doesn't work when running a crystal file as macro because the default target triple is used for compiling it.TL;DR The target triple should default to the system the compiler is running on. Because the same binary runs on linux-gnu and linux-musl it needs to detect which one to use.
The text was updated successfully, but these errors were encountered: