1
Fork 0

Respect --target in get_backend_from_raw_matches

This commit is contained in:
bjorn3 2025-01-20 15:47:26 +00:00
parent 3b6e3642ce
commit 056a9cebe9
4 changed files with 15 additions and 9 deletions

View file

@ -53,7 +53,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal}; use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
use rustc_session::config::{ use rustc_session::config::{
CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, UnstableOptions, CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, UnstableOptions,
Z_OPTIONS, nightly_options, Z_OPTIONS, nightly_options, parse_target_triple,
}; };
use rustc_session::getopts::{self, Matches}; use rustc_session::getopts::{self, Matches};
use rustc_session::lint::{Lint, LintId}; use rustc_session::lint::{Lint, LintId};
@ -1129,17 +1129,18 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
/// Get the codegen backend based on the raw [`Matches`]. /// Get the codegen backend based on the raw [`Matches`].
/// ///
/// `rustc -vV` and `rustc -Cpasses=list` need to get the codegen backend before we have parsed all /// `rustc -vV` and `rustc -Cpasses=list` need to get the codegen backend before we have parsed all
/// arguments and created a [`Session`]. This function reads `-Zcodegen-backend` and `--sysroot` /// arguments and created a [`Session`]. This function reads `-Zcodegen-backend`, `--target` and
/// without validating any other arguments and loads the codegen backend based on these arguments. /// `--sysroot` without validating any other arguments and loads the codegen backend based on these
/// arguments.
fn get_backend_from_raw_matches( fn get_backend_from_raw_matches(
early_dcx: &EarlyDiagCtxt, early_dcx: &EarlyDiagCtxt,
matches: &Matches, matches: &Matches,
) -> Box<dyn CodegenBackend> { ) -> Box<dyn CodegenBackend> {
let debug_flags = matches.opt_strs("Z"); let debug_flags = matches.opt_strs("Z");
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend=")); let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
let opts = config::Options::default(); let target = parse_target_triple(early_dcx, matches);
let sysroot = filesearch::materialize_sysroot(matches.opt_str("sysroot").map(PathBuf::from)); let sysroot = filesearch::materialize_sysroot(matches.opt_str("sysroot").map(PathBuf::from));
let target = config::build_target_config(early_dcx, &opts, &sysroot); let target = config::build_target_config(early_dcx, &target, &sysroot);
get_codegen_backend(early_dcx, &sysroot, backend_name, &target) get_codegen_backend(early_dcx, &sysroot, backend_name, &target)
} }

View file

@ -383,7 +383,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
crate::callbacks::setup_callbacks(); crate::callbacks::setup_callbacks();
let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone()); let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone());
let target = config::build_target_config(&early_dcx, &config.opts, &sysroot); let target = config::build_target_config(&early_dcx, &config.opts.target_triple, &sysroot);
let file_loader = config.file_loader.unwrap_or_else(|| Box::new(RealFileLoader)); let file_loader = config.file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
let path_mapping = config.opts.file_path_mapping(); let path_mapping = config.opts.file_path_mapping();
let hash_kind = config.opts.unstable_opts.src_hash_algorithm(&target); let hash_kind = config.opts.unstable_opts.src_hash_algorithm(&target);

View file

@ -41,7 +41,8 @@ where
let matches = optgroups().parse(args).unwrap(); let matches = optgroups().parse(args).unwrap();
let sessopts = build_session_options(&mut early_dcx, &matches); let sessopts = build_session_options(&mut early_dcx, &matches);
let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone()); let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone());
let target = rustc_session::config::build_target_config(&early_dcx, &sessopts, &sysroot); let target =
rustc_session::config::build_target_config(&early_dcx, &sessopts.target_triple, &sysroot);
let hash_kind = sessopts.unstable_opts.src_hash_algorithm(&target); let hash_kind = sessopts.unstable_opts.src_hash_algorithm(&target);
let checksum_hash_kind = sessopts.unstable_opts.checksum_hash_algorithm(); let checksum_hash_kind = sessopts.unstable_opts.checksum_hash_algorithm();
let sm_inputs = Some(SourceMapInputs { let sm_inputs = Some(SourceMapInputs {

View file

@ -1353,8 +1353,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg {
user_cfg user_cfg
} }
pub fn build_target_config(early_dcx: &EarlyDiagCtxt, opts: &Options, sysroot: &Path) -> Target { pub fn build_target_config(
match Target::search(&opts.target_triple, sysroot) { early_dcx: &EarlyDiagCtxt,
target: &TargetTuple,
sysroot: &Path,
) -> Target {
match Target::search(target, sysroot) {
Ok((target, warnings)) => { Ok((target, warnings)) => {
for warning in warnings.warning_messages() { for warning in warnings.warning_messages() {
early_dcx.early_warn(warning) early_dcx.early_warn(warning)