Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMake Cargo aware of standard library dependencies #1133
Conversation
Ericson2314
added some commits
May 25, 2015
This comment has been minimized.
This comment has been minimized.
posix4e
commented
May 26, 2015
|
Wow neat |
tshepang
reviewed
May 26, 2015
|
|
||
| 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 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
A funny 'coin'cidence is that the Java folks at Oracle are currently testing a similar concept (and they needed 9 major versions to get there). |
Valloric
reviewed
May 26, 2015
| 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 |
This comment has been minimized.
This comment has been minimized.
Valloric
May 26, 2015
The specific name doesn't concern me too much, but do make it boolean-positive instead of negative. So instead of having no-implicit-deps and setting it to false by default, make it use-implicit-deps and make it true by default.
Whatever name is bikeshedded should be boolean-positive.
Valloric
reviewed
May 26, 2015
|
|
||
| ## Phase 1 | ||
|
|
||
| Add a `--no-sysroot` flag to `rustc`, and pass that to `rustc` is the case that `no-implicit-deps` |
This comment has been minimized.
This comment has been minimized.
Valloric
May 26, 2015
Similar here; instead of --no-sysroot, make it --use-sysroot=false (with the default being true).
Ericson2314
force-pushed the
Ericson2314:cargo-libstd
branch
from
2ce5b77
to
86f72e4
May 26, 2015
Ericson2314
force-pushed the
Ericson2314:cargo-libstd
branch
from
86f72e4
to
9da1b02
May 26, 2015
This comment has been minimized.
This comment has been minimized.
|
@Valloric in case you don't get a notification from the commit message, I did what you suggested with the exception that the field is just called |
This comment has been minimized.
This comment has been minimized.
Valloric
commented
May 26, 2015
|
@Ericson2314 That's fine; like I said, I don't personally care much about the name (you'll get more than enough bikeshedding from others), only that a double negative is avoided. |
alexcrichton
added
the
T-dev-tools
label
May 26, 2015
This comment has been minimized.
This comment has been minimized.
llogiq
commented on text/0000-cargo-libstd-awareness.md in 4c0ea2a
May 28, 2015
|
That should probably read "...is to be downloaded...". |
This comment has been minimized.
This comment has been minimized.
|
I was flip/floping on what tense to use, so I think should be just "...is downloaded", but thanks for the catch! |
This comment has been minimized.
This comment has been minimized.
|
Also the text states that "std should be on crates.io" – the rust distribution should still contain all of std anyway, right? Otherwise people who download rust to try it during their commute are going to have a hard time. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the RFC @Ericson2314! I'm always quite eager to improve the cross-compilation experience of Rust, and I think that this will help out embedded targets and such quite a bit! At a high level, could you clarify the motivation for this RFC a bit more in the text? After reading it it's not clear to me what the RFC is trying to achieve. For example:
I think that refining the motivation will help me understand more of the detailed design as well, but I'll make some specific comments below about this.
I'm curious where you came up with this? Cargo doesn't pass
This worries me a bit, I don't think we want the ability to swap in an alternate standard library in a super easy fashion. If you're depending on your own "standard library", then I think it should be just that, a dependency in
Can you clarify why you can't use Cargo for these kinds of projects today? If you use
I also unfortunately don't fully understand what's going on here. Can you elaborate why you want to swap out a separate libstd than the one the compiler may already find elsewhere? If crates can be tracked in Cargo, then I definitely think they should, so I don't follow the motivation to not use
I don't quite understand this comment because this can already be done? I can upload a crate which says Overall I think this RFC feels like it's "bolting on" features after the fact instead of creating a well-integrated and smooth system with Cargo. I believe this is also (depending on the motivation) highly inter-related with #1005, and it may wish to be considered here. I think some refinement of the motivation, however, will help guide this RFC, though! |
Ericson2314
added some commits
May 28, 2015
Ericson2314
force-pushed the
Ericson2314:cargo-libstd
branch
from
0d76898
to
a7425e6
May 29, 2015
This comment has been minimized.
This comment has been minimized.
|
Ok, I talked to @alexcrichton for a long while on IRC, and then rewrite the RFC. In short, I massively elaborated the motivation, and cut phase 1. I'm respond to some his points, which will also offer some summery of what we talked about, though go to the IRC logs if you're really curious.
All three of those are valid motivation for this.
I extrapolated incorrectly from his comments in the issue I opened long ago. It's fixed in the current RFC. The larger picture is the same either way however: Cargo allows
I'm OK with having
I agree wholeheartedly, but this is currently not possible if crate names + target platform overlap with anything that is in the sysroot.
This this can only be accomplished with a Cargo config override, which I consider sufficiently hacky. It's possible phase 1 would have allowed this to happen more accidentally, but that's outta here.
I wanted libcore to be cross compiled automatically, but if on some machines the host and target match (i.e. no cross compile), the build will fail. See the expanded motivation for more details.
I meant do this in a such that all deps can be (cross-)compiled automatically. See rewritten RFC and below.
I think I was able to explain my case on IRC. Basically @alexcrichton and I (and presumably you, dear reader, too) would like easy no-brainer cross compiling. If we don't make packages state which of libstd or its backing crates packages they need, future Cargo needs to download/build everything to play it safe, and needs to do that for ever. By treating these things as normal deps, Cargo can do something adhoc like querying a Mozilla build farm, but can seamlessly transition to just building them like any other package if they get Cargoized. Then all that ad hoc functionality can be thrown out the window. Finally, if you use a unstable compiler, you can cross compile your own libstd today, and it is nice to do so. While it would be great to standardize libcore, using it effectively requires a fair amount of lang items, and if those are standardized, perhaps all of libcore's implementation could to[1]. Thus, for the time being, freestanding development is probably going to require a compiler that is capable of building libcore, and it just so happens that those people benefit from that the most, so we might as well give them a way to cross compile their whole project---libcore up---today. [1] @alexcrichton pointed out that with standardization there might be less overlap with the lang needed items to use libcore and the lang items it uses in its implementation, quite possible. |
alexcrichton
reviewed
May 30, 2015
|
|
||
|
|
||
| However rather than passing in libstd and its deps, Cargo lets the compiler look for them as need in | ||
| the compiler's sysroot [specifically `<sysroot>/lib/<target>`]. This is quite coarse in comparison, |
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 30, 2015
Member
I think it's important to spell out here that it's far from standard practice to dump libraries in the sysroot, and the only stable library in the sysroot today is libstd. We have been very hesitant to stabilize any more than precisely one library for many of these reasons.
This comment has been minimized.
This comment has been minimized.
Ericson2314
May 30, 2015
Author
Contributor
I'm a bit confused what you'd like me to elaborate on. I already wanted to emphasize we just do this in the case of libstd and its dependencies---in other words that we are so close---just 1 library away!---from not linking with the sysroot at all.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jun 1, 2015
Member
Hm re-reading I'm not quite sure what I was thinking... It may have been from the aspect that "and its deps" isn't so relevant in stable Rust today as libstd is the only library that can be implicitly linked to.
This comment has been minimized.
This comment has been minimized.
alexcrichton
reviewed
May 30, 2015
| - Packages may link or not link against libs in that directory as they please, with Cargo being | ||
| none the wiser. | ||
|
|
||
| - Cargo-built crates with the same name as those in there will collide, as the sysroot libs don't |
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 30, 2015
Member
This isn't quite true, for example liblibc exists in both the sysroot and on crates.io. Cargo will pass --extern libc=... which overrides everything (including the sysroot).
This comment has been minimized.
This comment has been minimized.
Ericson2314
May 30, 2015
Author
Contributor
Hmm, I'll need to update my code so I can see why the build is failing, or whether it does today.
alexcrichton
reviewed
May 30, 2015
| compile libstd for me. Since I needed to use an unstable compiler anyways, it was possible in | ||
| principle to build absolutely everything I needed with the same `rustc` version. Because of some | ||
| trouble with Cargo and target JSONs, I didn't use a custom target specification, and just used | ||
| `x86_64-gnu-linux`, meaning that depending on platform I was compiling on, I may or may have been |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
reviewed
May 30, 2015
| bikeshead the name. `implicit-deps` is true by default to maintain compatibility with existing | ||
| packages. When true, "std" will be implicitly appended to the list of dependencies. | ||
|
|
||
| When Cargo sees a package name it cannot resolve, it will query `rustc` for the default sysroot, and |
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 30, 2015
Member
Could you clarify what this means for "a package name it cannot resolve"? For example Cargo does not attempt to resolve the name "std" in any way today, so I'm not sure where this sort of resolution failure will start from.
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 30, 2015
Member
Reading a little more, my interpretation is that you're proposing that a crate explicitly declares that it depends on core and std (if the boolean field above is specified), is that right? If so, can you go into some more detail about what the syntax for doing so might be?
This comment has been minimized.
This comment has been minimized.
Ericson2314
Jun 15, 2015
Author
Contributor
Basically, I want it so
implicit-deps = false;
[dependencies]
core = "*" # Or some more appropriate version specifier
alloc = "*"
# ...other crates behind the facade....
std = "*"and
implicit-deps = true;and
# implicit-deps is true by defaultall mean the same thing.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jun 15, 2015
Member
Hm ok, your first snippet has a bit of a different interpretation because it means the dependencies like std come from crates.io, which probably isn't going to happen any time soon. Put another way there's no way to express a dependency on std in Cargo.toml today because we distribute it in binary form instead of on crates.io.
I think the reason I'm somewhat uneasy to add implicit-deps is that if you specify implicit-deps there's no way for you to actually link to the standard library. Did you have something in mind for doing that?
This comment has been minimized.
This comment has been minimized.
Ericson2314
Jun 16, 2015
Author
Contributor
Mmm, this RFC changes the way cargo works so that depended-on crates not on crates.io are looked for in the syroot instead, precisely so we can continue distributing those crates the same way for the time being. This allows:
- A clear migration path to a future where those crates are defined on crates.io
- A finer way to distinguish what functionality libraries intended for kernel use need
- Unstable rust users to locally define those crates so cargo cross-compiles them with the rest of their program.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jun 17, 2015
Member
Ah I see what this is saying now, although unfortunately I feel like that's a little too much magic going on under the hood. Cargo understands the "source" for any particular package, and it needs to understand if that source is crates.io or the sysroot ahead of time. Along those lines I think that this needs to have some new source syntax, such as:
[dependencies]
std = { rustc-sysroot = true }
This comment has been minimized.
This comment has been minimized.
Ericson2314
Jun 17, 2015
Author
Contributor
While yes, that does make Cargo's life easier, does this information really belong in the package metadata? A package just cares what version std is, not how cargo obtained it. Also, if we switch to deploying these crates via crates.io before the end of 1.0, we wouldn't want packages to break because they mandated that std must come from the sysroot.
That said, I'd still rather have that than the status quo. IIRC local packages (with cargo config) override no matter the version so this doesn't prohibit my third bullet point in my previous post.
alexcrichton
reviewed
May 30, 2015
| The only new interface proposed is a boolean field in `Cargo.toml` specifying that the package does | ||
| not depend on libstd by default. Note that this is technically orthogonal to Rust's `no_std`, as one | ||
| might want to `use` their own build of libstd by default, or implicitly depend on it but not | ||
| glob-import the prelude. To disambiguate, this field is called `implicit-deps`; please, go ahead and |
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 30, 2015
Member
Looking at this from another angle, the only implicitly available crate that is available in stable Rust is std. This means that we have quite a bit of freedom when considering the other crates distributed with Rust itself. For example this field could in theory just be implicit-std = false which passes a flag to the compiler disabling the implicit usage of std, and then the compiler will implicitly deny access to all other crates by default (e.g. even libcore).
Just a note that we have very few constraints today (just the name "std"), and we can do whatever we like with the other deps.
This comment has been minimized.
This comment has been minimized.
Ericson2314
May 30, 2015
Author
Contributor
I'm confused, I think the semantics you are describing is exactly what I proposed. implicit-deps controls access std and it's dependencies---whatever those may be.
I went with -deps and not -std because of unstable Rust. But if we want to gear the name around stable Rust, sure.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jun 1, 2015
Member
Oh yes we're definitely thinking of the same thing, I was just wondering if the name implicit-std was better. For example the name implicit-deps seems kinda scary that any crate could be an implicit dependency, when in fact there is only one crate in the stable world that can be an implicit dependency -- libstd.
I agree there are more crates that can be implicitly depended upon, but none of them are stable today, so we may not need to consider them. I think I was just somewhat startled at how this may imply that implicit dependencies are allowed from anywhere (when it's in fact just the sysroot)
This comment has been minimized.
This comment has been minimized.
Ericson2314
Jun 15, 2015
Author
Contributor
I see. Somebody beginning Rust, or beginning just even unstablized Rust, has no idea what dependencies would normally be implicit. One the other hand implicit-std sounds like one is just getting access to std, since Cargo normally doesn't allow one to extern transitive dependencies lest a direct dependency changes its dependencies. A name like implicit-std-and-its-deps would be the most clear, but my is it wordy.
Another option is to change it so that implicit-std = true only gives access to std itself, and dependencies on the crates behind the facade must always be explicit. This would also help on the off-chance that we want to version unstable std independently from its backing crates. Unfortunately, it also breaks backwards compatibility with existing packages, but only those using unstable Rust.
This comment has been minimized.
This comment has been minimized.
eternaleye
Jun 15, 2015
Another, more concise phrasing might be implicit-stdlibs = true - the 's' punches well above its weight class.
This comment has been minimized.
This comment has been minimized.
Ericson2314
Jun 15, 2015
Author
Contributor
Not bad! I tried to think of a short name to capture all that, but came up short.
alexcrichton
reviewed
May 30, 2015
| ## Future Compatibility | ||
|
|
||
| In the future, rather than giving up if libraries are missing Cargo could attempt to download them | ||
| from some build cache. In the farther future, the stdlib libraries may be Cargoized, and Cargo able |
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 30, 2015
Member
Ah one point I forgot about previously, which is probably pretty relevant to this, is: the compiler can only link against libraries it previously built. This means that we would need a build cache per-revision of the compiler, which unfortunately makes this much more infeasible :(
This comment has been minimized.
This comment has been minimized.
Ericson2314
May 30, 2015
Author
Contributor
Hmm, we over at NixOS maintain a build cache for Haskell and it works. If you only focus the slower release channels, and prioritize popular packages, it can still be useful.
The idea of a stable ABI scares me, but if/when it happens, that problem goes away too.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jun 1, 2015
Member
Ah yeah we could definitely pre-cache builds of std for each official release of the compiler, for example, but it may want to be mentioned here as a potential downside. For example all custom builds of the compiler (e.g. nightlies) will not have access to pre-built archives.
This comment has been minimized.
This comment has been minimized.
Ericson2314
Jun 15, 2015
Author
Contributor
I still don't see the downside. Today, the compiler and library are built together, so we are already building and storing std for each prebuilt compiler. Whether or not std is downloaded with a prebuilt compiler or separately from a crates.io build cache, the build time and storage requirements are the same.
This comment has been minimized.
This comment has been minimized.
llogiq
Jun 15, 2015
Contributor
Downloading std separately will stop those who have installed rust to look at it during their commute (case in point: me, a few weeks ago). Not everyone has a fast internet connection everywhere, so there may be other hidden downsides.
This comment has been minimized.
This comment has been minimized.
Ericson2314
Jun 15, 2015
Author
Contributor
Mmm, once std is downloaded once, it doesn't in principle need to be downloaded again. Assuming a local build cache shared between projects is implemented at this point in the future, the compiler's install script could set it up and pre-populate it with std. That way nobody forgets std on their commute :).
alexcrichton
self-assigned this
Jun 1, 2015
petrochenkov
removed
the
T-dev-tools
label
Jan 30, 2018
This comment has been minimized.
This comment has been minimized.
|
rust-lang/cargo#4959 is a partial (and more minimal) alternative to this RFC. I propose we close this RFC in favour of that proposal. @rfcbot fcp close |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 1, 2018
•
|
Team member @nrc has proposed to close this. The next step is review by the rest of the tagged teams:
No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
added
the
proposed-final-comment-period
label
Feb 1, 2018
This comment has been minimized.
This comment has been minimized.
|
Go ahead and make me a noop vote |
This comment has been minimized.
This comment has been minimized.
|
I think we should keep this RFC open simply as a tradition |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot reviewed |
2 similar comments
This comment has been minimized.
This comment has been minimized.
|
@rfcbot reviewed |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot reviewed |
This comment has been minimized.
This comment has been minimized.
|
I do agree we should have a more minimal first step, but I don't think it should be (just) rust-lang/cargo#4959. The most important part of this is the interface for specifying stdlilb deps, so we can cleanly bypass all the crufty sysroot and boostrapping implementation details needed today. Much of the discussion thread of this PR also mistakenly focused on uninteresting implementation minutia. I'm happy to rewrite this or open a new one to that end. |
This comment has been minimized.
This comment has been minimized.
|
+1 to the idea that sysroot should die and that stdlib crates should not be much different from crates from crates.io. We still, after several years, would like |
This comment has been minimized.
This comment has been minimized.
|
@matklad Yeah that's a great point. When I started preaching death to the sysroot, it was a pretty academic question of avoiding the complexity of needless distinctions. But now with all the new tooling work, be it incremental compilation, IDE support, etc, there's real tangible benefits visible to just about every regular user (far beyond the niche of embedded and OS devs). |
This comment has been minimized.
This comment has been minimized.
|
@Ericson2314 I'd like to not lose track of the other issues. I don't think a new RFC is the best way to do that though. Perhaps opening an issue or two on the Cargo repo would be better? Where there are UI things, I'd be keen to experiment on top of the sysroot stuff as a plugin if possible, otherwise as an unstable feature, then RFC later. For other things it would be good to identify small chunks of work which could be isolated and have their own RFCs or implementation. |
This comment has been minimized.
This comment has been minimized.
This was referenced Feb 2, 2018
This comment has been minimized.
This comment has been minimized.
|
@nrc OK made 2 (and found 1). Those basically correspond to what I implemented in my Cargo PR way back when, and can all be handled "decently independently". |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 8, 2018
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Mar 8, 2018
This was referenced Mar 16, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 18, 2018
|
The final comment period is now complete. |
This comment has been minimized.
This comment has been minimized.
|
Closing the RFC per complete FCP #1133 (comment) with a disposition to close. |
Ericson2314 commentedMay 26, 2015
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 where libstd can be
Cargoized.
I've been busy with school until very recently, so apologies in advance if it turns out I am not taking into account some recent change.
Rendered