-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Allow targets to override default codegen backend #116793
Conversation
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
cc @davidtwco |
This comment was marked as resolved.
This comment was marked as resolved.
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.
@davidtwco do you have any comment?
r=me with one nit unless @davidtwco says otherwise
let sopts = config::Options::default(); | ||
let sysroot = sopts.maybe_sysroot.clone().unwrap_or_else(|| { | ||
filesearch::get_or_default_sysroot().expect("Failed finding sysroot") | ||
}); | ||
let target = config::build_target_config(handler, &sopts, None, &sysroot); |
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 snippet appears several times. Any way to refactor it into the normal code path?
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.
Idk, the crate structure and everything is very confusing, so I'm not sure how to refactor this...
I've moved the maybe_sysroot->sysroot into a function, but I don't think I can do much more
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.
LGTM, with @cjgillot's comments addressed to their satisfaction :)
a699d87
to
eedd680
Compare
These commits modify compiler targets. |
eedd680
to
a03d19e
Compare
37fc0ba
to
5441523
Compare
// target_override is documented to be called before init(), so this is okay | ||
let target_override = backend.target_override(&config.opts); | ||
|
||
let target = config::build_target_config( | ||
&early_dcx, | ||
&config.opts, | ||
target_override, | ||
&sysroot, | ||
); |
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 part is duplicated on both arms. Any way to deduplicate?
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.
6d115f5. can't move target_override
because of the assertion.
@bors r+ |
…end, r=cjgillot Allow targets to override default codegen backend Implements rust-lang/compiler-team#670.
…kingjubilee Rollup of 13 pull requests Successful merges: - rust-lang#113525 (Dynamically size sigaltstk in std) - rust-lang#114009 (compiler: allow transmute of ZST arrays with generics) - rust-lang#116793 (Allow targets to override default codegen backend) - rust-lang#118623 (Improve std::fs::read_to_string example) - rust-lang#120504 (Vec::try_with_capacity) - rust-lang#121089 (Remove `feed_local_def_id`) - rust-lang#121280 (Implement MaybeUninit::fill{,_with,_from}) - rust-lang#122087 (Add missing background color for top-level rust documentation page and increase contrast by setting text color to black) - rust-lang#122104 (Rust is a proper name: rust → Rust) - rust-lang#122110 (Make `x t miri` respect `MIRI_TEMP`) - rust-lang#122114 (Make not finding core a fatal error) - rust-lang#122115 (Cancel parsing ever made during recovery) - rust-lang#122126 (Fix `tidy --bless` on ̶X̶e̶n̶i̶x̶ Windows) r? `@ghost` `@rustbot` modify labels: rollup
…kingjubilee Rollup of 15 pull requests Successful merges: - rust-lang#116791 (Allow codegen backends to opt-out of parallel codegen) - rust-lang#116793 (Allow targets to override default codegen backend) - rust-lang#117458 (LLVM Bitcode Linker: A self contained linker for nvptx and other targets) - rust-lang#119385 (Fix type resolution of associated const equality bounds (take 2)) - rust-lang#121438 (std support for wasm32 panic=unwind) - rust-lang#121893 (Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking) - rust-lang#122080 (Clarity improvements to `DropTree`) - rust-lang#122152 (Improve diagnostics for parenthesized type arguments) - rust-lang#122166 (Remove the unused `field_remapping` field from `TypeLowering`) - rust-lang#122249 (interpret: do not call machine read hooks during validation) - rust-lang#122299 (Store backtrace for `must_produce_diag`) - rust-lang#122318 (Revision-related tweaks for next-solver tests) - rust-lang#122320 (Use ptradd for vtable indexing) - rust-lang#122328 (unix_sigpipe: Replace `inherit` with `sig_dfl` in syntax tests) - rust-lang#122330 (bootstrap readme: fix, improve, update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#116793 - WaffleLapkin:target_rules_the_backend, r=cjgillot Allow targets to override default codegen backend Implements rust-lang/compiler-team#670.
@@ -2909,7 +2901,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M | |||
describe_lints, | |||
output_types, | |||
search_paths, | |||
maybe_sysroot: sysroot_opt, | |||
maybe_sysroot: Some(sysroot), |
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 made it impossible for the config
driver callback to determine whether the --sysroot
flag was passed or not, which is a problem for drivers that want to overwrite the default sysroot but honor explicit --sysroot
. I'm trying to fix this in #122993 but I don't really know what I am doing...
let codegen_backend = if let Some(make_codegen_backend) = config.make_codegen_backend { | ||
make_codegen_backend(&config.opts) | ||
} else { | ||
util::get_codegen_backend( | ||
&early_dcx, | ||
&config.opts.maybe_sysroot, | ||
config.opts.unstable_opts.codegen_backend.as_deref(), | ||
) | ||
let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone()); | ||
|
||
let (codegen_backend, target_override) = match config.make_codegen_backend { | ||
None => { | ||
// Build a target without override, so that it can override the backend if needed | ||
let target = | ||
config::build_target_config(&early_dcx, &config.opts, None, &sysroot); | ||
|
||
let backend = util::get_codegen_backend( | ||
&early_dcx, | ||
&sysroot, | ||
config.opts.unstable_opts.codegen_backend.as_deref(), | ||
&target, | ||
); | ||
|
||
// target_override is documented to be called before init(), so this is okay | ||
let target_override = backend.target_override(&config.opts); |
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 doesn't really do the same thing as before, or rather it assumes custom codegen backends require config.make_codegen_backend
, whereas config.opts.unstable_opts.codegen_backend
is also possible.
The new version calls config::build_target_config
once, without the override, which means the backend cannot add new targets, only at most slightly tweak existing ones.
To be clear, none of this really matters anymore due to:
(but I ran into it while trying to update Rust-GPU to nightly-2024-03-21
, just before #122810, just so I can get everything else out of the way before tackling the target_override
removal itself)
Implements rust-lang/compiler-team#670.