-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[WIP] per profile sysroot via Cargo.toml #2436
Conversation
This patch lets you use the 'profile.$profile.sysroot' key in Cargo.toml to pass `--sysroot $path` to `rustc` during the compilation of the current crate and its dependencies. Main use cases are kernel development and bare metal programming (e.g. microcontrollers) where the application depends on a minimal set of "core" crates like `core`, `alloc`, `collections`, etc. These dependencies need to be cross compiled for the target platform/architecture and a "sysroot" (*) provides, IMO ,the cleanest way to make these core dependencies available to the many crates that conform the application. (*) A sysroot is basically a directory that holds the already (cross) compiled "standard" crates (i.e. `core`, `std`, etc) that are linked to your Rust programs when you call `rustc`. The important bit is that you don't explicitly spell out these dependencies in e.g. a Cargo.toml; they are implicitly available. The fastest way to familiarize with sysroots is to explore the default sysroot with something like `tree $(rustc --print sysroot)`. cc rust-lang#2312
(rust_highfive has picked a reviewer for you, use r? to override) |
IMO, the feature implemented here is way more ergonomic, mainly because it's a per profile setting.
On the other hand, the RUSTFLAGS feature doesn't provide a per profile setting so you would have to
Which is less ergonomic. |
Thanks for the PR @japaric! In terms of links this also interacts with rust-lang/rfcs#1133 in the sense that Cargo may one day grow some "smarter resolution" for cross-compiled sysroots or something like that. That RFC, however, is still quite early and probably needs some work, so I wouldn't necessarily want to block this on that. In terms of whether this belongs in
The case of sysroot here is interesting because there's a few concerns with it:
I guess to be honest I'm not sure if we want to land this just yet or not. I definitely agree that this is more ergonomic than |
Now that RUSTFLAGS is a thing, I created a cargo wrapper that can be used just like cargo: Thanks for sharing your thoughts @alexcrichton! |
This patch lets you use the 'profile.$profile.sysroot' key in Cargo.toml to pass
--sysroot $path
to
rustc
during the compilation of the current crate and its dependencies.Main use cases are kernel development and bare metal programming (e.g. microcontrollers) where the
application depends on a minimal set of "core" crates like
core
,alloc
,collections
, etc.These dependencies need to be cross compiled for the target platform/architecture and a "sysroot"
(*) provides, IMO ,the cleanest way to make these core dependencies available to the many crates
that conform the application.
(*) A sysroot is basically a directory that holds the already (cross) compiled "standard" crates
(i.e.
core
,std
, etc) that are linked to your Rust programs when you callrustc
. The importantbit is that you don't explicitly spell out these dependencies in e.g. a Cargo.toml; they are
implicitly available. The fastest way to familiarize with sysroots is to explore the default sysroot
with something like
tree $(rustc --print sysroot)
.cc #2312
This is minimal PoC to start the discussion. There are a few unresolved questions.
--sysroot
torustc
. Should we just use thatfeature and not implement this one?
the call site or relative the root of the cargo project? Example, if the user sets 'sysroot =
foo' in their Cargo project and then calls
cargo build --manifest-path some/path/Cargo.toml
should
$(pwd)/foo
orsome/path/foo
be used as the sysroot?cc @alexcrichton @Zoxc