11# Motivation
22[ motivation ] : #motivation
33
4+ > [ !IMPORTANT]
5+ >
6+ > This section lists all of the motivations that have been associated with
7+ > build-std in its various iterations, but not all of these use cases will be
8+ > addressed by this proposal.
9+ >
10+ > The motivations that will not be addressed are nevertheless mentioned here so
11+ > that reviewers have a more complete context for what has and hasn't been
12+ > desired of build-std over time.
13+
414While the pre-built standard library has been sufficient for the majority of
515Rust users, there are a variety of use-cases which require the ability to
6- re-build the standard library. This section lists all of the motivations that
7- have been associated with build-std in its various iterations, but not all of
8- these use cases will be addressed by this proposal.
16+ re-build the standard library.
17+
18+ This RFC aims to support the following use cases:
919
10201 . ** Re-building the standard library with different codegen flags or profile**
1121 ([ wg-cargo-std-aware #2 ] )
@@ -14,10 +24,12 @@ these use cases will be addressed by this proposal.
1424 space available on their target platforms, which can be achieved in Cargo by
1525 setting ` opt-level = s/z ` and ` panic = "abort" ` in their profile. However,
1626 these settings will not apply to the pre-built standard library
27+
1728 - Similarly, when deploying to known environments, use of ` target-cpu ` or
1829 ` target-feature ` can improve the performance of code generation or allow the
1930 use of newer hardware features than the target's baseline provides. As above,
2031 these configuration will not apply to the pre-built standard library
32+
2133 - While the pre-built standard library is built to support debugging without
2234 compromising size and performance by setting ` debuginfo=1 ` , this isn't
2335 ideal, and building the standard library with the dev profile would provide
@@ -27,19 +39,26 @@ these use cases will be addressed by this proposal.
2739
2840 - Any compiler flags which change the ABI cannot currently be stabilised as they
2941 would immediately mismatch with the pre-built standard library
42+
3043 - Without an ability to rebuild the standard library using these flags, it is
3144 impossible to use them effectively and safely if stabilised
45+
3246 - ABI-modifying flags are designated as target modifiers ([ rfcs #3716 ] /[ rust #136966 ] )
3347 and require that the same value for the flag is passed to all compilation units
48+
3449 - Flags which need to be set across the entire crate graph to uphold some
3550 property (i.e. enhanced security) are also target modifiers
51+
3652 - For example: sanitizers, control flow integrity, ` -Zfixed-x18 ` , etc
3753
38543 . ** Building the standard library on a stable toolchain without Cargo**
3955
4056 - While tangential to the core of build-std as a feature, projects like Rust
4157 for Linux want to be able to build an unmodified ` core ` from ` rust-src ` in
4258 the sysroot on a stable toolchain without Cargo
59+
60+ - It is relatively straightforward to support this, hence its inclusion
61+
4362 - Cargo may also want a mechanism to build the standard library for build-std
4463 on a stable toolchain without relying on ` RUSTC_BOOTSTRAP `
4564
@@ -53,40 +72,58 @@ these use cases will be addressed by this proposal.
5372
5473 - There is no stable mechanism for using the standard library on a tier three
5574 target that does not ship a pre-built std
75+
5676 - While it is common for these targets to not support the standard library,
5777 they should be able to use ` core `
78+
5879 - These users are forced to use nightly and the unstable ` -Zbuild-std `
5980 feature or third-party tools like [ cargo-xbuild] (formerly [ xargo] )
6081
61- 6 . ** Using miri on a stable toolchain**
82+ The following use cases are not supported by this RFC, but could be supported
83+ with follow-up RFCs (and this RFC will attempt to ensure they remain viable as
84+ future possibilities):
6285
63- - Using miri requires building the standard library with specific compiler flags
64- that would not be appropriate for the pre-built standard library, so is forced
65- to require nightly and build its own sysroot
66-
67- 7 . ** Using the standard library with custom targets**
86+ 1 . ** Using the standard library with custom targets**
6887
6988 - There is no stable mechanism for using the standard library for a custom
7089 target (using target-spec-json)
90+
7191 - Like tier three targets, these targets often only support ` core ` and are
7292 forced to use nightly today
7393
74- 8 . ** Enabling Cargo features for the standard library** ([ wg-cargo-std-aware #4 ] )
94+ 2 . ** Enabling Cargo features for the standard library** ([ wg-cargo-std-aware #4 ] )
7595
7696 - There are opportunities to expose Cargo features from the standard library that
7797 would be useful for certain subsets of the Rust users.
98+
7899 - For example, embedded users may want to enable a feature like ` optimize_for_size ` or
79100 ` panic_immediate_abort ` to reduce binary size
80101
81- 9 . ** Modifying the source code of the standard library** ([ wg-cargo-std-aware #7 ] )
102+ 3 . ** Using miri on a stable toolchain**
103+
104+ - Using miri requires building the standard library with specific compiler flags
105+ that would not be appropriate for the pre-built standard library, so is forced
106+ to require nightly and build its own sysroot
107+
108+ Some use cases are unlikely to supported by the project unless a new and
109+ compelling use-case is presented, and so this RFC may make decisions which make
110+ these motivations harder to solve in future:
111+
112+ 1 . ** Modifying the source code of the standard library** ([ wg-cargo-std-aware #7 ] )
82113
83114 - Some platforms require a heavily modified standard library that would not
84115 be suitable for upstreaming, such as [ Apache's SGX SDK] [ sgx ] which replaces
85116 some standard library and ecosystem crates with forks or custom crates for a
86117 custom ` x86_64-unknown-linux-sgx ` target
118+
87119 - Similarly, some tier three targets may wish to patch standard library
88120 dependencies to add or improve support for the target
89121
122+ 2 . ** Retire the concept of the sysroot**
123+
124+ - Earlier proposals for build-std were motivated in-part by the desire to see
125+ the concept of the sysroot retired
126+
90127[ cargo-xbuild ] : https://github.com/rust-osdev/cargo-xbuild
91128[ xargo ] : https://github.com/japaric/xargo
92129
0 commit comments