]>
Commit | Line | Data |
---|---|---|
532ac7d7 XL |
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 | |
29967ef6 | 11 | //! Group nowadays at <https://github.com/rustwasm>. |
532ac7d7 | 12 | |
cdc7bbd5 | 13 | use super::wasm_base; |
dfeec247 | 14 | use super::{LinkerFlavor, LldFlavor, Target}; |
cdc7bbd5 | 15 | use crate::spec::abi::Abi; |
abe05a73 | 16 | |
29967ef6 | 17 | pub fn target() -> Target { |
cdc7bbd5 | 18 | let mut options = wasm_base::options(); |
5e7ed085 | 19 | options.os = "unknown".into(); |
29967ef6 | 20 | options.linker_flavor = LinkerFlavor::Lld(LldFlavor::Wasm); |
cdc7bbd5 XL |
21 | |
22 | // This is a default for backwards-compatibility with the original | |
23 | // definition of this target oh-so-long-ago. Once the "wasm" ABI is | |
24 | // stable and the wasm-bindgen project has switched to using it then there's | |
25 | // no need for this and it can be removed. | |
26 | // | |
27 | // Currently this is the reason that this target's ABI is mismatched with | |
28 | // clang's ABI. This means that, in the limit, you can't merge C and Rust | |
29 | // code on this target due to this ABI mismatch. | |
30 | options.default_adjusted_cabi = Some(Abi::Wasm); | |
31 | ||
064997fb FG |
32 | options.add_pre_link_args( |
33 | LinkerFlavor::Lld(LldFlavor::Wasm), | |
34 | &[ | |
35 | // For now this target just never has an entry symbol no matter the output | |
36 | // type, so unconditionally pass this. | |
37 | "--no-entry", | |
38 | // Rust really needs a way for users to specify exports and imports in | |
39 | // the source code. --export-dynamic isn't the right tool for this job, | |
40 | // however it does have the side effect of automatically exporting a lot | |
41 | // of symbols, which approximates what people want when compiling for | |
42 | // wasm32-unknown-unknown expect, so use it for now. | |
43 | "--export-dynamic", | |
44 | ], | |
45 | ); | |
46 | options.add_pre_link_args( | |
47 | LinkerFlavor::Gcc, | |
48 | &[ | |
49 | // Make sure clang uses LLD as its linker and is configured appropriately | |
50 | // otherwise | |
51 | "--target=wasm32-unknown-unknown", | |
52 | "-Wl,--no-entry", | |
53 | "-Wl,--export-dynamic", | |
54 | ], | |
55 | ); | |
0bf4aa26 | 56 | |
29967ef6 | 57 | Target { |
5e7ed085 | 58 | llvm_target: "wasm32-unknown-unknown".into(), |
29967ef6 | 59 | pointer_width: 32, |
5e7ed085 FG |
60 | data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(), |
61 | arch: "wasm32".into(), | |
532ac7d7 | 62 | options, |
29967ef6 | 63 | } |
abe05a73 | 64 | } |