]>
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 | |
532ac7d7 | 13 | use super::wasm32_base; |
dfeec247 | 14 | use super::{LinkerFlavor, LldFlavor, Target}; |
abe05a73 | 15 | |
29967ef6 | 16 | pub fn target() -> Target { |
532ac7d7 | 17 | let mut options = wasm32_base::options(); |
29967ef6 XL |
18 | options.os = "unknown".to_string(); |
19 | options.linker_flavor = LinkerFlavor::Lld(LldFlavor::Wasm); | |
532ac7d7 | 20 | let clang_args = options.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap(); |
abe05a73 | 21 | |
532ac7d7 XL |
22 | // Make sure clang uses LLD as its linker and is configured appropriately |
23 | // otherwise | |
24 | clang_args.push("--target=wasm32-unknown-unknown".to_string()); | |
2c00a5a8 | 25 | |
532ac7d7 XL |
26 | // For now this target just never has an entry symbol no matter the output |
27 | // type, so unconditionally pass this. | |
28 | clang_args.push("-Wl,--no-entry".to_string()); | |
5869c6ff XL |
29 | |
30 | // Rust really needs a way for users to specify exports and imports in | |
31 | // the source code. --export-dynamic isn't the right tool for this job, | |
32 | // however it does have the side effect of automatically exporting a lot | |
33 | // of symbols, which approximates what people want when compiling for | |
34 | // wasm32-unknown-unknown expect, so use it for now. | |
35 | clang_args.push("-Wl,--export-dynamic".to_string()); | |
36 | ||
37 | // Add the flags to wasm-ld's args too. | |
38 | let lld_args = options.pre_link_args.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm)).unwrap(); | |
39 | lld_args.push("--no-entry".to_string()); | |
40 | lld_args.push("--export-dynamic".to_string()); | |
0bf4aa26 | 41 | |
29967ef6 | 42 | Target { |
8faf50e0 | 43 | llvm_target: "wasm32-unknown-unknown".to_string(), |
29967ef6 | 44 | pointer_width: 32, |
abe05a73 XL |
45 | data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(), |
46 | arch: "wasm32".to_string(), | |
532ac7d7 | 47 | options, |
29967ef6 | 48 | } |
abe05a73 | 49 | } |