rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
133 stars 8 forks source link

Documentation on how to use the new cargo-std support in place of cargo xbuild #41

Closed alex closed 4 years ago

alex commented 4 years ago

Now that the pieces are starting to come together, having documentation so one can play with migrating to this would be a huge boon.

phil-opp commented 4 years ago

It seems like cargo build -Z build-std=core,alloc is roughly the equivalent to cargo xbuild. I just tried it and it basically works, I just needed to add rlibc as dependency (including extern crate) because the mem feature of compiler_builtins is not activated.

I'm currently looking for a way to automatically pass the -Z build-std argument through a configuration file, similar to build.rustflags in .cargo/config. Does anyone know if this is possible?

alexcrichton commented 4 years ago

In addition to what @phil-opp wrote above there's also this comment FWIW.

Does anyone know if this is possible?

This is sort of tangentially covered by https://github.com/rust-lang/wg-cargo-std-aware/issues/5 to "only need" -Z build-std instead of a list of crates, but then the actual final UX of enabling the build-std logic hasn't been discussed too much, so I've opened https://github.com/rust-lang/wg-cargo-std-aware/issues/43 to track that.

Basically in short, it's not possible yet, you've got to pass -Z build-std to everything. We know it's not great, but the ball's now rolling!

phil-opp commented 4 years ago

@alexcrichton Thanks! Something like the build.std configuration key you proposed sounds like a good solution.

One workaround I found for now is to use cargo aliases, e.g. xbuild for build -Z build-std, which is slightly more ergonomic than typing out the full -Z command.

alexcrichton commented 4 years ago

Pointed out on https://github.com/rust-lang/wg-cargo-std-aware/issues/43, we forgot to add documentation to https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for this feature! Adding that should be sufficient for closing out this issue.

alex commented 4 years ago

Based on https://github.com/fishinabarrel/linux-kernel-module-rust/pull/180, this seems to be working great based on the provided instruction so I'm considering this working!