]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs
Issue error when `-C link-self-contained` option is used on unsupported platforms
[rust.git] / compiler / rustc_target / src / spec / wasm32_unknown_unknown.rs
1 //! A "bare wasm" target representing a WebAssembly output that makes zero
2 //! assumptions about its environment.
3 //!
4 //! The `wasm32-unknown-unknown` target is intended to encapsulate use cases
5 //! that do not rely on any imported functionality. The binaries generated are
6 //! entirely self-contained by default when using the standard library. Although
7 //! the standard library is available, most of it returns an error immediately
8 //! (e.g. trying to create a TCP stream or something like that).
9 //!
10 //! This target is more or less managed by the Rust and WebAssembly Working
11 //! Group nowadays at <https://github.com/rustwasm>.
12
13 use super::{wasm_base, Cc, LinkerFlavor, Target};
14 use crate::spec::abi::Abi;
15
16 pub fn target() -> Target {
17     let mut options = wasm_base::options();
18     options.os = "unknown".into();
19
20     // This is a default for backwards-compatibility with the original
21     // definition of this target oh-so-long-ago. Once the "wasm" ABI is
22     // stable and the wasm-bindgen project has switched to using it then there's
23     // no need for this and it can be removed.
24     //
25     // Currently this is the reason that this target's ABI is mismatched with
26     // clang's ABI. This means that, in the limit, you can't merge C and Rust
27     // code on this target due to this ABI mismatch.
28     options.default_adjusted_cabi = Some(Abi::Wasm);
29
30     options.add_pre_link_args(
31         LinkerFlavor::WasmLld(Cc::No),
32         &[
33             // For now this target just never has an entry symbol no matter the output
34             // type, so unconditionally pass this.
35             "--no-entry",
36             // Rust really needs a way for users to specify exports and imports in
37             // the source code. --export-dynamic isn't the right tool for this job,
38             // however it does have the side effect of automatically exporting a lot
39             // of symbols, which approximates what people want when compiling for
40             // wasm32-unknown-unknown expect, so use it for now.
41             "--export-dynamic",
42         ],
43     );
44     options.add_pre_link_args(
45         LinkerFlavor::WasmLld(Cc::Yes),
46         &[
47             // Make sure clang uses LLD as its linker and is configured appropriately
48             // otherwise
49             "--target=wasm32-unknown-unknown",
50             "-Wl,--no-entry",
51             "-Wl,--export-dynamic",
52         ],
53     );
54
55     Target {
56         llvm_target: "wasm32-unknown-unknown".into(),
57         pointer_width: 32,
58         data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(),
59         arch: "wasm32".into(),
60         options,
61     }
62 }