# Supporting a new target

**URL:** <https://internals.rust-lang.org/t/supporting-a-new-target/4483>\
**Category:** compiler\
**Created:** [December 21, 2016, 8:58pm UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483 "2016-12-21T20:58:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wildstyle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/wildstyle/32/6195_2.png) [@wildstyle](https://internals.rust-lang.org/u/wildstyle)\
**Post date:** [December 21, 2016, 8:58pm UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483/1 "2016-12-21T20:58:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![vadimcn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vadimcn/32/2789_2.png) [@vadimcn](https://internals.rust-lang.org/u/vadimcn)\
**Post date:** [December 21, 2016, 9:16pm UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483/2 "2016-12-21T21:16:35Z")

</div>

> [@wildstyle](#):
>
> 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?

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

```rust
[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.

---

<div class="post-metadata">

**Author:** ![wildstyle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/wildstyle/32/6195_2.png) [@wildstyle](https://internals.rust-lang.org/u/wildstyle)\
**Post date:** [December 21, 2016, 9:18pm UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483/3 "2016-12-21T21:18:04Z")

</div>

> [@vadimcn](#):
>
> I think you want something like this

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

---

<div class="post-metadata">

**Author:** ![wildstyle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/wildstyle/32/6195_2.png) [@wildstyle](https://internals.rust-lang.org/u/wildstyle)\
**Post date:** [December 21, 2016, 9:26pm UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483/4 "2016-12-21T21:26:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hanna-kruppe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hanna-kruppe/32/6540_2.png) [@hanna-kruppe](https://internals.rust-lang.org/u/hanna-kruppe)\
**Post date:** [December 21, 2016, 10:49pm UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483/5 "2016-12-21T22:49:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wildstyle](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/wildstyle/32/6195_2.png) [@wildstyle](https://internals.rust-lang.org/u/wildstyle)\
**Post date:** [December 23, 2016, 3:11pm UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483/6 "2016-12-23T15:11:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:27am UTC](https://internals.rust-lang.org/t/supporting-a-new-target/4483/7 "2019-03-25T08:27:30Z")

</div>

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