Skip to content

Commit 056a9ce

Browse files
committed
Respect --target in get_backend_from_raw_matches
1 parent 3b6e364 commit 056a9ce

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

compiler/rustc_driver_impl/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use rustc_middle::ty::TyCtxt;
5353
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
5454
use rustc_session::config::{
5555
CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, UnstableOptions,
56-
Z_OPTIONS, nightly_options,
56+
Z_OPTIONS, nightly_options, parse_target_triple,
5757
};
5858
use rustc_session::getopts::{self, Matches};
5959
use rustc_session::lint::{Lint, LintId};
@@ -1129,17 +1129,18 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
11291129
/// Get the codegen backend based on the raw [`Matches`].
11301130
///
11311131
/// `rustc -vV` and `rustc -Cpasses=list` need to get the codegen backend before we have parsed all
1132-
/// arguments and created a [`Session`]. This function reads `-Zcodegen-backend` and `--sysroot`
1133-
/// without validating any other arguments and loads the codegen backend based on these arguments.
1132+
/// arguments and created a [`Session`]. This function reads `-Zcodegen-backend`, `--target` and
1133+
/// `--sysroot` without validating any other arguments and loads the codegen backend based on these
1134+
/// arguments.
11341135
fn get_backend_from_raw_matches(
11351136
early_dcx: &EarlyDiagCtxt,
11361137
matches: &Matches,
11371138
) -> Box<dyn CodegenBackend> {
11381139
let debug_flags = matches.opt_strs("Z");
11391140
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
1140-
let opts = config::Options::default();
1141+
let target = parse_target_triple(early_dcx, matches);
11411142
let sysroot = filesearch::materialize_sysroot(matches.opt_str("sysroot").map(PathBuf::from));
1142-
let target = config::build_target_config(early_dcx, &opts, &sysroot);
1143+
let target = config::build_target_config(early_dcx, &target, &sysroot);
11431144

11441145
get_codegen_backend(early_dcx, &sysroot, backend_name, &target)
11451146
}

compiler/rustc_interface/src/interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
383383
crate::callbacks::setup_callbacks();
384384

385385
let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone());
386-
let target = config::build_target_config(&early_dcx, &config.opts, &sysroot);
386+
let target = config::build_target_config(&early_dcx, &config.opts.target_triple, &sysroot);
387387
let file_loader = config.file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
388388
let path_mapping = config.opts.file_path_mapping();
389389
let hash_kind = config.opts.unstable_opts.src_hash_algorithm(&target);

compiler/rustc_interface/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ where
4141
let matches = optgroups().parse(args).unwrap();
4242
let sessopts = build_session_options(&mut early_dcx, &matches);
4343
let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone());
44-
let target = rustc_session::config::build_target_config(&early_dcx, &sessopts, &sysroot);
44+
let target =
45+
rustc_session::config::build_target_config(&early_dcx, &sessopts.target_triple, &sysroot);
4546
let hash_kind = sessopts.unstable_opts.src_hash_algorithm(&target);
4647
let checksum_hash_kind = sessopts.unstable_opts.checksum_hash_algorithm();
4748
let sm_inputs = Some(SourceMapInputs {

compiler/rustc_session/src/config.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg {
13531353
user_cfg
13541354
}
13551355

1356-
pub fn build_target_config(early_dcx: &EarlyDiagCtxt, opts: &Options, sysroot: &Path) -> Target {
1357-
match Target::search(&opts.target_triple, sysroot) {
1356+
pub fn build_target_config(
1357+
early_dcx: &EarlyDiagCtxt,
1358+
target: &TargetTuple,
1359+
sysroot: &Path,
1360+
) -> Target {
1361+
match Target::search(target, sysroot) {
13581362
Ok((target, warnings)) => {
13591363
for warning in warnings.warning_messages() {
13601364
early_dcx.early_warn(warning)

0 commit comments

Comments
 (0)