Skip to content

Commit 0b6dce4

Browse files
Issue error when -C link-self-contained option is used on unsupported platforms
Document supported targets for `-C link-self-contained` Move `LinkSelfContainedDefault::True` from wasm_base to wasm32_wasi
1 parent dedfb9c commit 0b6dce4

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,9 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
15881588
/// We only provide such support for a very limited number of targets.
15891589
fn self_contained(sess: &Session, crate_type: CrateType) -> bool {
15901590
if let Some(self_contained) = sess.opts.cg.link_self_contained {
1591+
if sess.target.link_self_contained == LinkSelfContainedDefault::False {
1592+
sess.emit_err(errors::UnsupportedLinkSelfContained);
1593+
}
15911594
return self_contained;
15921595
}
15931596

compiler/rustc_codegen_ssa/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,7 @@ pub enum AppleSdkRootError<'a> {
530530
pub struct ReadFileError {
531531
pub message: std::io::Error,
532532
}
533+
534+
#[derive(Diagnostic)]
535+
#[diag(codegen_ssa_unsupported_link_self_contained)]
536+
pub struct UnsupportedLinkSelfContained;

compiler/rustc_error_messages/locales/en-US/codegen_ssa.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,5 @@ codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`
184184
codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {error}
185185
186186
codegen_ssa_read_file = failed to read file: {message}
187+
188+
codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target

compiler/rustc_target/src/spec/wasm32_wasi.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
//! best we can with this target. Don't start relying on too much here unless
7373
//! you know what you're getting in to!
7474
75-
use super::{crt_objects, wasm_base, Cc, LinkerFlavor, Target};
75+
use super::crt_objects::{self, LinkSelfContainedDefault};
76+
use super::{wasm_base, Cc, LinkerFlavor, Target};
7677

7778
pub fn target() -> Target {
7879
let mut options = wasm_base::options();
@@ -83,6 +84,9 @@ pub fn target() -> Target {
8384
options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained();
8485
options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained();
8586

87+
// FIXME: Figure out cases in which WASM needs to link with a native toolchain.
88+
options.link_self_contained = LinkSelfContainedDefault::True;
89+
8690
// Right now this is a bit of a workaround but we're currently saying that
8791
// the target by default has a static crt which we're taking as a signal
8892
// for "use the bundled crt". If that's turned off then the system's crt

compiler/rustc_target/src/spec/wasm_base.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::crt_objects::LinkSelfContainedDefault;
21
use super::{cvs, Cc, LinkerFlavor, PanicStrategy, RelocModel, TargetOptions, TlsModel};
32

43
pub fn options() -> TargetOptions {
@@ -95,9 +94,6 @@ pub fn options() -> TargetOptions {
9594

9695
pre_link_args,
9796

98-
// FIXME: Figure out cases in which WASM needs to link with a native toolchain.
99-
link_self_contained: LinkSelfContainedDefault::True,
100-
10197
// This has no effect in LLVM 8 or prior, but in LLVM 9 and later when
10298
// PIC code is implemented this has quite a drastic effect if it stays
10399
// at the default, `pic`. In an effort to keep wasm binaries as minimal

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ metrics.
210210

211211
## link-self-contained
212212

213-
On targets that support it this flag controls whether the linker will use libraries and objects
214-
shipped with Rust instead or those in the system.
213+
On `windows-gnu`, `linux-musl`, and `wasi` targets, this flag controls whether the
214+
linker will use libraries and objects shipped with Rust instead or those in the system.
215215
It takes one of the following values:
216216

217217
* no value: rustc will use heuristic to disable self-contained mode if system has necessary tools.

0 commit comments

Comments
 (0)