Skip to content

Commit 72ec7a3

Browse files
committed
use LinkSelfContained for -C link-self-contained
1 parent f989d5a commit 72ec7a3

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
15341534
/// Whether we link to our own CRT objects instead of relying on gcc to pull them.
15351535
/// We only provide such support for a very limited number of targets.
15361536
fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
1537-
if let Some(self_contained) = sess.opts.cg.link_self_contained {
1537+
if let Some(self_contained) = sess.opts.cg.link_self_contained.crt.is_explicitly_set() {
15381538
return self_contained;
15391539
}
15401540

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::interface::parse_cfgspecs;
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
55
use rustc_session::config::InstrumentCoverage;
6+
use rustc_session::config::LinkSelfContained;
67
use rustc_session::config::Strip;
78
use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
89
use rustc_session::config::{
@@ -549,7 +550,7 @@ fn test_codegen_options_tracking_hash() {
549550
untracked!(incremental, Some(String::from("abc")));
550551
// `link_arg` is omitted because it just forwards to `link_args`.
551552
untracked!(link_args, vec![String::from("abc"), String::from("def")]);
552-
untracked!(link_self_contained, Some(true));
553+
untracked!(link_self_contained, LinkSelfContained::on());
553554
untracked!(linker, Some(PathBuf::from("linker")));
554555
untracked!(linker_flavor, Some(LinkerFlavor::Gcc));
555556
untracked!(no_stack_check, true);

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl LinkSelfContained {
230230
}
231231

232232
/// Keeps stable behavior only turning the self-contained CRT linking on.
233-
fn on() -> Self {
233+
pub fn on() -> Self {
234234
LinkSelfContained::crt_only()
235235
}
236236

compiler/rustc_session/src/options.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ mod desc {
414414
pub const parse_split_dwarf_kind: &str =
415415
"one of supported split dwarf modes (`split` or `single`)";
416416
pub const parse_gcc_ld: &str = "one of: no value, `lld`";
417+
pub const parse_link_self_contained: &str =
418+
"one of: `y`, `yes`, `on`, `n`, `no`, `off`, `auto`, `crt`, `linker`, `all`";
417419
pub const parse_stack_protector: &str =
418420
"one of (`none` (default), `basic`, `strong`, or `all`)";
419421
pub const parse_branch_protection: &str =
@@ -1027,6 +1029,20 @@ mod parse {
10271029
true
10281030
}
10291031

1032+
/// Parses `-C link-self-contained`: it used to be a boolean without a static default, but now
1033+
/// also accepts some strings, in addition to the regular boolean values.
1034+
pub(crate) fn parse_link_self_contained(slot: &mut LinkSelfContained, v: Option<&str>) -> bool {
1035+
// Whenever `-C link-self-contained` is passed without a value, it's an opt-in
1036+
// just like `parse_opt_bool`.
1037+
let s = v.unwrap_or("y");
1038+
1039+
match LinkSelfContained::from_str(s).ok() {
1040+
Some(value) => *slot = value,
1041+
None => return false,
1042+
}
1043+
true
1044+
}
1045+
10301046
pub(crate) fn parse_stack_protector(slot: &mut StackProtector, v: Option<&str>) -> bool {
10311047
match v.and_then(|s| StackProtector::from_str(s).ok()) {
10321048
Some(ssp) => *slot = ssp,
@@ -1116,7 +1132,7 @@ options! {
11161132
"extra arguments to append to the linker invocation (space separated)"),
11171133
link_dead_code: Option<bool> = (None, parse_opt_bool, [TRACKED],
11181134
"keep dead code at link time (useful for code coverage) (default: no)"),
1119-
link_self_contained: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
1135+
link_self_contained: LinkSelfContained = (LinkSelfContained::default(), parse_link_self_contained, [UNTRACKED],
11201136
"control whether to link Rust provided C objects/libraries or rely
11211137
on C toolchain installed in the system"),
11221138
linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],

0 commit comments

Comments
 (0)