rust/src/libstd
Alex Crichton 4c21a3bc2a std: Depend directly on crates.io crates
Ever since we added a Cargo-based build system for the compiler the
standard library has always been a little special, it's never been able
to depend on crates.io crates for runtime dependencies. This has been a
result of various limitations, namely that Cargo doesn't understand that
crates from crates.io depend on libcore, so Cargo tries to build crates
before libcore is finished.

I had an idea this afternoon, however, which lifts the strategy
from #52919 to directly depend on crates.io crates from the standard
library. After all is said and done this removes a whopping three
submodules that we need to manage!

The basic idea here is that for any crate `std` depends on it adds an
*optional* dependency on an empty crate on crates.io, in this case named
`rustc-std-workspace-core`. This crate is overridden via `[patch]` in
this repository to point to a local crate we write, and *that* has a
`path` dependency on libcore.

Note that all `no_std` crates also depend on `compiler_builtins`, but if
we're not using submodules we can publish `compiler_builtins` to
crates.io and all crates can depend on it anyway! The basic strategy
then looks like:

* The standard library (or some transitive dep) decides to depend on a
  crate `foo`.
* The standard library adds

  ```toml
  [dependencies]
  foo = { version = "0.1", features = ['rustc-dep-of-std'] }
  ```
* The crate `foo` has an optional dependency on `rustc-std-workspace-core`
* The crate `foo` has an optional dependency on `compiler_builtins`
* The crate `foo` has a feature `rustc-dep-of-std` which activates these
  crates and any other necessary infrastructure in the crate.

A sample commit for `dlmalloc` [turns out to be quite simple][commit].
After that all `no_std` crates should largely build "as is" and still be
publishable on crates.io! Notably they should be able to continue to use
stable Rust if necessary, since the `rename-dependency` feature of Cargo
is soon stabilizing.

As a proof of concept, this commit removes the `dlmalloc`,
`libcompiler_builtins`, and `libc` submodules from this repository. Long
thorns in our side these are now gone for good and we can directly
depend on crates.io! It's hoped that in the long term we can bring in
other crates as necessary, but for now this is largely intended to
simply make it easier to manage these crates and remove submodules.

This should be a transparent non-breaking change for all users, but one
possible stickler is that this almost for sure breaks out-of-tree
`std`-building tools like `xargo` and `cargo-xbuild`. I think it should
be relatively easy to get them working, however, as all that's needed is
an entry in the `[patch]` section used to build the standard library.
Hopefully we can work with these tools to solve this problem!

[commit]: 28ee12db81
2018-12-11 21:08:22 -08:00
..
collections Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
ffi Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
io Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
net Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
os Make std::os::unix/linux::fs::MetadataExt::a/m/ctime* documentation clearer 2018-11-22 02:36:11 +01:00
prelude Reformat std prelude source to show it is the sum of core and alloc preludes 2018-07-07 23:16:27 +02:00
sync Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
sys std: Depend directly on crates.io crates 2018-12-11 21:08:22 -08:00
sys_common Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
tests Breaking change upgrades 2018-09-04 13:22:08 -06:00
thread Auto merge of #56157 - RalfJung:park, r=nagisa 2018-12-10 12:19:47 +00:00
alloc.rs Rollup merge of #55901 - euclio:speling, r=petrochenkov 2018-11-15 11:04:42 +01:00
ascii.rs Remove unstable and deprecated APIs 2018-07-30 18:18:23 +02:00
build.rs std: Depend directly on crates.io crates 2018-12-11 21:08:22 -08:00
Cargo.toml std: Depend directly on crates.io crates 2018-12-11 21:08:22 -08:00
env.rs cleanup: remove static lifetimes from consts in libstd 2018-12-04 10:21:42 +01:00
error.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
f32.rs Fix doc for new copysign functions 2018-10-24 15:19:23 -07:00
f64.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
fs.rs std: Depend directly on crates.io crates 2018-12-11 21:08:22 -08:00
future.rs fix futures aliasing mutable and shared ref 2018-11-28 19:30:11 +01:00
keyword_docs.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
lib.rs Update Cargo submodule and its dependencies 2018-12-10 13:45:22 -08:00
macros.rs stabilize std::dbg!(...) 2018-12-01 02:54:09 +01:00
memchr.rs Fix typos found by codespell. 2018-08-19 17:41:28 +02:00
num.rs Stabilize num::NonZeroU* 2018-05-16 19:11:31 +02:00
panic.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
panicking.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
path.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
primitive_docs.rs std: Depend directly on crates.io crates 2018-12-11 21:08:22 -08:00
process.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
rt.rs Deny bare trait objects in src/libstd. 2018-07-10 20:35:36 +02:00
time.rs Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00