1
Fork 0

Auto merge of #135030 - Flakebi:require-cpu, r=workingjubilee

Target option to require explicit cpu

Some targets have many different CPUs and no generic CPU that can be used as a default. For these targets, the user needs to explicitly specify a CPU through `-C target-cpu=`.

Add an option for targets and an error message if no CPU is set.

This affects the proposed amdgpu and avr targets.

amdgpu tracking issue: #135024
AVR MCP: https://github.com/rust-lang/compiler-team/issues/800
This commit is contained in:
bors 2025-01-30 20:21:50 +00:00
commit a730edcd67
7 changed files with 41 additions and 0 deletions

View file

@ -546,6 +546,7 @@ impl Target {
key!(link_env_remove, list);
key!(asm_args, list);
key!(cpu);
key!(need_explicit_cpu, bool);
key!(features);
key!(dynamic_linking, bool);
key!(direct_access_external_data, Option<bool>);
@ -720,6 +721,7 @@ impl ToJson for Target {
target_option_val!(link_env_remove);
target_option_val!(asm_args);
target_option_val!(cpu);
target_option_val!(need_explicit_cpu);
target_option_val!(features);
target_option_val!(dynamic_linking);
target_option_val!(direct_access_external_data);

View file

@ -2254,6 +2254,9 @@ pub struct TargetOptions {
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
/// to "generic".
pub cpu: StaticCow<str>,
/// Whether a cpu needs to be explicitly set.
/// Set to true if there is no default cpu. Defaults to false.
pub need_explicit_cpu: bool,
/// Default target features to pass to LLVM. These features overwrite
/// `-Ctarget-cpu` but can be overwritten with `-Ctarget-features`.
/// Corresponds to `llc -mattr=$features`.
@ -2686,6 +2689,7 @@ impl Default for TargetOptions {
link_script: None,
asm_args: cvs![],
cpu: "generic".into(),
need_explicit_cpu: false,
features: "".into(),
direct_access_external_data: None,
dynamic_linking: false,