|
2 | 2 |
|
3 | 3 | Cargo-xbuild is a wrapper for `cargo build`, which cross compiles the sysroot crates `core`, `compiler_builtins`, and `alloc` for custom targets. It is a simplified fork of [`xargo`](https://github.com/japaric/xargo), which is in maintainance mode.
|
4 | 4 |
|
| 5 | +## Alternative: The `build-std` feature of cargo |
| 6 | + |
| 7 | +Cargo now has its own feature for cross compiling the sysroot: [**`build-std`**](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std). You can use it by passing `-Z build-std=core,alloc` to `cargo build`. Alternatively, you can specify the following in a `.cargo/config.toml` file: |
| 8 | + |
| 9 | +```toml |
| 10 | +[unstable] |
| 11 | +build-std = ["core", "compiler_builtins", "alloc"] |
| 12 | +``` |
| 13 | + |
| 14 | +The above requires at least Rust nightly 2020–07–15. With the above config in place, the normal `cargo build` command will now automatically cross-compile the specified sysroot crates. |
| 15 | + |
| 16 | +Since the `build-std` feature currently provides no way to enable the `mem` feature of `compiler_builtins`, you need to add a dependency on the [`rlibc`](https://docs.rs/rlibc/1.0.0/rlibc/) crate to provide implementations of `memset`, `memcpy`, etc, which the compiler expects. Note that you need to add an `extern crate rlibc` statement in order for this to work (even in the 2018 edition of Rust). This is required to get cargo to link the otherwise unused crate. |
| 17 | + |
| 18 | +Compared to `cargo-xbuild`, there are many advantages of using `cargo`'s own feature: |
| 19 | + |
| 20 | +- the normal `cargo {check, build, run, test}` commands can be used |
| 21 | +- no external tool must be installed |
| 22 | +- less bugs and breakage because it is always up to date with rustc/cargo |
| 23 | +- faster compilation since the compiler can build the sysroot concurrently to the project crates |
| 24 | +- it might be stablized one day |
| 25 | + |
| 26 | +So it is strongly recommended to try the `build-std` feature of cargo instead of using this crate. |
| 27 | + |
5 | 28 | ## Dependencies
|
6 | 29 |
|
7 | 30 | - The `rust-src` component, which you can install with `rustup component add
|
8 | 31 | rust-src`.
|
9 | 32 |
|
10 | 33 | - Rust and Cargo.
|
11 | 34 |
|
12 |
| -## Installation |
| 35 | +## Installation of `cargo-xbuild` |
| 36 | + |
| 37 | +In case you decide to use `cargo-xbuild` instead of cargo's `build-std` feature for some reason, you can install this crate through: |
13 | 38 |
|
14 | 39 | ```
|
15 | 40 | $ cargo install cargo-xbuild
|
|
0 commit comments