-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add a profile option to select the codegen backend #9118
Conversation
r? @ehuss (rust-highfive has picked a reviewer for you, use r? to override) |
cc @khyperia This may be useful for rust-gpu. |
I think it would be nice to have a |
12d44e3
to
c5b64cd
Compare
☔ The latest upstream changes (presumably #9112) made this pull request unmergeable. Please resolve the merge conflicts. |
799ebe8
to
2c9b26e
Compare
We discussed this during the Cargo meeting today, and we were somewhat wary to land this. We have tried to keep hardcoded paths out of manifests historically, and we would ideally prefer to avoid continuing to do so. We were also not certain about landing a feature whose future in rustc itself is uncertain, for example we're not certain how the long-term design of this feature will play out in rustc and whether it'll continue to map well to a profile option. For these reasons we're hesitant to land this PR at this time. One option we discussed though which could be a possibility would be to add a |
Ah another concern that we had about this is that profiles are target-independent, but what you'd probably want is a target-specific profile for something like the codegen backend. For example the current cranelift backend doesn't support the same array of targets LLVM supports, so configuring and using this can be difficult for projects that do cross compilation. This is something we'd like to solve in the future (e.g. target-specific profile options), but is too large of a feature to implement inline here. |
This is one of the reasons I would also like to be able to specify it in |
bd9959c
to
0de6c28
Compare
Looks like that is already supported: https://doc.rust-lang.org/cargo/reference/config.html#profilenamepackagename |
src/doc/src/reference/unstable.md
Outdated
serde = "1.0.117" | ||
|
||
[profile.dev.package.foo] | ||
codegen-backend = "/path/to/librustc_codegen_cranelift.so" |
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.
This could become
codegen-backend = "/path/to/librustc_codegen_cranelift.so" | |
codegen-backend = "cranelift" |
once rust-lang/rust#81746 lands.
☔ The latest upstream changes (presumably #9184) made this pull request unmergeable. Please resolve the merge conflicts. |
I think @alexcrichton's response still stands: we don't want to use full paths to codegen backends. It might make sense to have just a name of a codegen backend, pass that to rustc, and then rustc can find and load the codegen backend in its normal way. Or, it's possible that this should be an aspect of the target. But either way, the PR as submitted isn't something we want to merge. I think the next step on this is a proposal, not a PR. That proposal should be based on codegen backend names, not full paths. And ideally, that proposal should start in rustc, and cargo should just expose that rustc option; cargo shouldn't be in the business of finding rustc's backends for it, rustc should know how to load |
This PR already implements passing the name as option. It literally passes the value through to rustc as |
@bjorn3 Ah, I see! If you could change the Cargo support to require that the option be an identifier, rather than a path, then I'd be happy to see this go in in that form. |
Using a path could be useful for testing purposes. In any case I don't think using a path will ever be stabilized on the rustc side as it isn't possible to compile a codegen backend for stable anyway outside of the rust build system. If you want I can make it a warning or forbid it in cargo though. |
For testing purpose, I think people can use
Please make it a hard error to pass anything other than an identifier, and then I'd be happy to fcp-merge this. |
This makes it possible to compile only specific crates with a certain codegen backend.
That doesn't allow changing the codegen backend just for certain crates.
Where should I add this code? |
0de6c28
to
88da239
Compare
@bjorn3 wrote:
Acknowledged, but I still don't think we should have a Cargo config option that takes an exact path to a codegen backend. (Personally, I'd love to have a Cargo config option for specifying per-crate RUSTFLAGS.)
In |
Done |
I posted one fix for the validation logic. Apart from that, there's a failing test on iOS; I think the profile test you updated needs to keep the |
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
I think so too. I think it would be nice to enable the feature of serde_json that sorts hashmaps to keep them deterministic. That would significantly reduce the test output diff. |
src/cargo/util/toml/mod.rs
Outdated
|
||
if let Some(codegen_backend) = &self.codegen_backend { | ||
features.require(Feature::codegen_backend())?; | ||
if codegen_backend.contains(|c| !c.is_ascii_alphanumeric() && c != '_') { |
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.
if codegen_backend.contains(|c| !c.is_ascii_alphanumeric() && c != '_') { | |
if codegen_backend.contains(|c: char| !c.is_ascii_alphanumeric() && c != '_') { |
Sorry, that CI failure was my fault with the previous code suggestion.
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.
I actually only noticed the bail!()
change. Rustc uses the existence of .
to distinguish between builtin and external backends.
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.
I didn't know that. We can always expand what this allows if rustc adds a built-in backend that needs a broader set of potential inputs.
CI passed. |
@bors r+ |
📌 Commit e96309a has been approved by |
☀️ Test successful - checks-actions |
Update cargo 9 commits in cc17afbb0067b1f57d8882640f63b2168d5b7624..b51439fd8b505d4800a257acfecf3c69f81e35cf 2021-08-02 20:28:08 +0000 to 2021-08-09 18:40:05 +0000 - Deduplicate entries in cargo --list (rust-lang/cargo#9773) - Include aliases with other commands (rust-lang/cargo#9764) - Add a profile option to select the codegen backend (rust-lang/cargo#9118) - remove useless conversions (rust-lang/cargo#9617) - collapse nested if blocks (rust-lang/cargo#9613) - Refactor fake_file() away from cargo_command tests (rust-lang/cargo#9767) - Update cargo-platform to 0.1.2 (rust-lang/cargo#9762) - Bump to the latest jobserver dependency (rust-lang/cargo#9760) - Fix semver check for rust 1.54.0 (rust-lang/cargo#9763)
Update cargo 9 commits in cc17afbb0067b1f57d8882640f63b2168d5b7624..b51439fd8b505d4800a257acfecf3c69f81e35cf 2021-08-02 20:28:08 +0000 to 2021-08-09 18:40:05 +0000 - Deduplicate entries in cargo --list (rust-lang/cargo#9773) - Include aliases with other commands (rust-lang/cargo#9764) - Add a profile option to select the codegen backend (rust-lang/cargo#9118) - remove useless conversions (rust-lang/cargo#9617) - collapse nested if blocks (rust-lang/cargo#9613) - Refactor fake_file() away from cargo_command tests (rust-lang/cargo#9767) - Update cargo-platform to 0.1.2 (rust-lang/cargo#9762) - Bump to the latest jobserver dependency (rust-lang/cargo#9760) - Fix semver check for rust 1.54.0 (rust-lang/cargo#9763)
Update cargo 9 commits in cc17afbb0067b1f57d8882640f63b2168d5b7624..b51439fd8b505d4800a257acfecf3c69f81e35cf 2021-08-02 20:28:08 +0000 to 2021-08-09 18:40:05 +0000 - Deduplicate entries in cargo --list (rust-lang/cargo#9773) - Include aliases with other commands (rust-lang/cargo#9764) - Add a profile option to select the codegen backend (rust-lang/cargo#9118) - remove useless conversions (rust-lang/cargo#9617) - collapse nested if blocks (rust-lang/cargo#9613) - Refactor fake_file() away from cargo_command tests (rust-lang/cargo#9767) - Update cargo-platform to 0.1.2 (rust-lang/cargo#9762) - Bump to the latest jobserver dependency (rust-lang/cargo#9760) - Fix semver check for rust 1.54.0 (rust-lang/cargo#9763)
This makes it possible to compile only specific crates with a certain codegen backend.
I have tested this by compiling Bevy with cg_llvm, but one of the examples using cg_clif.
By the way I noticed that many unstable profile options are not checked when using profile overrides.