Skip to content

Commit 07d6581

Browse files
authored
Recommend using the build-std feature of cargo instead of this crate
1 parent 3715d64 commit 07d6581

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,39 @@
22

33
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.
44

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+
528
## Dependencies
629

730
- The `rust-src` component, which you can install with `rustup component add
831
rust-src`.
932

1033
- Rust and Cargo.
1134

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:
1338

1439
```
1540
$ cargo install cargo-xbuild

0 commit comments

Comments
 (0)