33- RFC PR: [ rust-lang/rfcs #0000 ] ( https://github.com/rust-lang/rfcs/pull/0000 )
44- Rust Issue: [ rust-lang/rust #0000 ] ( https://github.com/rust-lang/rust/issues/0000 )
55
6+ <!--
7+
8+ This document is long and has lots of authors, follow these rules to maintain a
9+ consistent voice and structure:
10+
11+ Writing style:
12+
13+ - Text is wrapped at ~80 characters, except for headings
14+
15+ - Use the passive voice
16+
17+ - Items in bullet point lists shouldn't end with a period
18+
19+ - Avoid introducing sections that only include other sections and no written
20+ content within them
21+
22+ - In the proposals, write as if the feature has already been accepted and
23+ implemented
24+
25+ - Leave a line between each bullet point
26+
27+ - With the exception of table of contents-style sections (in this document and
28+ in Appendix I), always use reference-style links
29+
30+ - Use a spell checker and broken link checker
31+
32+ Structure:
33+
34+ - Every header has a reference link defined below it with its anchor. Top-level
35+ sections just match the header text. Other sections have a prefix (e.g.
36+ "rationale-foo", not "foo")
37+
38+ - Add parentheses with `([?][anchor])` wherever an explanation is justified,
39+ linking to the relevant sub-section in the rationale/alternative section. This
40+ is not required for unresolved questions and future possibilities
41+
42+ - Each justification/alternative in a section must be included in the bullet
43+ list at the bottom of that sub-section, likewise with unresolved questions and
44+ future possibilities
45+
46+ - Each future possibility, unresolved question and rationale/alternative must
47+ backlink back to the section that links to it
48+
49+ - Rationale/alternatives must be in the order that they are referenced in the
50+ text, including in end-of-sub-section lists
51+
52+ - Add anyone who has provided feedback prior to the publication of the RFC to
53+ the acknowledgements section
54+
55+ Consistency:
56+
57+ - Ensure that Appendix I is up-to-date after any changes
58+
59+ - Appendix II should only reflect the discussion on the cited sources, rather
60+ than the current status quo if it has changed
61+
62+ - build-std should not be in backticks (i.e. not `build-std`)
63+
64+ - "pre-built" should always have a hyphen
65+
66+ - Crate names, Cargo configuration options, compiler flags, file names and
67+ environment variables should always be in a backticks (e.g. `build-std`)
68+
69+ - Values passed to compiler flags should be in double quotes (e.g. "compatible")
70+
71+ Git:
72+
73+ - Try to keep each individual change to a single commit and describe that change
74+ in the commit message
75+
76+ - This makes it easier to review and catch-up
77+
78+ - Keep the first line of commit messages limited to 50 characters and the
79+ remaining lines to 74 characters
80+
81+ -->
82+
683# Summary
784[ summary ] : #summary
885
@@ -14,6 +91,14 @@ supported:
14912 . Rebuilding the standard library with ABI-modifying flags
15923 . Building the standard library for tier three targets
1693
94+ This RFC proposes a handful of changes to Cargo, the compiler and standard
95+ library with the goal of defining a minimal build-std that has the potential of
96+ being stabilised:
97+
98+ - Explicitly declaring support for the standard library in target specs
99+ - Explicit and implicit dependencies on the standard library in ` Cargo.toml `
100+ - Re-building the standard library when the profile or target modifiers change
101+
17102This RFC is co-authored by [ David Wood] [ davidtwco ] and
18103[ Adam Gemmell] [ adamgemmell ] . To improve the readability of this RFC, it does not
19104follow the standard RFC template, while still aiming to capture all of the
@@ -38,6 +123,20 @@ As a general rule, this RFC tries to answer the question "what crates of the
38123standard library get built and when do they get built" and considers anything
39124else as likely out-of-scope.
40125
126+ ### Acknowledgements
127+ [ acknowledgements ] : #acknowledgements
128+
129+ This RFC would not have been possible without the advice, feedback and support
130+ of [ Josh Triplett] [ joshtriplett ] , [ Eric Huss] [ ehuss ] ,
131+ [ Wesley Wiser] [ wesleywiser ] and [ Tomas Sedovic] [ tomassedovic ] .
132+
133+ Thanks to [ mati865] for advising on some of the specifics related to special
134+ object files, [ petrochenkov] for his expertise on rustc's dependency loading and
135+ name resolution; [ fee1-dead] for their early and thorough reviews and to
136+ [ Ed Page] [ epage ] for writing about opaque dependencies.
137+
138+ Thanks to [ Jacob Bramley] [ jacobbramley ] for their feedback on early drafts.
139+
41140### Terminology
42141[ terminology ] : #terminology
43142
@@ -48,15 +147,47 @@ The following terminology is used throughout the RFC:
48147- "std" is used to refer only to the ` std ` crate, not the entirety of the standard
49148 library
50149
150+ Throughout the RFC's "Proposal" sections, parentheses with "?" links will be
151+ present that which link the relevant section in the appropriate "Rationale and
152+ alternatives" section to justify a decision or provide alternatives to it.
153+
154+ Additionally, "note alerts" will be used in the * Proposal* sections to separate
155+ implementation considerations from the core proposal. Implementation detail
156+ should be considered non-normative. These details could change during
157+ implementation and are present solely to demonstrate that the implementation
158+ feasibility has been considered and to provide an example of how implementation
159+ could proceed.
160+
161+ > [ !NOTE]
162+ >
163+ > This is an example of a "note alert" that will be used to separate
164+ > implementation detail from the proposal proper.
165+
51166# Contents
52167[ contents ] : #contents
53168
54- This RFC has the following contents:
169+ This RFC has been split into multiple stages. Each stage is a
170+ self-contained proposal building on the previous, which could be accepted,
171+ implemented and stabilised on its own.
172+
173+ As build-std is a complex feature with many interdependent design decisions, it
174+ is challenging to draft a proposal that is small enough to have an achievable
175+ scope in the short-to-medium term while making a convincing argument that it is
176+ forward-compatible with any desired future extensions. A staged proposal enables
177+ this - each stage can have a small and achievable scope, while still allowing a
178+ reviewer to skip ahead and get a sense of what is planned and how that builds on
179+ what came before.
180+
181+ Later stages are less detailed and complete than the previous stages, intended
182+ to indicate the intended direction that the RFC will take and help provide
183+ context for the proposals of earlier stages.
55184
561851 . [ Summary] [ summary ] (you are here)
57186
58187 - Introduction to the proposal, its scope, terminology/conventions used and
59188 the structure of the RFC
189+
190+ - [ Proposal-wide rationale and alternatives] [ rationale-and-alternatives ]
60191
611922 . [ Background] ( ./1-background.md )
62193
@@ -74,7 +205,75 @@ This RFC has the following contents:
74205 - Descriptions of the varied problems that build-std has been proposed as a
75206 solution to
76207
77- 1 . [ Appendix II: Exhaustive literature review] ( ./4-appendix-literature-review.md )
208+ 5 . [ Stage 1a: build-std=always] ( ./4-stage-1a.md )
209+
210+ - Proposes adding a ` build-std = "always|off" ` option to the Cargo
211+ configuration which will unconditionally re-build the standard library
212+ crates listed in the ` build-std-crates ` option
213+
214+ - [ Proposal] ( ./4-stage-1a.md#proposal )
215+
216+ - [ Rationale and alternatives] ( ./4-stage-1a.md#rationale-and-alternatives )
217+
218+ - [ Unresolved questions] ( ./4-stage-1a.md#unresolved-questions )
219+
220+ - [ Future possibilities] ( ./4-stage-1a.md#future-possibilities )
221+
222+ 6 . [ Stage 1b: Explicit dependencies] ( ./5-stage-1b.md )
223+
224+ - Proposes supporting explicit dependencies on the standard library crates in
225+ ` Cargo.toml `
226+
227+ - Enables Cargo to determine which standard library crates are required by
228+ the crate graph without ` build-std-crates ` being set
229+
230+ - Necessary for future extensions which support public/private standard
231+ library dependencies or enabling features of the standard library
232+
233+ - [ Proposal] ( ./5-stage-1b.md#proposal )
234+
235+ - [ Rationale and alternatives] ( ./5-stage-1b.md#rationale-and-alternatives )
236+
237+ - [ Unresolved questions] ( ./5-stage-1b.md#unresolved-questions )
238+
239+ - [ Future possibilities] ( ./5-stage-1b.md#future-possibilities )
240+
241+ 7 . [ Stage 2: build-std=compatible] ( ./6-stage-2.md )
242+
243+ - Proposes extending the ` build-std ` option with a new ` compatible ` value
244+ which will become the default and automatically rebuilds the standard
245+ library when it is necessary to maintain compatibility with the compiler
246+ flags used by the rest of the crate graph.
247+
248+ - [ Proposal] ( ./6-stage-2.md#proposal )
249+
250+ - [ Rationale and alternatives] ( ./6-stage-2.md#rationale-and-alternatives )
251+
252+ - [ Unresolved questions] ( ./6-stage-2.md#unresolved-questions )
253+
254+ - [ Future possibilities] ( ./6-stage-2.md#future-possibilities )
255+
256+ 8 . [ Stage 3: build-std=match-profile] ( ./7-stage-3.md )
257+
258+ - Proposes extending the ` build-std ` option with new values which
259+ automatically rebuild the standard library to match the user's current
260+ profile.
261+
262+ - [ Proposal] ( ./7-stage-3.md#proposal )
263+
264+ - [ Rationale and alternatives] ( ./7-stage-3.md#rationale-and-alternatives )
265+
266+ - [ Unresolved questions] ( ./7-stage-3.md#unresolved-questions )
267+
268+ - [ Future possibilities] ( ./7-stage-3.md#future-possibilities )
269+
270+ 9 . [ Appendix I: Summary of changes] ( ./8-appendix-summary-of-changes.md )
271+
272+ - Summary of each of the changes from each stage which would need implemented
273+ in the Rust toolchain, grouped by the project team whose purview the change
274+ would fall under
275+
276+ 10 . [ Appendix II: Exhaustive literature review] ( ./9-appendix-literature-review.md )
78277
79278 - More detailed summaries of the relevant issues, discussions, pull requests
80279 and proposals that comprise the history of the build-std feature since
@@ -83,5 +282,54 @@ This RFC has the following contents:
83282 - [ * History* ] ( ./2-history.md ) aims to summarise this content further and
84283 cover everything that should be necessary to understand the proposal
85284
285+ # Rationale and alternatives
286+ [ rationale-and-alternatives ] : #rationale-and-alternatives
287+
288+ These rationales and alternatives apply to the proposal as-a-whole, rather than
289+ any specific stage:
290+
291+ ## Why not do nothing?
292+ [ rationale-why-not-do-nothing ] : #why-not-do-nothing
293+
294+ Support for rebuilding the standard library is a long-standing feature request
295+ from subsets of the Rust community and blocks the work of some project teams
296+ (e.g. sanitisers and branch protection in the compiler team, amongst others).
297+ Inaction forces these users to remain on nightly and depend on the unstable
298+ ` -Zbuild-std ` flag indefinitely. RFCs and discussion dating back to the first
299+ stable release of the language demonstrate the longevity of build-std as a
300+ need.
301+
302+ ## Shouldn't build-std be part of rustup?
303+ [ rationale-in-rustup ] : #shouldnt-build-std-be-part-of-rustup
304+
305+ build-std is effectively creating a new sysroot with a customised standard
306+ library. rustup as Rust's toolchain manager has lots of existing machinery
307+ to create and maintain sysroots. rustup knows how to download ` rust-src ` , it
308+ knows how to create a new toolchain from an existing sysroot (as in
309+ ` rustup toolchain link ` ), it would only need to learn how to invoke Cargo on the
310+ ` rust-src ` sources. rustup would be invoking tools from the next layer of
311+ abstraction (Cargo) in the same way that Cargo invokes tools from the layer of
312+ abstraction after it (rustc).
313+
314+ A brief prototype of this idea was created and a
315+ [ short design document was drafted] [ why-not-rustup ] before concluding that it
316+ would not be possible. With artifact dependencies, it may be desirable to build
317+ with a different standard library and if rustup was creating different
318+ toolchains per-customised standard library then Cargo would need to have
319+ knowledge of these to switch between them, which isn't possible (and something
320+ of a layering violation). It is also unclear how Cargo would find and use the
321+ uncustomized host sysroot for build scripts and procedural macros.
322+
86323[ davidtwco ] : https://github.com/davidtwco
87- [ adamgemmell ] : https://github.com/adamgemmell
324+ [ adamgemmell ] : https://github.com/adamgemmell
325+ [ ehuss ] : https://github.com/ehuss
326+ [ epage ] : https://github.com/epage
327+ [ fee1-dead ] : https://github.com/fee1-dead
328+ [ jacobbramley ] : https://github.com/jacobbramley
329+ [ joshtriplett ] : https://github.com/joshtriplett
330+ [ mati865 ] : https://github.com/mati865
331+ [ petrochenkov ] : https://github.com/petrochenkov
332+ [ tomassedovic ] : https://github.com/tomassedovic
333+ [ wesleywiser ] : https://github.com/wesleywiser
334+
335+ [ why-not-rustup ] : https://hackmd.io/@davidtwco/rkYRlKv_1x
0 commit comments