Build with custom libstd using xargo?


#1

I’m working on edits to libstd, and I’d like to test them locally. Following the advice in the xargo README, I did:

XARGO_RUST_SRC=<workspace>/rust/src/ xargo build

(where <workspace>/rust is a copy of the rust-lang/rust repository with my changes)

Unfortunately, I got the following output:

   Compiling core v0.0.0 (file:///<workspace>/rust/src/libcore)
    Finished release [optimized] target(s) in 16.24 secs
   Compiling tmp v0.1.0 (file:////tmp/tmp)
error[E0463]: can't find crate for `std`

error: aborting due to previous error

error: Could not compile `tmp033`.

To learn more, run the command again with --verbose.

Any advice here?


#2

What do you have in Xargo.toml?


#3

Ah, I don’t have a Xargo.toml.


#4

So, following the advice in the README, I added a Xargo.toml as follows:

[build.dependencies.std]
features = []

Unfortunately, I’m still getting the same error. I’m not really sure what the underlying issue is, so I’m not sure how to go about debugging this.


#5

OK, I ended up figuring it out. Two issues:

First, I was trying to compile with libtest, but in order to do that, you need to add this to Xargo.toml so that things will build in the right order:

[dependencies.std]
features = ["jemalloc"]
stage = 0

[dependencies.test]
stage = 1

Second, however, you need to compile with the abort panic strategy in order to use a custom libstd. libtest, on the other hand, requires the unwind panic strategy, so the two are incompatible. I had to scrap using libtest and implement the functionality without it. I also had to set panic = "abort" in my build profiles in Cargo.toml.

Thus, you have to remove the libtest dependency, bringing Xargo.toml back down to this:

[dependencies.std]
features = ["jemalloc"]

However, even with this, I was still getting an error - the compiler was still trying to link in panic_unwind. I’m still not sure what was causing it, but I was able to fix it by being more aggressive and setting RUSTFLAGS='-C panic=abort' when calling xargo build, and that did the trick.