Skip to content

Commit 5d91c1c

Browse files
committed
add dedicated -C link-self-contained structure
1 parent 5bc8870 commit 5d91c1c

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,7 @@ name = "rustc_session"
39953995
version = "0.0.0"
39963996
dependencies = [
39973997
"atty",
3998+
"bitflags",
39983999
"getopts",
39994000
"libc",
40004001
"rustc_ast",

compiler/rustc_session/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
atty = "0.2.13"
8+
bitflags = "1.2.1"
89
getopts = "0.2"
910
rustc_macros = { path = "../rustc_macros" }
1011
tracing = "0.1"

compiler/rustc_session/src/config.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{lint, HashStableContext};
99
use crate::{EarlyErrorHandler, Session};
1010

1111
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
12-
1312
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
1413
use rustc_target::abi::Align;
1514
use rustc_target::spec::{LinkerFlavorCli, PanicStrategy, SanitizerSet, SplitDebuginfo};
@@ -210,6 +209,50 @@ impl LinkerPluginLto {
210209
}
211210
}
212211

212+
/// The different values `-C link-self-contained` can take: a list of individually enabled or
213+
/// disabled components used during linking, coming from the rustc distribution, instead of being
214+
/// found somewhere on the host system.
215+
///
216+
/// They can be set in bulk via `-C link-self-contained=yes|y|on` or `-C
217+
/// link-self-contained=no|n|off`, and those boolean values are the historical defaults.
218+
///
219+
/// But each component is fine-grained, and can be unstably targeted, to use:
220+
/// - some CRT objects
221+
/// - the libc static library
222+
/// - libgcc/libunwind libraries
223+
/// - a linker we distribute
224+
/// - some sanitizer runtime libraries
225+
/// - all other MinGW libraries and Windows import libs
226+
///
227+
#[derive(Default, Clone, PartialEq, Debug)]
228+
pub struct LinkSelfContained {
229+
/// Whether the user explicitly set `-C link-self-contained` on or off, the historical values.
230+
/// Used for compatibility with the existing opt-in and target inference.
231+
pub explicitly_set: Option<bool>,
232+
233+
/// The components that are enabled.
234+
components: LinkSelfContainedComponents,
235+
}
236+
237+
bitflags::bitflags! {
238+
#[derive(Default)]
239+
/// The `-C link-self-contained` components that can individually be enabled or disabled.
240+
pub struct LinkSelfContainedComponents: u8 {
241+
/// CRT objects (e.g. on `windows-gnu`, `musl`, `wasi` targets)
242+
const CRT_OBJECTS = 1 << 0;
243+
/// libc static library (e.g. on `musl`, `wasi` targets)
244+
const LIBC = 1 << 1;
245+
/// libgcc/libunwind (e.g. on `windows-gnu`, `fuchsia`, `fortanix`, `gnullvm` targets)
246+
const UNWIND = 1 << 2;
247+
/// Linker, dlltool, and their necessary libraries (e.g. on `windows-gnu` and for `rust-lld`)
248+
const LINKER = 1 << 3;
249+
/// Sanitizer runtime libraries
250+
const SANITIZERS = 1 << 4;
251+
/// Other MinGW libs and Windows import libs
252+
const MINGW = 1 << 5;
253+
}
254+
}
255+
213256
/// Used with `-Z assert-incr-state`.
214257
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
215258
pub enum IncrementalStateAssertion {

0 commit comments

Comments
 (0)