@@ -255,3 +255,84 @@ etc.).
255255This also changes the way Cargo interacts with the compiler, helping to
256256prevent interleaved messages when multiple crates attempt to display a message
257257at the same time.
258+
259+ ### build-std
260+ * Tracking Repository: https://github.com/rust-lang/wg-cargo-std-aware
261+
262+ The ` build-std ` feature enables Cargo to compile the standard library itself as
263+ part of a crate graph compilation. This feature has also historically been known
264+ as "std-aware Cargo". This feature is still in very early stages of development,
265+ and is also a possible massive feature addition to Cargo. This is a very large
266+ feature to document, even in the minimal form that it exists in today, so if
267+ you're curious to stay up to date you'll want to follow the [ tracking
268+ repository] ( https://github.com/rust-lang/wg-cargo-std-aware ) and its set of
269+ issues.
270+
271+ The functionality implemented today is behind a flag called ` -Z build-std ` . This
272+ flag indicates that Cargo should compile the standard library from source code
273+ using the same profile as the main build itself. Note that for this to work you
274+ need to have the source code for the standard library available, and at this
275+ time the only supported method of doing so is to add the ` rust-src ` rust rustup
276+ component:
277+
278+ ```
279+ $ rustup component add rust-src --toolchain nightly
280+ ```
281+
282+ It is also required today that the ` -Z build-std ` flag is combined with the
283+ ` --target ` flag. Note that you're not forced to do a cross compilation, you're
284+ just forced to pass ` --target ` in one form or another.
285+
286+ Usage looks like:
287+
288+ ```
289+ $ cargo new foo
290+ $ cd foo
291+ $ cargo +nightly run -Z build-std --target x86_64-unknown-linux-gnu
292+ Compiling core v0.0.0 (...)
293+ ...
294+ Compiling foo v0.1.0 (...)
295+ Finished dev [unoptimized + debuginfo] target(s) in 21.00s
296+ Running `target/x86_64-unknown-linux-gnu/debug/foo`
297+ Hello, world!
298+ ```
299+
300+ Here we recompiled the standard library in debug mode with debug assertions
301+ (like ` src/main.rs ` is compiled) and everything was linked together at the end.
302+
303+ Using ` -Z build-std ` will implicitly compile the stable crates ` core ` , ` std ` ,
304+ ` alloc ` , and ` proc_macro ` . If you're using ` cargo test ` it will also compile the
305+ ` test ` crate. If you're working with an environment which does not support some
306+ of these crates, then you can pass an argument to ` -Zbuild-std ` as well:
307+
308+ ```
309+ $ cargo +nightly build -Z build-std=core,alloc
310+ ```
311+
312+ The value here is a comma-separated list of standard library crates to build.
313+
314+ #### Requirements
315+
316+ As a summary, a list of requirements today to use ` -Z build-std ` are:
317+
318+ * You must install libstd's source code through ` rustup component add rust-src `
319+ * You must pass ` --target `
320+ * You must use both a nightly Cargo and a nightly rustc
321+ * The ` -Z build-std ` flag must be passed to all ` cargo ` invocations.
322+
323+ #### Reporting bugs and helping out
324+
325+ The ` -Z build-std ` feature is in the very early stages of development! This
326+ feature for Cargo has an extremely long history and is very large in scope, and
327+ this is just the beginning. If you'd like to report bugs please either report
328+ them to:
329+
330+ * Cargo - https://github.com/rust-lang/cargo/issues/new - for implementation bugs
331+ * The tracking repository -
332+ https://github.com/rust-lang/wg-cargo-std-aware/issues/new - for larger design
333+ questions.
334+
335+ Also if you'd like to see a feature that's not yet implemented and/or if
336+ something doesn't quite work the way you'd like it to, feel free to check out
337+ the [ issue tracker] ( https://github.com/rust-lang/wg-cargo-std-aware/issues ) of
338+ the tracking repository, and if it's not there please file a new issue!
0 commit comments