Adding a new target

I’ve started work on adding a new target to rustc. I have gotten it to the point where I have a working stage 1 compiler. Using this rustc, I can create a simple #[no_core] staticlib and it looks great under disassembly. I’m cross compiling because it’s more convenient than running stuff on the target. Also since the target’s not yet supported, I figure cross compiling is my only hope.

When I try to build the whole shebang using rustbuild / x.py, it fails at “Building stage1 std artifacts”. Unfortunately it doesn’t offer much detail about the failure beyond “error: Could not compile 'core'”. The “process didn’t exit successfully” line indicates that it used stage 0 to build core. Without detailed logs I’ll guess that the problem must be that my target’s not supported by the stage 0 rustc so it must be giving up. BTW I did use “–verbose” but it still didn’t offer any detail here.

If the stage 0 rustc supports everything under the sun then maybe this cross-compile bootstrap need is an uncommon one.

I’ve tried using the now-legacy ./configure / make build but it failed before the stage1 compiler was produced. I can go back to digging into why this fails if it’s the more promising route.

Does anyone have any suggestions about how to get past these issues?

First, yes, you should cross compile first to add a new target.

core is pretty demanding, and it’s perfectly possible to be able to compile no_core libraries but not core. I don’t think it’s stage0 problem… Try running x.py with -v option for verbose output?

2 Likes

Unfortunately I’m already using --verbose and it’s not clear what went wrong.

Here’s an excerpt:

+ ./x.py build --config hex.toml --stage 1 --verbose
    Finished debug [unoptimized] target(s) in 0.0 secs
finding compilers
CC_x86_64-unknown-linux-gnu = "cc"
AR_x86_64-unknown-linux-gnu = "ar"
CC_mynewtarget-unknown-linux-musl = "mynewtarget-linux-clang"
AR_mynewtarget-unknown-linux-musl = "ar"
CXX_x86_64-unknown-linux-gnu = "c++"
running sanity check
collecting channel variables

Building stage1 test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
running: "/local/mnt/workspace/rust/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "-j" "8" "--target" "x86_64-unknown-linux-gnu" "-v" "--release" "--manifest-path" "/local/mnt/workspace/rust/rust/src/rustc/test_shim/Cargo.toml"
       Fresh term v0.0.0 (file:///local/mnt/workspace/rust/rust/src/libterm)
       Fresh getopts v0.0.0 (file:///local/mnt/workspace/rust/rust/src/libgetopts)
       Fresh test v0.0.0 (file:///local/mnt/workspace/rust/rust/src/libtest)
       Fresh test_shim v0.1.0 (file:///local/mnt/workspace/rust/rust/src/rustc/test_shim)
    Finished release [optimized] target(s) in 0.0 secs
executing step Step { name: "build-crate-std_shim", stage: 1, host: "x86_64-unknown-linux-gnu", target: "mynewtarget-unknown-linux-musl" }
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> mynewtarget-unknown-linux-musl)
running: "/local/mnt/workspace/rust/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "-j" "8" "--target" "mynewtarget-unknown-linux-musl" "-v" "--release" "--features" "panic-unwind backtrace" "--manifest-path" "/local/mnt/workspace/rust/rust/src/rustc/std_shim/Cargo.toml"
   Compiling core v0.0.0 (file:///local/mnt/workspace/rust/rust/src/libcore)
       Fresh gcc v0.3.38
       Fresh build_helper v0.1.0 (file:///local/mnt/workspace/rust/rust/src/build_helper)
     Running `/local/mnt/workspace/rust/rust/build/bootstrap/debug/rustc src/libcore/lib.rs --crate-name core --crate-type lib -C opt-level=2 -C metadata=1904068360b1afd2 -C extra-filename=-1904068360b1afd2 --out-dir /local/mnt/workspace/rust/rust/build/x86_64-unknown-linux-gnu/stage1-std/mynewtarget-unknown-linux-musl/release/deps --emit=dep-info,link --target mynewtarget-unknown-linux-musl -L dependency=/local/mnt/workspace/rust/rust/build/x86_64-unknown-linux-gnu/stage1-std/mynewtarget-unknown-linux-musl/release/deps -C codegen-units=8`
error: Could not compile `core`.

Caused by:
  process didn't exit successfully: `/local/mnt/workspace/rust/rust/build/bootstrap/debug/rustc src/libcore/lib.rs --crate-name core --crate-type lib -C opt-level=2 -C metadata=1904068360b1afd2 -C extra-filename=-1904068360b1afd2 --out-dir /local/mnt/workspace/rust/rust/build/x86_64-unknown-linux-gnu/stage1-std/mynewtarget-unknown-linux-musl/release/deps --emit=dep-info,link --target mynewtarget-unknown-linux-musl -L dependency=/local/mnt/workspace/rust/rust/build/x86_64-unknown-linux-gnu/stage1-std/mynewtarget-unknown-linux-musl/release/deps -C codegen-units=8` (exit code: 1)


command did not execute successfully: "/local/mnt/workspace/rust/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "-j" "8" "--target" "mynewtarget-unknown-linux-musl" "-v" "--release" "--features" "panic-unwind backtrace" "--manifest-path" "/local/mnt/workspace/rust/rust/src/rustc/std_shim/Cargo.toml"
expected success, got: exit code: 101

I guess I can try to strace it to get some hints about what went wrong. There’s bound to be helpful output written by rustc or the linker but it’s just been redirected. I just hoped there’d be something obvious about what I was doing that was in error.

I don’t expect build/bootstrap/debug/rustc to be able to support --target mynewtarget-unknown-linux-musl though so I’m suspecting that when I dig further I’ll find an error message regarding the unsupported target.

Hii, If you were able to resolve this, can you please provide the steps to follow. I'm stuck at the same point.