Skip to content

Support dynamically-linked and/or native musl targets #40113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Introduce temporary target feature crt_static_respected
This feature allows targets to opt in to full support of the crt-static
feature. Currently, crt-static is allowed on all targets, even those
that really can't or really shouldn't support it. This works because it
is very loose in the specification of its effects. Changing the behavior
of crt-static to be more strict in how it chooses libraries and links
executables would likely cause compilation to fail on these platforms.

To avoid breaking existing uses of crt-static, whitelist targets that
support the new, stricter behavior. For all other targets, this changes
crt-static from being "mostly a no-op" to "explicitly a no-op".
  • Loading branch information
smaeul committed Aug 22, 2017
commit beb8abe9a5045a232b423b909b7aaffecbf8bafc
9 changes: 9 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@ impl Session {
}

pub fn crt_static(&self) -> bool {
// If the target does not opt in to crt-static support, use its default.
if self.target.target.options.crt_static_respected {
self.crt_static_feature()
} else {
self.target.target.options.crt_static_default
}
}

pub fn crt_static_feature(&self) -> bool {
let requested_features = self.opts.cg.target_feature.split(',');
let found_negative = requested_features.clone().any(|r| r == "-crt-static");
let found_positive = requested_features.clone().any(|r| r == "+crt-static");
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_back/target/linux_musl_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub fn opts() -> TargetOptions {

// These targets statically link libc by default
base.crt_static_default = true;
// These targets allow the user to choose between static and dynamic linking.
base.crt_static_respected = true;

base
}
5 changes: 5 additions & 0 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ pub struct TargetOptions {

/// Whether or not the CRT is statically linked by default.
pub crt_static_default: bool,
/// Whether or not crt-static is respected by the compiler (or is a no-op).
pub crt_static_respected: bool,

/// Whether or not stack probes (__rust_probestack) are enabled
pub stack_probes: bool,
Expand Down Expand Up @@ -479,6 +481,7 @@ impl Default for TargetOptions {
panic_strategy: PanicStrategy::Unwind,
abi_blacklist: vec![],
crt_static_default: false,
crt_static_respected: false,
stack_probes: false,
}
}
Expand Down Expand Up @@ -715,6 +718,7 @@ impl Target {
key!(min_atomic_width, Option<u64>);
try!(key!(panic_strategy, PanicStrategy));
key!(crt_static_default, bool);
key!(crt_static_respected, bool);
key!(stack_probes, bool);

if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
Expand Down Expand Up @@ -903,6 +907,7 @@ impl ToJson for Target {
target_option_val!(max_atomic_width);
target_option_val!(panic_strategy);
target_option_val!(crt_static_default);
target_option_val!(crt_static_respected);
target_option_val!(stack_probes);

if default.abi_blacklist != self.options.abi_blacklist {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/windows_msvc_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub fn opts() -> TargetOptions {
is_like_windows: true,
is_like_msvc: true,
pre_link_args: args,
crt_static_respected: true,

.. Default::default()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
cfg.insert((tf, Some(feat)));
}

if sess.crt_static() {
if sess.crt_static_feature() {
cfg.insert((tf, Some(Symbol::intern("crt-static"))));
}
}