Stream: t-compiler

Topic: adding an aarch64_be-unknown-linux-gnu target


Steev (Nov 02 2018 at 18:15, on Zulip):

I've been slowly stumbling my way through adding support for arm64 big endian to rust/rustc, but I've kind of hit a wall at the moment.
What I'm currently doing is attempting to cross compile rust for aarch64_be.

I have a Gentoo host which has an aarch64_be cross compiler built on it. I've added the target, and I'm currently attempting to build rust and I can build my own amd64 rustc which does have the aarch64_be-unknown-linux-gnu target in it, however I'm stuck trying to figure out how to use that built version as the one to build the aarch64_be version.

The following may be overkill, but unfortunately the documentation for adding a target seems to be lacking (or at least, I couldn't find anything with my searches, aside from an issue where someone was working on the documentation but got bored with it so stopped.)

My source checkout is /storage/rust/rust, and everything that is built, is in /storage/rust/build. I run the following commands from /storage/rust.

CC_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-gcc AR_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-ar CXX_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-g++ LD_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-ld ARCH=x86_64 BUILD=x86_64-unknown-linux-gnu HOST=aarch64_be-unknown-linux-gnu PREFIX=x86_64-unknown-linux-gnu  SRC_DIR=/storage/rust/rust /storage/rust/rust/configure --enable-ccache --enable-ninja --full-bootstrap --host=$HOST

nice $SRC_DIR/x.py build src/llvm --host $BUILD

nice $SRC_DIR/x.py build src/rustc --host $HOST

This seems to do the correct thing, except when I get to the part where it tries to build for $HOST, the stage0 it tries to use is still the one downloaded, which doesn't have the aarch64_be-unknown-linux-gnu target in it. What I'm trying to figure out and haven't been able to, is how to point it to the compiler I've just built? I'm assuming I can use --local-rust-root=/storage/rust/build/$something but I'm not sure what $somethiing should be, or if I'm even along the right path.

Any help would be greatly appreciated.

The output I get, when I am attempting to run the above commands is:

Updating only changed submodules
Submodules updated in 0.08 seconds
    Finished dev [unoptimized] target(s) in 0.37s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.37s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.35s
Copying stage0 test from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.43s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 codegen artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu, llvm)
    Finished release [optimized] target(s) in 0.30s
Assembling stage1 compiler (x86_64-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.31s
Copying stage1 std from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / aarch64_be-unknown-linux-gnu)
Building stage1 test artifacts (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.35s
Copying stage1 test from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / aarch64_be-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.30s
Copying stage1 std from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage1 compiler artifacts (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.42s
Copying stage1 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / aarch64_be-unknown-linux-gnu)
Building stage1 codegen artifacts (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu, llvm)
    Finished release [optimized] target(s) in 0.34s
Assembling stage2 compiler (aarch64_be-unknown-linux-gnu)
Uplifting stage1 std (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu)
Copying stage2 std from stage1 (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu / aarch64_be-unknown-linux-gnu)
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu)
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/storage/rust/build/bootstrap/debug/rustc - --crate-name ___ --print=file-names --target aarch64_be-unknown-linux-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)
--- stderr
error: Error loading target specification: Could not find specification for target "aarch64_be-unknown-linux-gnu"
  |
  = help: Use `--print target-list` for a list of built-in targets


