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

Enable bootstrapping non-build-machine targets #31884

Merged
merged 14 commits into from
Mar 1, 2016

Conversation

alexcrichton
Copy link
Member

These commits add support to the rustbuild build system to compile non-build-system compilers. For example this will allow creating an ARM compiler on a x86 system. The high level way this works is:

  • The only compiler ever run is the build target compiler. No other compiler is assumed to be runnable.
  • As a result, all output artifacts come from the build compiler.
  • The libs for the stageN cross-compiled compiler will be linked into place after the build target builds them.

This will break the assumption that a compiler never links to anything it didn't itself produce, but it retains the assumption that a compiler only ever links to anything built in the same stage. I believe this means that the stage1 cross-compiled compilers will still be usable.

I tested this by creating an arm-unknown-linux-gnueabihf compiler. So far the linking ended up all working OK (including LLVM being cross compiled), but I haven't been able to run it yet (in QEMU for a raspberry pi). I think that's because my system linker is messed up or something like that (some newer option is assumed when it's not actually there).

Overall, though, this means that rustbuild can compile an arm-unknown-linux-gnueabihf compiler. Ideally we could even start shipping nightlies based on this at some point!

@alexcrichton
Copy link
Member Author

r? @brson

@@ -115,6 +115,11 @@ pub fn compiler_rt(build: &Build, target: &str) {
let mode = if build.config.rust_optimize {"Release"} else {"Debug"};
let (dir, build_target, libname) = if target.contains("linux") {
let os = if target.contains("android") {"-android"} else {""};
let arch = if arch == "arm" && target.contains("eabihf") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this cover the armv7-unknown-linux-gnueabihf target?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I... doubt it will!

@japaric
Copy link
Member

japaric commented Feb 27, 2016

I've tested this PR by cross compiling a compiler to arm-unknown-linux-gnueabihf. And, then testing that cross compiled rustc/std on an ARMv7 board by running some smoke tests. The smoke tests consisted of: building cargo, cargo testing hyper and cargo testing clap and all of them succeeded. (NOTE: I needed cargo on the ARM target, so I used an unofficial cargo binary from RustBuild. The host was an x86_64 machine running Ubuntu 15.10. The target was an ARMv7 machine running hard-float Ubuntu 15.10)

I found two (minor) issues. @alexcrichton is already aware of them, but to reiterate:

  • We use the flags produced by the host llvm-config --cxxflags to cross compile rustc_llvm. Among these flags there is a -m64 flag that's not recognized by the ARM cross g++ compiler. This flag needs to be filtered out before passing the flags to g++.
  • The cross compiled libcompiler-rt.a doesn't get copied to the build/arm-unknown-linux-gnueabihf/stageN directories.

This commit fixes a longstanding issue with the makefiles where all host
platforms bootstrap themselves. This commit alters the build logic for the
bootstrap to instead only bootstrap the build triple, and all other compilers
are compiled from that one compiler.

The benefit of this change is that we can cross-compile compilers which cannot
run on the build platform. For example our builders could start creating
`arm-unknown-linux-gnueabihf` compilers.

This reduces the amount of bootstrapping we do, reducing the amount of test
coverage, but overall it should largely just end in faster build times for
multi-host compiles as well as enabling a feature which can't be done today.

cc rust-lang#5258
These flags aren't applicable to build scripts, and may actuall wreak havoc.
Needs a different target to get built and also we apparently need to appease the
C++ compiler somehow.
Currently all multi-host builds assume the the build platform can run the
`llvm-config` binary generated for each host platform we're creating a compiler
for. Unfortunately this assumption isn't always true when cross compiling, so we
need to handle this case.

This commit alters the build script of `rustc_llvm` to understand when it's
running an `llvm-config` which is different than the platform we're targeting for.
Fixes `--step librustc`
Right now it's implicitly done as part of building the compiler, but this was
intended to be a standalone step to ensure we tracked what built what.
This switches the defaults to ensure that everything is built with the build
compiler rather than the host compiler itself (which we're not guaranteed to be
able to run)
When cross compiling for a new host, we can't actually run the host compiler to
generate its own libs. In theory, however, all stage2 compilers (for any host)
will produce the same libraries, so we just require the build compiler to
produce the necessary host libraries and then we link those into place.
These should all no longer be necessary as they've been folded into the
compiler.
This allows bootstrapping new platforms immediately in stage0
Also fix a bug where we didn't clean out previous nightlies
* Fixes a warning with libc
* Brings in some new flag updates for various platforms through gcc-rs
* Otherwise routine updates here/there
@alexcrichton alexcrichton force-pushed the no-bootstrap-from-existing branch from 86d83be to 15b4a8c Compare February 28, 2016 18:50
@alexcrichton
Copy link
Member Author

Thanks for testing this out @japaric! I've amended the relevant commits and those issues should all be fixed.

@brson
Copy link
Contributor

brson commented Feb 29, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Feb 29, 2016

📌 Commit 15b4a8c has been approved by brson

@joerg-krause
Copy link
Contributor

How do you exactly use this feature? Can you give an example on howto build for the ARM target you mentioned?

@japaric
Copy link
Member

japaric commented Feb 29, 2016

How do you exactly use this feature? Can you give an example on howto build for the ARM target you mentioned?

Pass --host=$triple and --enable-rustbuild to the configure script before calling make. Something like this:

mkdir build
cd build
../configure --enable-rustbuild --host=arm-unknown-linux-gnueabihf
make

bors added a commit that referenced this pull request Feb 29, 2016
These commits add support to the rustbuild build system to compile non-build-system compilers. For example this will allow creating an ARM compiler on a x86 system. The high level way this works is:

* The only compiler ever run is the build target compiler. No other compiler is assumed to be runnable.
* As a result, all output artifacts come from the build compiler.
* The libs for the stageN cross-compiled compiler will be linked into place after the build target builds them.

This will break the assumption that a compiler never links to anything it didn't itself produce, but it retains the assumption that a compiler only ever links to anything built in the same stage. I believe this means that the stage1 cross-compiled compilers will still be usable.

I tested this by creating an `arm-unknown-linux-gnueabihf` compiler. So far the linking ended up all working OK (including LLVM being cross compiled), but I haven't been able to run it yet (in QEMU for a raspberry pi). I think that's because my system linker is messed up or something like that (some newer option is assumed when it's not actually there).

Overall, though, this means that rustbuild can compile an arm-unknown-linux-gnueabihf compiler. Ideally we could even start shipping nightlies based on this at some point!
@bors
Copy link
Contributor

bors commented Feb 29, 2016

⌛ Testing commit 15b4a8c with merge 5a0308a...

@bors bors merged commit 15b4a8c into rust-lang:master Mar 1, 2016
@alexcrichton alexcrichton deleted the no-bootstrap-from-existing branch March 2, 2016 06:07
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

Successfully merging this pull request may close these issues.

5 participants