Supporting a new target

I’m writing support for a new target in rustc. So far I can make staticlibs work correctly, and inline assembly, so that’s great IMO.

Here’s my current challenges, I’d love to hear your thoughts:

  1. Rustbuild fails for me. It’s trying to use the stage0 compiler to build my stage1 libstd. This looks like it is wrong for only my use case: bootstrapping stage1 for which no stage0-supporting-my-target exists yet. Can anyone confirm this, or am I misusing/misconfiguring rustbuild?
  2. If I ignore that failure and just use my new stage1 rustc to try to build core by hand, I get a failure during LLVMRustWriteOutputFile() on one particular compile. It’s an assertion in my target, so I’m pretty sure I can take it from here. But it might be easier to investigate if I could dump the input to a file. It still encounters the assertion when I use -C emit=llvm-ir. I guess there’s no way to dump anything higher-level than that right?

How did you configure rustbuild? I think you want something like this in your config.toml:

[build]
target = ["<host target>", "<your target>"]

i.e. you are building a compiler that still runs on the host platform, but can also cross-compile to your target.

Oh! Well, now that you point it out, that's a pretty simple mistake. Thanks!

Hmm, after adding the host triple to the list of targets, it still uses ./build/bootsrap/debug/rustc and ./build/host/stage0/bin/cargo with my desired target to build libcore. It doesn’t give an error beyond “Could not compile core”, but I assume it’s something about the target not being supported.

Should I clean everything first and then restart the build after that change?

You should see if you can compile core in isolation before trying to bootstrap rustc. Create a #![no_std] project, add a path dependency for core in Cargo.toml (point it at src/libcore/ in your rust checkout) and pass --target foo to cargo.

To do this you will need a cargo that uses your custom-built rustc. Use rustup toolchain link to hook your rustc up to rustup’s cargo, that’s the easiest way I know of.

That was a great tip (rustup toolchain link), @hanna-kruppe, thanks. I didn’t know about that feature.

Now I can just cd to src/libcore and do cargo build. I still see that same isRegLoc() assertion I was hitting in #2, but it is simpler to reproduce. I’ll crank on this one for a bit and check in if I get stuck again.

Thanks, all.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.