1
Fork 0

Let backends define custom targets

Add a target_override hook that takes priority over builtin targets.
This commit is contained in:
khyperia 2020-09-17 12:01:12 +02:00
parent 95386b656e
commit c946c40d9d
6 changed files with 27 additions and 11 deletions

View file

@ -818,10 +818,11 @@ pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateCo
user_cfg
}
pub fn build_target_config(opts: &Options, error_format: ErrorOutputType) -> Config {
let target = Target::search(&opts.target_triple).unwrap_or_else(|e| {
pub fn build_target_config(opts: &Options, target_override: Option<Target>) -> Config {
let target_result = target_override.map_or_else(|| Target::search(&opts.target_triple), Ok);
let target = target_result.unwrap_or_else(|e| {
early_error(
error_format,
opts.error_format,
&format!(
"Error loading target specification: {}. \
Use `--print target-list` for a list of built-in targets",
@ -835,7 +836,7 @@ pub fn build_target_config(opts: &Options, error_format: ErrorOutputType) -> Con
"32" => 32,
"64" => 64,
w => early_error(
error_format,
opts.error_format,
&format!(
"target specification was invalid: \
unrecognized target-pointer-width {}",

View file

@ -1234,6 +1234,7 @@ pub fn build_session(
diagnostics_output: DiagnosticOutput,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
target_override: Option<Target>,
) -> Session {
// FIXME: This is not general enough to make the warning lint completely override
// normal diagnostic warnings, since the warning lint can also be denied and changed
@ -1253,7 +1254,7 @@ pub fn build_session(
DiagnosticOutput::Raw(write) => Some(write),
};
let target_cfg = config::build_target_config(&sopts, sopts.error_format);
let target_cfg = config::build_target_config(&sopts, target_override);
let host_triple = TargetTriple::from_triple(config::host_triple());
let host = Target::search(&host_triple).unwrap_or_else(|e| {
early_error(sopts.error_format, &format!("Error loading host specification: {}", e))