Skip to content

Commit 4c0ea2a

Browse files
committed
First version
I clarified and cleaned up some things, but force-pushed as - The ideas are the same, just the wording is changed - At the time of commit, I had not yet submitted the PR
1 parent 7f3d678 commit 4c0ea2a

File tree

1 file changed

+74
-8
lines changed

1 file changed

+74
-8
lines changed

Diff for: text/0000-cargo-libstd-awareness.md

+74-8
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,92 @@
55

66
# Summary
77

8-
One para explanation of the feature.
8+
Currently, all packages implicitly depend on libstd. This makes Cargo unsuitable for packages that
9+
need a custom-built libstd, or otherwise depend on crates with the same names as libstd and the
10+
crates behind the facade. The proposed fixes also open the door to a future were libstd can be
11+
Cargoized.
912

1013
# Motivation
1114

12-
Why are we doing this? What use cases does it support? What is the expected outcome?
15+
Bare-metal work cannot use a standard build of libstd. But since any crate built with Cargo can link
16+
with a system-installed libstd if the target matches, using Cargo for such projects can be irksome
17+
or impossible.
18+
19+
Cargoizing libstd also generally simplifies the infrastructure, and makes cross compiling much
20+
slicker, but that is a separate discussion.
21+
22+
Finally, I first raised this issue here: https://github.com/rust-lang/Cargo/issues/1096 Also, there
23+
are some (heavily bit-rotted) projects at https://github.com/RustOS-Fork-Holding-Ground that depend
24+
on each other in the way this RFC would make much more feasible.
1325

1426
# Detailed design
1527

16-
This is the bulk of the RFC. Explain the design in enough detail for somebody familiar
17-
with the language to understand, and for somebody familiar with the compiler to implement.
18-
This should get into specifics and corner-cases, and include examples of how the feature is used.
28+
The current situation seems to be more of an accident of `rustc`'s pre-Cargo history than an
29+
explicit design decision. Cargo passes the location and name of all depended on crates to `rustc`.
30+
This is good because it means that that no undeclared dependencies on other Cargo packages can leak
31+
through. However, it also passes in `--sysroot /path/to/some/libdir`, the directory being were
32+
libstd is. This means packages are free to use libstd, the crates behind the facade, or none of the
33+
above, with Cargo being none the wiser.
34+
35+
The only new interface proposed is a boolean field to the package meta telling Cargo that the
36+
package does not depend on libstd by default. This need not imply Rust's `no_std`, as one might want
37+
to `use` their own build of libstd by default. To disambiguate, this field is called
38+
q`no-implicit-deps`; please, go ahead and bikeshead the name. `no-implicit-deps` is false by
39+
default to maintain compatibility with existing packages.
40+
41+
The meaning of this flag is defined in 3 phases, where each phase extends the last. The idea being
42+
is that while earlier phases are easier to implement, later phases yield a more elegant system.
43+
44+
## Phase 1
45+
46+
Add a `--no-sysroot` flag to `rustc`, and pass that to `rustc` is the case that `no-implicit-deps`
47+
is true.
48+
49+
This hotfix is enough to allow us bare-metal devs to use Cargo for our own projects, but doesn't
50+
suffice for creating an ecosystem of packages that depend on crates behind the facade but not libstd
51+
itself. This is because the choices are all or nothing: Either one implicitly depends on libstd or
52+
the crates behind the facade, or they don't depend on them at all.
53+
54+
## Phase 2
55+
56+
Since, passing in a directory of crates is inherently more fragile than passing in a crate
57+
itself, make Cargo use `--no-sysroot` in all cases.
58+
59+
Cargo would special case package names corresponding to the crates behind the facade, such that if
60+
the package don't exist, it would simply pass the corresponding system crate to `rustc`. I assume
61+
the names are blacklisted on crates.io already, so by default the packages won't exist. But users
62+
can use config files to extend the namespace so their own modded libstds can be used instead. Even
63+
if they don't want to change libstd but just cross-compile it, this is frankly the easiest way as
64+
Cargo will seemliest cross compile both their project and it's transitive dependencies.
65+
66+
In this way we can put packages on crates.io that depend on the crates behind the facade. Some
67+
packages that already exist, like liblog and libbitflags, should be given features that optionally
68+
allow them to avoid libstd and just depend directly on the crates behind the facade they really
69+
need.
70+
71+
## Phase 3
72+
73+
If/when the standard library is built with Cargo and put on crates.io, all the specially-cased
74+
package names can be treated normally,
75+
76+
The standard library is be downloaded and built from crates.io. Or equivalently, Cargo comes with a
77+
cache of that build, as Cargo should be able cache builds between projects at this point. Just as in
78+
phase 2, `no-implicit-deps` just prevents libstd from implicitly being appended to the list of
79+
dependencies.
80+
81+
Again, to make this as least controversial as possible, this RFC does not propose outright that the
82+
standard library should be Cargoized. This 3rd phases just describes how this feature would work
83+
were that to happen.
1984

2085
# Drawbacks
2186

22-
Why should we *not* do this?
87+
I really don't know of any. Development for hosted environments would hardly be very affected.
2388

2489
# Alternatives
2590

26-
What other designs have been considered? What is the impact of not doing this?
91+
Make it so all dependencies, even libstd, must be explicit. C.f. Cabal and base.
2792

2893
# Unresolved questions
2994

30-
What parts of the design are still TBD?
95+
There are multiple lists of dependencies for different things (e.g. tests), Should libstd be append
96+
to all of them in phases 2 and 3?

0 commit comments

Comments
 (0)