-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Cargo aware of standard library dependencies #1133
Changes from 2 commits
7f3d678
4c0ea2a
eee7dba
9da1b02
630ac97
a7425e6
37e9246
d549d15
b3476e1
c22463f
c257f34
4a8bf9b
4b4d8a3
1ee980f
f0a0b3b
3422763
8392c4a
ffc442b
1c53ae1
cc8a1f2
71ba640
9a61baa
89a461a
4656eb9
984bcb5
af9442b
d16f8c3
77be419
afae118
a1f8ab1
2334770
61cd8ca
fac0c9b
a062095
bbf1ec6
81a923a
51cfdb6
a36a46b
e6aae38
7e73557
f7fd3df
b327075
d38daad
f8859d5
d208a5f
cb67deb
e8b1aa2
477d8bc
b9aa2da
26e1b6e
d35237f
28353b2
44f1e84
2ea3e83
324e225
02889b8
bbc503b
b1e1b4b
50a0862
e8f14b7
c501fd9
2719c44
54aa001
2774668
d85091a
ee4104f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
- Feature Name: cargo_libstd_awareness | ||
- Start Date: 2015-05-26 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
# Summary | ||
|
||
Currently, all packages implicitly depend on libstd. This makes Cargo unsuitable for packages that | ||
need a custom-built libstd, or otherwise depend on crates with the same names as libstd and the | ||
crates behind the facade. The proposed fixes also open the door to a future were libstd can be | ||
Cargoized. | ||
|
||
# Motivation | ||
|
||
Bare-metal work cannot use a standard build of libstd. But since any crate built with Cargo can link | ||
with a system-installed libstd if the target matches, using Cargo for such projects can be irksome | ||
or impossible. | ||
|
||
Cargoizing libstd also generally simplifies the infrastructure, and makes cross compiling much | ||
slicker, but that is a separate discussion. | ||
|
||
Finally, I first raised this issue here: https://github.com/rust-lang/Cargo/issues/1096 Also, there | ||
are some (heavily bit-rotted) projects at https://github.com/RustOS-Fork-Holding-Ground that depend | ||
on each other in the way this RFC would make much more feasible. | ||
|
||
# Detailed design | ||
|
||
The current situation seems to be more of an accident of `rustc`'s pre-Cargo history than an | ||
explicit design decision. Cargo passes the location and name of all depended on crates to `rustc`. | ||
This is good because it means that that no undeclared dependencies on other Cargo packages can leak | ||
through. However, it also passes in `--sysroot /path/to/some/libdir`, the directory being were | ||
libstd is. This means packages are free to use libstd, the crates behind the facade, or none of the | ||
above, with Cargo being none the wiser. | ||
|
||
The only new interface proposed is a boolean field to the package meta telling Cargo that the | ||
package does not depend on libstd by default. This need not imply Rust's `no_std`, as one might want | ||
to `use` their own build of libstd by default. To disambiguate, this field is called | ||
q`no-implicit-deps`; please, go ahead and bikeshead the name. `no-implicit-deps` is false by | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The specific name doesn't concern me too much, but do make it boolean-positive instead of negative. So instead of having Whatever name is bikeshedded should be boolean-positive. |
||
default to maintain compatibility with existing packages. | ||
|
||
The meaning of this flag is defined in 3 phases, where each phase extends the last. The idea being | ||
is that while earlier phases are easier to implement, later phases yield a more elegant system. | ||
|
||
## Phase 1 | ||
|
||
Add a `--no-sysroot` flag to `rustc`, and pass that to `rustc` is the case that `no-implicit-deps` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar here; instead of |
||
is true. | ||
|
||
This hotfix is enough to allow us bare-metal devs to use Cargo for our own projects, but doesn't | ||
suffice for creating an ecosystem of packages that depend on crates behind the facade but not libstd | ||
itself. This is because the choices are all or nothing: Either one implicitly depends on libstd or | ||
the crates behind the facade, or they don't depend on them at all. | ||
|
||
## Phase 2 | ||
|
||
Since, passing in a directory of crates is inherently more fragile than passing in a crate | ||
itself, make Cargo use `--no-sysroot` in all cases. | ||
|
||
Cargo would special case package names corresponding to the crates behind the facade, such that if | ||
the package don't exist, it would simply pass the corresponding system crate to `rustc`. I assume | ||
the names are blacklisted on crates.io already, so by default the packages won't exist. But users | ||
can use config files to extend the namespace so their own modded libstds can be used instead. Even | ||
if they don't want to change libstd but just cross-compile it, this is frankly the easiest way as | ||
Cargo will seemliest cross compile both their project and it's transitive dependencies. | ||
|
||
In this way we can put packages on crates.io that depend on the crates behind the facade. Some | ||
packages that already exist, like liblog and libbitflags, should be given features that optionally | ||
allow them to avoid libstd and just depend directly on the crates behind the facade they really | ||
need. | ||
|
||
## Phase 3 | ||
|
||
If/when the standard library is built with Cargo and put on crates.io, all the specially-cased | ||
package names can be treated normally, | ||
|
||
The standard library is be downloaded and built from crates.io. Or equivalently, Cargo comes with a | ||
cache of that build, as Cargo should be able cache builds between projects at this point. Just as in | ||
phase 2, `no-implicit-deps` just prevents libstd from implicitly being appended to the list of | ||
dependencies. | ||
|
||
Again, to make this as least controversial as possible, this RFC does not propose outright that the | ||
standard library should be Cargoized. This 3rd phases just describes how this feature would work | ||
were that to happen. | ||
|
||
# Drawbacks | ||
|
||
I really don't know of any. Development for hosted environments would hardly be very affected. | ||
|
||
# Alternatives | ||
|
||
Make it so all dependencies, even libstd, must be explicit. C.f. Cabal and base. | ||
|
||
# Unresolved questions | ||
|
||
There are multiple lists of dependencies for different things (e.g. tests), Should libstd be append | ||
to all of them in phases 2 and 3? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/were/where
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!