command did not execute successfully: "/storage/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "aarch64_be-unknown-linux-gnu" "-j" "8" "--release" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/storage/rust/rust/src/libstd/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101
thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
failed to run: /storage/rust/build/bootstrap/debug/bootstrap build src/rustc --host=aarch64_be-unknown-linux-gnu
Build completed unsuccessfully in 0:00:06```
nikomatsakis (Nov 02 2018 at 18:29, on Zulip):

cc @Alex Crichton, who probably knows the most about adding new targets? Certainly I would expect @Alex Crichton to know the answer to this:

What I'm trying to figure out and haven't been able to, is how to point it to the compiler I've just built? I'm assuming I can use --local-rust-root=/storage/rust/build/$something but I'm not sure what $somethiing should be, or if I'm even along the right path.

Alex Crichton (Nov 02 2018 at 18:34, on Zulip):

@Steev the --local-rust-root should be the same as rustc --print sysroot, aka the folder containing bin which in turns contains rustc

Alex Crichton (Nov 02 2018 at 18:35, on Zulip):

and that may fix your issue?

Steev (Nov 02 2018 at 18:52, on Zulip):

It doesn't seem to. I've added everything to a script here, my script looks like the following:

main() {
    #ARCH=aarch64_be
    ARCH=x86_64
    BUILD=x86_64-unknown-linux-gnu
    HOST=aarch64_be-unknown-linux-gnu
    #HOST=x86_64-unknown-linux-gnu
    PREFIX=x86_64-unknown-linux-gnu
    CC_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-gcc
    AR_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-ar
    CXX_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-g++
    LD_aarch64_be_unknown_linux_gnu=aarch64_be-unknown-linux-gnu-ld
    RUSTC_LINKER=aarch64_be-unknown-linux-gnu-gcc

   $SRC_DIR/configure \
       --enable-ccache \
       --enable-ninja \
       --enable-rustbuild \
       --local-rust-root=/storage/rust/build/x86_64-unknown-linux-gnu/stage2/ \
       --enable-local-rebuild \
       --full-bootstrap \
       --host=$HOST

   # work around rust-lang/rust#38037
   nice $SRC_DIR/x.py build src/llvm --host=$BUILD

   # STDOUT
   # Building LLVM for x86_64-unknown-linux-gnu

   nice $SRC_DIR/x.py build src/rustc --host=$HOST

And I get

Building stage0 std artifacts (x86_64-unknown-linux-gnu -> aarch64_be-unknown-linux-gnu)
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/storage/rust/build/bootstrap/debug/rustc - --crate-name ___ --print=file-names --target aarch64_be-unknown-linux-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)
--- stderr
error: Error loading target specification: Could not find specification for target "aarch64_be-unknown-linux-gnu"
  |
  = help: Use `--print target-list` for a list of built-in targets


command did not execute successfully: "/storage/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "aarch64_be-unknown-linux-gnu" "-j" "8" "--release" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/storage/rust/rust/src/libstd/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101
thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1112:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
failed to run: /storage/rust/build/bootstrap/debug/bootstrap build src/rustc --host=aarch64_be-unknown-linux-gnu
Build completed unsuccessfully in 0:00:06

Still. Someone on discord mentioned using the cargo.toml to set the rustc to use, but I'm not sure how the interaction works between using the configure script and the cargo.toml file.

Steev (Nov 02 2018 at 20:40, on Zulip):

@Alex Crichton so... no go. Every time it goes to create the stage0 std artifacts, it uses the /storage/rust/build/bootstrap/debug/rustc.

# Instead of downloading the src/stage0.txt version of the compiler
# specified, use this rustc binary instead as the stage0 snapshot compiler.
rustc = "/storage/rust/build/x86_64-unknown-linux-gnu/stage2/bin/rustc"

At this point, I have no idea. I don't really understand why the bootstrapped rustc doesn't have the target in it, but the stage2 one does.

Alex Crichton (Nov 02 2018 at 20:43, on Zulip):

@Steev oh the .../bootstrap/debug/rustc isn't the actual rustc that's used, it's just a thin wrapper. If you pass -vv to ./x.py build you should see the real rustc being used somewhere in the output. Specifying that rustc should work as well though. Have you tried running the rustc manually to make sure it supports the target in question?

Steev (Nov 02 2018 at 20:46, on Zulip):

(deleted)

Steev (Nov 02 2018 at 20:56, on Zulip):

@Alex Crichton Okay, yes, it's still using the stage0 -

rustc command: "LD_LIBRARY_PATH"="/storage/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib:" "/storage/rust/build/x86_64-unknown-linux-gnu/stage0/bin/rustc" "-" "--crate-name" "___" "--print=file-names" "--target" "aarch64_be-unknown-linux-gnu" "--crate-type" "bin" "--crate-type" "rlib" "--crate-type" "dylib" "--crate-type" "cdylib" "--crate-type" "staticlib" "--crate-type" "proc-macro" "--cfg" "stage0" "--sysroot" "/storage/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot" "-Cprefer-dynamic" "-Clinker=aarch64_be-unknown-linux-gnu-gcc" "-C" "debug-assertions=n" "-C" "link-args=-Wl,-rpath,$ORIGIN/../lib" "-Z" "force-unstable-if-unmarked"
sysroot: "/storage/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot"
libdir: "/storage/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib"
error: Error loading target specification: Could not find specification for target "aarch64_be-unknown-linux-gnu"
steev@oswin /storage/rust $ ./build/x86_64-unknown-linux-gnu/stage2/bin/rustc --print target-list | grep aarch64
aarch64-fuchsia
aarch64-linux-android
aarch64-pc-windows-msvc
aarch64-unknown-cloudabi
aarch64-unknown-freebsd
aarch64-unknown-hermit
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
aarch64-unknown-netbsd
aarch64-unknown-none
aarch64-unknown-openbsd
aarch64_be-unknown-linux-gnu

(sorry if this got sent twice, I'm still trying to figure out zulip)

Alex Crichton (Nov 02 2018 at 21:22, on Zulip):

@Steev this may be a bug in rustbuild then?

Alex Crichton (Nov 02 2018 at 21:22, on Zulip):

I'm not sure :(

Steev (Nov 02 2018 at 23:32, on Zulip):

@Alex Crichton so, i did something hacky and worked around the issue by taking the x86_64 rustc toolchain that i'd built, and installed it to a temporary directory and then once the install finished, moved it into the stage0 directory... this appears to be working, so while it's not ideal, it is a bit of a workaround.

Steev (Nov 03 2018 at 19:58, on Zulip):

@Alex Crichton i think i'm going about this the wrong way - ideally, i'd be able to point the build at my freshly built toolchain, but perhaps I should instead send a pull request enabling aarch64_be as a target first, and then deal with trying to get aarch64_be building as a host?

Alex Crichton (Nov 05 2018 at 16:17, on Zulip):

@Steev yeah adding the target first probably makes sense! We can take the other issues from there

Last update: Nov 20 2019 at 01:10UTC