]> git.lizzy.rs Git - rust.git/commitdiff
Issue error when `-C link-self-contained` option is used on unsupported platforms
authorStackDoubleFlow <ojaslandge@gmail.com>
Tue, 8 Nov 2022 04:42:07 +0000 (22:42 -0600)
committerStackDoubleFlow <ojaslandge@gmail.com>
Tue, 15 Nov 2022 04:21:24 +0000 (22:21 -0600)
Document supported targets for `-C link-self-contained`

Move `LinkSelfContainedDefault::True` from wasm_base to wasm32_wasi

compiler/rustc_codegen_ssa/src/back/link.rs
compiler/rustc_codegen_ssa/src/errors.rs
compiler/rustc_error_messages/locales/en-US/codegen_ssa.ftl
compiler/rustc_target/src/spec/wasm32_wasi.rs
compiler/rustc_target/src/spec/wasm_base.rs
src/doc/rustc/src/codegen-options/index.md

index 4445e5f6c3a64e3d24c0d9379f15cfd74337eda1..2091730af22672758311fb41df19fb3be433e499 100644 (file)
@@ -1588,6 +1588,9 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
 /// We only provide such support for a very limited number of targets.
 fn self_contained(sess: &Session, crate_type: CrateType) -> bool {
     if let Some(self_contained) = sess.opts.cg.link_self_contained {
+        if sess.target.link_self_contained == LinkSelfContainedDefault::False {
+            sess.emit_err(errors::UnsupportedLinkSelfContained);
+        }
         return self_contained;
     }
 
index bfc4515de0984405ecb640911b802296ab1a109a..ade50af0aee8d7dabcc31b835100c55db03f2418 100644 (file)
@@ -530,3 +530,7 @@ pub enum AppleSdkRootError<'a> {
 pub struct ReadFileError {
     pub message: std::io::Error,
 }
+
+#[derive(Diagnostic)]
+#[diag(codegen_ssa_unsupported_link_self_contained)]
+pub struct UnsupportedLinkSelfContained;
index eb6b403d00e88943e8eddd6f32d66bce672b0bc4..70ce559526c3619dbbd9fd8592610f699c8e07db 100644 (file)
@@ -184,3 +184,5 @@ codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`
 codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {error}
 
 codegen_ssa_read_file = failed to read file: {message}
+
+codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target
index 93a956403e50fe56276e03c3398100c762a16c91..6f0bbf0672d449d555a32beae5bad63e1b0bfe96 100644 (file)
@@ -72,7 +72,8 @@
 //! best we can with this target. Don't start relying on too much here unless
 //! you know what you're getting in to!
 
-use super::{crt_objects, wasm_base, Cc, LinkerFlavor, Target};
+use super::crt_objects::{self, LinkSelfContainedDefault};
+use super::{wasm_base, Cc, LinkerFlavor, Target};
 
 pub fn target() -> Target {
     let mut options = wasm_base::options();
@@ -83,6 +84,9 @@ pub fn target() -> Target {
     options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained();
     options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained();
 
+    // FIXME: Figure out cases in which WASM needs to link with a native toolchain.
+    options.link_self_contained = LinkSelfContainedDefault::True;
+
     // Right now this is a bit of a workaround but we're currently saying that
     // the target by default has a static crt which we're taking as a signal
     // for "use the bundled crt". If that's turned off then the system's crt
index 528a84a8b37cbae3a2142cefff14f0206fe15551..625d3b37c4f2682d67ffd785ecc8b2a9a63f5a0b 100644 (file)
@@ -1,4 +1,3 @@
-use super::crt_objects::LinkSelfContainedDefault;
 use super::{cvs, Cc, LinkerFlavor, PanicStrategy, RelocModel, TargetOptions, TlsModel};
 
 pub fn options() -> TargetOptions {
@@ -95,9 +94,6 @@ macro_rules! args {
 
         pre_link_args,
 
-        // FIXME: Figure out cases in which WASM needs to link with a native toolchain.
-        link_self_contained: LinkSelfContainedDefault::True,
-
         // This has no effect in LLVM 8 or prior, but in LLVM 9 and later when
         // PIC code is implemented this has quite a drastic effect if it stays
         // at the default, `pic`. In an effort to keep wasm binaries as minimal
index f5a49410ea555e03f6937976d23ed8b8d08f5942..7e355b7fccfc4485a5f11e11d10165ce8148f607 100644 (file)
@@ -210,8 +210,8 @@ metrics.
 
 ## link-self-contained
 
-On targets that support it this flag controls whether the linker will use libraries and objects
-shipped with Rust instead or those in the system.
+On `windows-gnu`, `linux-musl`, and `wasi` targets, this flag controls whether the
+linker will use libraries and objects shipped with Rust instead or those in the system.
 It takes one of the following values:
 
 * no value: rustc will use heuristic to disable self-contained mode if system has necessary tools.