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

Cross compiling for Darwin selects incorrect linker flags #386

Open
vinistock opened this issue Sep 10, 2024 · 0 comments
Open

Cross compiling for Darwin selects incorrect linker flags #386

vinistock opened this issue Sep 10, 2024 · 0 comments

Comments

@vinistock
Copy link

vinistock commented Sep 10, 2024

When configuring to cross compile darwin-x86 -> darwin-aarch64 or darwin-aarch64 -> darwin-x86, toolchains_llvm seems to be selecting some linker flags that prevent compilation. I'm working to support cross compilation on Sorbet (here's the PR sorbet/sorbet#8162).

First, the documentation says that when cross compiling it will try to use libstdc++ instead of libc++. However, that leads to an error telling the developer to switch to using libc++. There's some more context in this forum answer where they say libstdc++ is deprecated for MacOS.

I was able to move further by setting stdlib=libc++, but then on this line we enter the else statement because is_xcompile is true. Linking will then fail saying that hash-style, build-id and z are unknown arguments to the linker.

After patching that part to not enter the else statement, it then fails further down because it always sets stdlib to be stdc++ when cross compiling, which adds another incompatible linker flag.

After patching that spot, then I was able to cross compile darwin-arm64 -> darwin-x86. We put our patches in sorbet#10 because I don't know what the general solution would be, but it does get Sorbet to build and produces a valid x86 binary.

Note

If you check the PR on Sorbet, you'll see that I added the MacOS SDK as a local repository to be able to give the llvm_toolchain definition a sysroot, enabling me to cross compile.

I'm not sure if that's the intended approach. It feels a bit weird given that it's the same SDK and I would assume the regular toolchain already has that configured somewhere. Please, let me know if I'm setting up something wrong.

It would be nice to add examples of how to configure cross compilation on Darwin to the documentation. If the approach is considered to be correct, then we can contribute some docs.

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

1 participant