-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Re-do the FreeBSD cross-builds to use Clang and libc++. Fixes #44433 #46941
Conversation
The main goal here is to use FreeBSD's normal libc++, instead of statically linking the libstdc++ packaged with GCC, because that libstdc++ has bugs that cause rustc to deadlock inside LLVM. But the easiest way to use libc++ is to switch the build from GCC to Clang, and the Clang package in the Ubuntu image already knows how to cross-compile (given a sysroot and preferably cross-binutils), so the toolchain script now uses that instead of building a custom compiler. This also de-duplicates the `build-toolchain.sh` script.
The code inside this conditional will not work on FreeBSD 10+ because those versions use clang and libc++ rather than libstdc++. Since FreeBSD comes with libc++ in the base, presumably all 10+ systems will have it present. Searching for libstdc++.a will not work if it is not present. As a result, this would previously have set `LLVM_STATIC_STDCPP=libstdc++.a`, which isn't a valid path and caused problems later on when building `librustc_llvm`. This could possibly be updated in the future to look for `libc++.a` on FreeBSD, by expanding the code inside the conditional. In one attempt to run this on x86_64-freebsd, I found that libc++ was not compiled with PIC, so it failed anyway.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks! The main reason for linking the C++ standard library was more ABI compatibility in the sense that we can work with any number of Linux systems without worrying about the version of the C++ standard library they have installed (aka one less dependency for rustc-the-executable). Maybe that's not an issue with FreeBSD though? We're already not binary-compatible across major releases and it could be that within a release there's only one version of libc++? |
I very much appreciate any guidance, thank you.
Since
I really don't know much about FreeBSD, so I tried to investigate this. It looks like within a major release of FreeBSD, compatibility is important. So 10.3 to 10.4 should be fine. But jumping to 11.x would not be. So as-is, the results of this PR would presumably work fine with FreeBSD 10.{3+}. But it might not work for FreeBSD 11+? So with the strategy here of NOT using Alternatively, we can figure out how to statically link So the desire would be to statically link As noted earlier, I attempted statically linking The important bits of the error were:
This seems to indicate that the So we need to also compile Does this sound correct? I don't immediately know how to do this but I can continue to work on it. Mainly I'd like to find some confidence that I am at least on the right track. |
After looking into this a bit, it seems like it would be very difficult to compile anything from FreeBSD sources on the Ubuntu build machine without doing it in a virtual machine. Maybe first we should try testing the dist artifacts this current PR produces? I have a |
@ScottAbbey oh I wouldn't worry too much about compatibility, the ABI of functions like In that case though sounds like we should get this in to test it, and then we can evaluate what to do next! @bors: r+ |
📌 Commit b989428 has been approved by |
⌛ Testing commit b989428 with merge 8944069f8e3f0e26228d5bc3895700c22afd466b... |
💔 Test failed - status-travis |
⌛ Testing commit b989428 with merge f177bd0b40458df86eb249781f098a8a89efaab5... |
💔 Test failed - status-travis |
⌛ Testing commit b989428 with merge f84089f6757cd5104b731c8a813eafcac4257ae2... |
💔 Test failed - status-travis |
Re-do the FreeBSD cross-builds to use Clang and libc++. Fixes #44433 Reviving #45077, from @jld: > The main goal here is to use FreeBSD's normal libc++, instead of > statically linking the libstdc++ packaged with GCC, because that > libstdc++ has bugs that cause rustc to deadlock inside LLVM. > > But the easiest way to use libc++ is to switch the build from GCC to > Clang, and the Clang package in the Ubuntu image already knows how to > cross-compile (given a sysroot and preferably cross-binutils), so the > toolchain script now uses that instead of building a custom compiler. > > This also de-duplicates the build-toolchain.sh script. #45077 was close but didn't quite make it. I rebased @jld's work off the current `master` and started with that. I was able to determine that this Travis error (#45077 (comment)) was ultimately caused by `src/librustc_llvm/build.rs` attempting to follow a wrong value in `LLVM_STATIC_STDCPP` (#45077 (comment)). I looked at the downstream port for FreeBSD (https://svnweb.freebsd.org/ports/head/lang/rust/) and it seems like they do not use `--enable-llvm-static-stdcpp`. Since `libc++` is included in the FreeBSD 10+ base system, we don't need to statically link it either? So in b989428 I have set the FreeBSD build to not actually use `LLVM_STATIC_STDCPP`. I was able to run `./src/ci/docker/run.sh` with both `dist-i686-freebsd` and `dist-x86_64-freebsd` successfully and in about 1 minute of testing it seemed like the dist-x86_64-freebsd results worked on a FreeBSD 11 system. It should fix #44433, which seems to be affecting many potential users. Also FreeBSD users should be able to `./x.py build` which should help anyone who wants to upstream fixes for FreeBSD. Questions: Does this approach seem to be the right way to go? Do we actually really want to statically link `libc++`? (I tried that here, but it ultimately ran into a roadblock on x86_64: #45077 (comment)) Can we rewrite the comment here to be more clear about why some systems aren't going to actually use this option: https://github.com/rust-lang/rust/blob/b989428f7dec7b52d68bed6a21e9b5b0a8086267/src/bootstrap/compile.rs#L550-L553 How does this affect users of older FreeBSD systems? It seemed like no one was complaining about using a 10.3 base version in the thread for #45077. FreeBSD seems to only officially support 10.3, 10.4, and 11.x right now, do we have to consider older users? The `libc++` stuff came in for FreeBSD 10, older FreeBSD used `libstdc++`. Looks like @alexcrichton was leading the discussion on the previous issue: r? @alexcrichton Let me know what I can do to help get this through.
☀️ Test successful - status-appveyor, status-travis |
Reviving #45077, from @jld:
#45077 was close but didn't quite make it. I rebased @jld's work off the current
master
and started with that.I was able to determine that this Travis error (#45077 (comment)) was ultimately caused by
src/librustc_llvm/build.rs
attempting to follow a wrong value inLLVM_STATIC_STDCPP
(#45077 (comment)).I looked at the downstream port for FreeBSD (https://svnweb.freebsd.org/ports/head/lang/rust/) and it seems like they do not use
--enable-llvm-static-stdcpp
.Since
libc++
is included in the FreeBSD 10+ base system, we don't need to statically link it either?So in b989428 I have set the FreeBSD build to not actually use
LLVM_STATIC_STDCPP
.I was able to run
./src/ci/docker/run.sh
with bothdist-i686-freebsd
anddist-x86_64-freebsd
successfully and in about 1 minute of testing it seemed like the dist-x86_64-freebsd results worked on a FreeBSD 11 system.It should fix #44433, which seems to be affecting many potential users. Also FreeBSD users should be able to
./x.py build
which should help anyone who wants to upstream fixes for FreeBSD.Questions:
Does this approach seem to be the right way to go? Do we actually really want to statically link
libc++
? (I tried that here, but it ultimately ran into a roadblock on x86_64: #45077 (comment))Can we rewrite the comment here to be more clear about why some systems aren't going to actually use this option:
rust/src/bootstrap/compile.rs
Lines 550 to 553 in b989428
How does this affect users of older FreeBSD systems? It seemed like no one was complaining about using a 10.3 base version in the thread for #45077. FreeBSD seems to only officially support 10.3, 10.4, and 11.x right now, do we have to consider older users? The
libc++
stuff came in for FreeBSD 10, older FreeBSD usedlibstdc++
.Looks like @alexcrichton was leading the discussion on the previous issue:
r? @alexcrichton
Let me know what I can do to help get this through.