I am attempting to cross-compile on an offline system. I have the appropriate targets (if it is relevant, the targets I am using are classified as Tier 3), howbeit when I attempt to build using the target then I get the following error:
error[E0514]: found crate
std compiled by an incompatible version of rustc
= help: please recompile that crate using this compiler (rustc 1.39.0-beta.2 (5752b6348 2019-09-27))
= note: the following crate versions were found:
std compiled by rustc 1.39.0-beta.7234 (5752b6348 2019-09-27): [path/to/libstd].rlib
std compiled by rustc 1.39.0-beta.7234 (5752b6348 2019-09-27): [path/to/libstd].so
error: aborting due to previous error
My question is how to resolve this issue on an offline system. How exactly do I "recompile that create using this compiler"? I could grab a separate online system and copy-pasta files around if needed. Thanks!
The error indicates that you are trying to use a libstd compiled by one version of rustc with a different rustc version. This is not allowed. Try recompiling libstd using the rustc you use on the offline system. Normally you would use the unstable
-Zbuild-std flag of cargo, but it seems your rustc version is just a month or two too old to support it. (Basic standard library support. by ehuss · Pull Request #7216 · rust-lang/cargo · GitHub was merged 2019-09-03) If you have the option to do so, I would recommend updating rustc. If you are using 1.39 for bootstrapping reasons, know that mrustc now supports bootstrapping rustc 1.54 too. If updating to a newer rustc version is not an option, you could rebuild rustc using the same rustc you are currently use and when doing so pass both the host and target you need to
--target. The resulting rustc version will then be able to compile for both the host (for build scripts and proc macros) and the target you need.
Ah ok, what does the process of recompiling libstd involve? I am still a bit of a novice with Rust, so any and all insight is appreciated!
If you were to use a compile that was even a release or two older, you would be able to simply use
cargo build -Zbuild-std=std --target $my_target instead of
cargo build --target $my_target, but if you are not able to update the procedure would roughly be to get the source for the rustc version you want to use and run
cargo build -p test --target $my_target --release (making sure to use the exact same rustc as you will eventually use the sysroot with) and then copy the contents of the
target/$my_target/release/deps directory to
lib/rustlib/$my_target/lib in the rustc sysroot.