rust-osdev / cargo-xbuild

Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.
Apache License 2.0
258 stars 25 forks source link

Intermittend IO error with local toolchains #21

Closed dvdhrm closed 5 years ago

dvdhrm commented 5 years ago

Hey

In sysroot::update() you call util::cp_r() to copy the lib and bin directories of lib/rustlib/ to the local sysroot. However, if these directories are empty, they might not exist at all, in which case the xbuild script errors out with:

error: intermittent IO error while iterating directory `/.../rust-lang/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin`
caused by: IO error for operation on /.../rust-lang/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/bin: No such file or directory (os error 2)
caused by: No such file or directory (os error 2)

In particular, if you compile rustc locally and use rustup toolchain link <name> <path> to link to the stage2 binaries, this error occurs. A simple workaround is to simply mkdir the respective directories. In my scenario, the bin directory is non-existant, so I just created it and everything runs smoothly.

I assume when you install your toolchains into a target directory, the installer automatically creates these directories, and as such the error does not occur. I didn't test this, though.

Anyway, would be nice to check whether the directory exists, rather than erroring out.

Thanks! David

phil-opp commented 5 years ago

This code was already there in xargo before rust-xbuild was forked from it. I know that the bin directory is optional and only required for linking with LLD. I don't know what the lib directory is used for.

We could of course add a check that these directories exists before trying to copy them, and otherwise print a warning and just skip the copying. I'm a bit short on time at the moment, but I would be happy to merge a PR that implements that.

stlankes commented 5 years ago

Hello,

I have a similar problem on my aarch64 system.

RUST_TARGET_PATH=PATH_TO_THE_TARGET cargo xbuild --target aarch64-unknown-hermit-kernel error: intermittent IO error while iterating directory /home/stefan/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/bin

Any idea, how I could fix it?

phil-opp commented 5 years ago

@stlankes We could just guard this cp_r call with an if that checks whether the source directory exists. If it doesn't we should emit a warning.