@@ -43,7 +43,7 @@ useful for users of tier three targets.
43
43
> as is feasible.
44
44
45
45
Alongside ` build-std ` , a ` build-std-crate ` key will be introduced
46
- ([ ?] [ rationale-build-std-crate ] ), which can be used to specify which crate from
46
+ ([ ?] [ rationale-build-std-crate ] ), which can be used to specify which "level" of
47
47
the standard library is to be built. Only "core", "alloc" and "std" are valid
48
48
values for ` build-std-crate ` .
49
49
@@ -57,6 +57,9 @@ will not be used unless explicitly set and the crate graph's dependencies on the
57
57
standard library will determine which crates are built instead. Otherwise,
58
58
` build-std-crate ` will default to "std".
59
59
60
+ If ` std ` is to be built and Cargo is building a test using the default test
61
+ harness then Cargo will also build the ` test ` crate.
62
+
60
63
> [ !NOTE]
61
64
>
62
65
> Inspired by the concept of [ opaque dependencies] [ Opaque dependencies ] , the
@@ -71,21 +74,20 @@ standard library will determine which crates are built instead. Otherwise,
71
74
> the dependencies of the ` core ` , ` alloc ` or ` std ` standard library crates
72
75
> individually (via profile overrides, for example).
73
76
>
74
- > - The profiles defined by the standard library will be used.
77
+ > - The profile defined by the standard library will be used.
75
78
>
76
79
> Cargo will resolves the dependencies of opaque dependencies, such as the
77
- > standard library, separately in their own workspaces. The "roots" of such a
78
- > resolve are defined as the unified set of packages that any crate in the
79
- > dependency graph has a explicit dependency on and those which Cargo infers a
80
- > direct dependency on. A dependency on the roots are added to all crates in the
81
- > "parent" resolve.
80
+ > standard library, separately in their own workspaces. The root of such a
81
+ > resolve will be the crate specified in ` build-std-crates ` , or, if stage 1b is
82
+ > implemented, the unified set of packages that any crate in the dependency
83
+ > a direct dependency on. A dependency on the relevant roots are added to all
84
+ > crates in the "parent" resolve.
82
85
>
83
86
> Regardless of which standard library crates are being built, Cargo will build
84
87
> the ` sysroot ` crate of the standard library workspace. ` alloc ` and ` std ` will
85
88
> be optional dependencies of the ` sysroot ` crate which will be enabled when the
86
- > user has requested them. The sysroot always depends on the ` proc_macro ` and
87
- > ` test ` crates. Panic runtimes are dependencies of ` std ` and will be enabled
88
- > depending on the features that Cargo passes to ` std ` (see
89
+ > user has requested them. Panic runtimes are dependencies of ` std ` and will be
90
+ > enabled depending on the features that Cargo passes to ` std ` (see
89
91
> [ * Panic strategies* ] [ panic-strategies ] ).
90
92
>
91
93
> rustc loads panic runtimes in a different way to most dependencies, and
@@ -96,13 +98,14 @@ standard library will determine which crates are built instead. Otherwise,
96
98
>
97
99
> The standard library will always be a non-incremental build
98
100
> ([ ?] [ rationale-incremental ] ), with no ` depinfo ` produced, and only a ` rlib `
99
- > produced (no ` dylib ` ) ([ ?] [ rationale-no-dylib ] ). It will be built into the
100
- > ` target ` directory of the crate or workspace like any other dependency.
101
+ > produced (no ` dylib ` ) ([ ?] [ rationale-no-dylib ] ). It will be built in Cargo's
102
+ > " target" directory of the crate or workspace like any other dependency.
101
103
102
104
The host pre-built standard library will always be used for procedural macros
103
- and build scripts ([ ?] [ rationale-sysroot-for-host-deps ] ). Artifact dependencies
104
- use the same standard library as the rest of the crate (pre-built or
105
- newly-built, as appropriate).
105
+ and build scripts ([ ?] [ rationale-sysroot-for-host-deps ] ). Multi-target projects
106
+ (resulting from the "target" field in artifact dependencies or the use of
107
+ ` per-pkg-target ` fields) may result in the standard library being built multiple
108
+ times - once for each target in the project.
106
109
107
110
* See the following sections for rationale/alternatives:*
108
111
@@ -127,10 +130,10 @@ newly-built, as appropriate).
127
130
## Interactions with ` #![no_std] `
128
131
[ interactions-with-no_std ] : #interactions-with-no_std
129
132
130
- Behaviour of crates using ` #![no_std] ` will change even if the standard library
131
- is rebuilt and passed via ` --extern ` to rustc. Due to ` #![no_std] ` , rustc will
132
- not automatically attempt to load std, but if the user writes ` extern crate std `
133
- then the rebuilt std will be found .
133
+ Behaviour of crates using ` #![no_std] ` will not change whether or not ` std ` is
134
+ rebuilt and passed via ` --extern ` to rustc, and ` #![no_std] ` will still be
135
+ required in order for ` rustc ` to not attempt to load ` std ` and add it to the
136
+ extern prelude .
134
137
135
138
* See the following sections for rationale/alternatives:*
136
139
@@ -198,8 +201,9 @@ explicit and implicit standard library dependencies.
198
201
When it is necessary to build the standard library, Cargo will look for sources
199
202
in a fixed location in the sysroot ([ ?] [ rationale-custom-src-path ] ):
200
203
` lib/rustlib/src ` . rustup's ` rust-src ` component downloads standard library
201
- sources to this location. If the sources are not found, Cargo will emit an error
202
- and recommend the user download ` rust-src ` if using rustup.
204
+ sources to this location and will be made a default component. If the sources
205
+ are not found, Cargo will emit an error and recommend the user download
206
+ ` rust-src ` if using rustup.
203
207
204
208
` rust-src ` will contain the sources for the standard library crates as well as
205
209
its vendored dependencies ([ ?] [ rationale-vendoring ] ). As a consequence sources
@@ -217,12 +221,6 @@ of standard library dependencies will not need be fetched from crates.io.
217
221
- [ * Why vendor standard library dependencies?* ] [ rationale-vendoring ]
218
222
- [ * Why not check if ` rust-src ` has been modified?* ] [ rationale-src-modifications ]
219
223
220
- ### ` libunwind `
221
- [ libunwind ] : #libunwind
222
-
223
- ` libunwind ` 's sources are included in the ` rust-src ` component so that they can
224
- be used as part of the standard library build on targets which require it.
225
-
226
224
## Panic strategies
227
225
[ panic-strategies ] : #panic-strategies
228
226
@@ -261,6 +259,18 @@ In line with Cargo's stance on not parsing the `RUSTFLAGS` environment variable,
261
259
it will not be checked for compilation flags that would require additional
262
260
crates to be built for compilation to succeed.
263
261
262
+ > [ !NOTE]
263
+ >
264
+ > This RFC does not propose building ` libunwind ` locally as ` unwind ` 's build
265
+ > script [ used to do] [ rust#84124 ] . The ` unwind ` crate usually links to the
266
+ > system's ` libunwind ` , in which case any target modifiers used should be set
267
+ > correctly to match compilation flags to match this artifact. Certain flags
268
+ > such as ` -Clink-self-contained=yes ` may cause ` rustc ` to find ` libunwind ` in
269
+ > the sysroot, in which case any set target modifiers may break linking.
270
+ >
271
+ > This could be treated similarly to the ` compiler_builtins ` manual ` c ` feature
272
+ > in the future.
273
+
264
274
* See the following sections for future possibilities:*
265
275
266
276
- [ * Avoid building ` panic_unwind ` unnecessarily* ] [ future-panic_unwind ]
@@ -284,7 +294,7 @@ A handful of targets require linking against special object files, such as
284
294
` windows-gnu ` , ` linux-musl ` and ` wasi ` targets. For example, ` linux-musl `
285
295
targets require ` crt1.o ` , ` crti.o ` , ` crtn.o ` , etc.
286
296
287
- Since [ rust #76185 ] /[ compiler-team #343 ] , the compiler has a stable
297
+ Since [ rust #76158 ] /[ compiler-team #343 ] , the compiler has a stable
288
298
` -Clink-self-contained ` flag which will look for special object files in
289
299
expected locations, typically populated by the ` rust-std ` components. Its
290
300
behaviour can be forced by ` -Clink-self-contained=true ` , but is force-enabled
@@ -313,7 +323,8 @@ missing special object files.
313
323
[ compiler-builtins ] : #compiler-builtins
314
324
315
325
` compiler-builtins ` is always built with ` -Ccodegen-units=10000 ` to force each
316
- intrinsic into its own object file to avoid symbol clashes with libgcc.
326
+ intrinsic into its own object file to avoid symbol clashes with libgcc. This is
327
+ currently enforced with a profile override in the standard library's workspace.
317
328
318
329
rustc will automatically use a large number of codegen units for the
319
330
` compiler-builtins ` crate, unless manually specified using the ` -Ccodegen-units `
@@ -352,14 +363,15 @@ It will not be enabled by default because it is possible that the target
352
363
platform does not have a suitable C compiler available. The user being able to
353
364
enable this manually will be enabled through work on features (see
354
365
[ * Allow enabling/disabling features with build-std* ] [ future-features ] from Stage
355
- 1b).
366
+ 1b). This will require the user to manually configure ` CFLAGS ` to ensure that
367
+ the c components will link with Rust code.
356
368
357
369
## Caching
358
370
[ caching ] : #caching
359
371
360
372
Standard library artifacts built by build-std will not be shared between crates
361
- or workspaces, as they only exist in the ` target ` directory of a specific crate
362
- or workspace ([ ?] [ rationale-caching ] ).
373
+ or workspaces, as they only exist in Cargo's target directory for a specific
374
+ crate or workspace ([ ?] [ rationale-caching ] ).
363
375
364
376
* See the following sections for rationale/alternatives:*
365
377
@@ -511,7 +523,7 @@ There are various alternatives to putting `build-std` in the Cargo configuration
511
523
512
524
2 . build-std could be enabled or disabled in the ` Cargo.toml ` . However, under
513
525
which conditions the standard library is rebuilt is better determined by the
514
- user of Cargo, rather than the project being built.
526
+ user of Cargo, rather than the package being built.
515
527
516
528
A user may want to never rebuild the standard library so as to avoid
517
529
invalidating the guarantees of their qualified toolchain, or may want to
@@ -672,9 +684,9 @@ which further limits potential use cases to those without `target-modifiers`.
672
684
[ rationale-replace-no_std ] : #why-not-replace-no_std-as-the-source-of-truth-for-whether-a-crate-depends-on-std
673
685
674
686
Crates can currently use the crate attribute ` #![no_std] ` to indicate a lack of
675
- dependency on ` std ` . With ` Cargo.toml ` being used to express a dependency on the
676
- standard library (or lack thereof), it is unintuitive for there to be two
677
- sources-of-truth for this information.
687
+ dependency on ` std ` . With Cargo being used to express a dependency (or lack
688
+ thereof) on the standard library (and further so in [ stage1b ] ) it is unintuitive
689
+ for there to be two sources-of-truth for this information.
678
690
679
691
` #![no_std] ` serves two purposes - it stops the compiler from loading ` std ` from
680
692
the sysroot and adding ` extern crate std ` , and it prevents the user from
@@ -757,14 +769,17 @@ providing an empty path.
757
769
### Why use ` noprelude ` with ` --extern ` ?
758
770
[ rationale-noprelude-with-extern ] : #why-use-noprelude-with---extern
759
771
760
- The ` noprelude ` modifier for ` --extern ` is necessary for use of the ` --extern `
761
- flag to be equivalent to using a modified sysroot.
772
+ Rustc has logic specific to the standard library that decides when to add those
773
+ crates to the extern prelude which will not be changed as part of this RFC.
774
+ Adding The ` noprelude ` modifier for ` --extern ` is necessary for use of the
775
+ ` --extern ` flag to be equivalent to loading from a sysroot.
762
776
763
777
Without ` noprelude ` , rustc implicitly inserts a ` extern crate $name ` when using
764
778
` --extern ` . As a consequence, if a newly-built ` alloc ` were passed using
765
- ` --extern alloc=alloc.rlib ` then ` extern crate alloc ` would not be required, but
766
- it would be if the pre-built ` alloc ` could be used. This difference in how a
767
- crate is made available to rustc should not be observable to the user.
779
+ ` --extern alloc=alloc.rlib ` then ` extern crate alloc ` would not be required to
780
+ use the locall-built ` alloc ` , but it would be to use the pre-built ` alloc ` . This
781
+ difference in how a crate is made available to rustc should not be observable to
782
+ the user.
768
783
769
784
↩ [ * Preventing implicit sysroot dependencies* ] [ preventing-implicit-sysroot-dependencies ]
770
785
@@ -832,19 +847,23 @@ included.
832
847
[ rationale-implied-bootstrap ] : #why-allow-building-from-the-sysroot-with-implied-rustc_bootstrap
833
848
834
849
Cargo needs to be able to build the standard library crates, which inherently
835
- require a nightly toolchain. It could set ` RUSTC_BOOTSTRAP ` internally to do
836
- this with a stable toolchain, however this is a shared requirement with other
837
- build systems that wish to build an unmodified standard library and want to work
838
- on stable toolchains.
839
-
840
- For example, Rust's project goal to enable Rust for Linux to build using only a
841
- stable toolchain would require that it be possible to build ` core ` without
842
- nightly.
850
+ require a nightly toolchain. This is a shared requirement with other build
851
+ systems that wish to build an unmodified standard library and want to work
852
+ on stable toolchains. For example, Rust's project goal to enable Rust for Linux
853
+ to build using only a stable toolchain would require that it be possible to
854
+ build ` core ` without nightly.
855
+
856
+ Cargo could continue to set ` RUSTC_BOOTSTRAP ` internally when building standard
857
+ library crates with a stable toolchain, but the Rust project
858
+ [ does not wish to encourage] [ rustc-bootstrap-docs ] widespread usage of this
859
+ "escape-hatch" where possible. Allowing crate sources in the sysroot to use
860
+ nightly features is a compromise and fits into the model of the sysroot being
861
+ unique to that version of the toolchain.
843
862
844
863
It is not sufficient for rustc to special-case the ` core ` , ` alloc ` and ` std `
845
- crate names as when being built as part of the standard library, dependencies of
846
- the standard library also use unstable features and so these crate would also
847
- need such special-casing, which is not practical.
864
+ crate names as when being built as part of the standard library dependencies of
865
+ the standard library also use unstable features. These crates would also need
866
+ such special-casing, which is not practical.
848
867
849
868
↩ [ * Building the standard library on a stable toolchain* ] [ building-the-standard-library-on-a-stable-toolchain ]
850
869
@@ -964,11 +983,13 @@ produced by build-std.
964
983
965
984
[ compiler-builtins#411 ] : https://github.com/rust-lang/compiler-builtins/pull/411
966
985
[ compiler-team#343 ] : https://github.com/rust-lang/compiler-team/issues/343
967
- [ rust#76185 ] : https://github.com/rust-lang/rust/pull/76185
986
+ [ rust#76158 ] : https://github.com/rust-lang/rust/pull/76158
968
987
[ rust#71009 ] : https://github.com/rust-lang/rust/pull/71009
988
+ [ rust#84124 ] : https://github.com/rust-lang/rust/pull/84124
969
989
[ rust#135395 ] : https://github.com/rust-lang/rust/pull/135395
970
990
971
991
[ std-build.rs ] : https://github.com/rust-lang/rust/blob/f315e6145802e091ff9fceab6db627a4b4ec2b86/library/std/build.rs#L17
992
+ [ rustc-bootstrap-docs ] : https://doc.rust-lang.org/nightly/unstable-book/compiler-environment-variables/RUSTC_BOOTSTRAP.html#stability-policy
972
993
973
994
[ cargo-add ] : https://doc.rust-lang.org/cargo/commands/cargo-add.html
974
995
[ cargo-bench ] : https://doc.rust-lang.org/cargo/commands/cargo-bench.html
0 commit comments