Skip to content

Commit fb5acb8

Browse files
committed
Rename CLI option to target_api_feature, rework handling
- Rename to singular form, allowing comma separation and multiple occurrences - Allow usage of `target_api_feature` even if the target has no defined `target_api_kind`
1 parent efda8ad commit fb5acb8

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/doc/rustc/src/codegen-options/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,14 @@ point instructions in software. It takes one of the following values:
480480
* `y`, `yes`, `on`, or no value: use soft floats.
481481
* `n`, `no`, or `off`: use hardware floats (the default).
482482

483-
## target-api-features
483+
## target-api-feature
484484

485485
This option tells `rustc` which operating system APIs are expected to be supported for the target.
486486
Implied features are added as well.
487487

488+
API features are added as a comma-separated list (`-C target_api_feature=a,b`). The option can be
489+
specified more than once to add more features the the list.
490+
488491
#### Windows
489492

490493
Currently, this option is only used for Windows targets, where the feature

src/librustc_interface/util.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,25 @@ pub fn add_configuration(
5454
cfg.insert((tf, Some(sym::crt_dash_static)));
5555
}
5656

57+
let ta = sym::target_api_feature;
5758
let target_options = &sess.target.target.options;
59+
let mut selected_target_apis = sess.opts.cg.target_api_feature.as_ref();
60+
5861
if let Some(target_api_kind) = &target_options.target_api_kind {
5962
let target_api_defaults = &target_options.target_api_default_features;
60-
let selected_target_apis =
61-
sess.opts.cg.target_api_features.as_ref().unwrap_or(target_api_defaults);
63+
64+
let api_features_to_check = selected_target_apis.unwrap_or(target_api_defaults);
65+
selected_target_apis = Some(api_features_to_check);
6266

6367
let apis = rustc_target::api::get_enabled_target_api_features(
6468
target_api_kind,
65-
selected_target_apis,
69+
api_features_to_check,
6670
);
6771

68-
let ta = sym::target_api_feature;
6972
cfg.extend(apis.into_iter().map(|api| (ta, Some(Symbol::intern(api)))));
73+
}
74+
75+
if let Some(selected_target_apis) = selected_target_apis {
7076
cfg.extend(selected_target_apis.into_iter().map(|api| (ta, Some(Symbol::intern(api)))));
7177
}
7278
}

src/librustc_session/options.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ macro_rules! options {
273273
pub const parse_tls_model: &str =
274274
"one of supported TLS models (`rustc --print tls-models`)";
275275
pub const parse_target_feature: &str = parse_string;
276+
pub const parse_target_api_feature: &str = parse_opt_comma_list;
276277
}
277278

278279
#[allow(dead_code)]
@@ -673,6 +674,17 @@ macro_rules! options {
673674
None => false,
674675
}
675676
}
677+
678+
fn parse_target_api_feature(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool {
679+
match (slot, v) {
680+
(Some(vec), Some(s)) => { vec.extend(s.split(',').map(|s| s.to_string())); true },
681+
(slot @ None, Some(s)) => {
682+
*slot = Some(s.split(',').map(|s| s.to_string()).collect());
683+
true
684+
},
685+
_ => false,
686+
}
687+
}
676688
}
677689
) }
678690

@@ -768,8 +780,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
768780
"save all temporary output files during compilation (default: no)"),
769781
soft_float: bool = (false, parse_bool, [TRACKED],
770782
"use soft float ABI (*eabihf targets only) (default: no)"),
771-
target_api_features: Option<Vec<String>> = (None, parse_opt_list, [TRACKED],
772-
"a list of target APIs that are expected to be be available on the target (default: use target default)"),
783+
target_api_feature: Option<Vec<String>> = (None, parse_target_api_feature, [TRACKED],
784+
"a comma-separated list of target APIs that are expected to be be available on the target
785+
(default: use target default) (can be used multiple times)"),
773786
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
774787
"select target processor (`rustc --print target-cpus` for details)"),
775788
target_feature: String = (String::new(), parse_target_feature, [TRACKED],

0 commit comments

Comments
 (0)