|
| 1 | +//! A "bare wasm" target representing a WebAssembly output that makes zero |
| 2 | +//! assumptions about its environment, similar to wasm32-unknown-unknown, but |
| 3 | +//! that also specifies an _upper_ bound on the set of wasm proposals that are |
| 4 | +//! supported. |
| 5 | +//! |
| 6 | +//! It is implemented as a variant on LLVM's wasm32-unknown-unknown target, with |
| 7 | +//! the additional flags `-Ctarget-cpu=mvp` and `-Ctarget-feature=+mutable-globals`. |
| 8 | +//! |
| 9 | +//! This target exists to resolve a tension in Rustc's choice of WebAssembly |
| 10 | +//! proposals to support. Since most WebAssembly users are in fact _on the web_ |
| 11 | +//! and web browsers are frequently updated with support for the latest |
| 12 | +//! features, it is reasonable for Rustc to generate wasm code that exploits new |
| 13 | +//! WebAssembly proposals as they gain browser support. At least by default. And |
| 14 | +//! this is what the wasm32-unknown-unknown target does, which means that the |
| 15 | +//! _exact_ WebAssembly features that Rustc generates will change over time. |
| 16 | +//! |
| 17 | +//! But a different set of users -- smaller but nonetheless worth supporting -- |
| 18 | +//! are using WebAssembly in implementations that either don't get updated very |
| 19 | +//! often, or need to prioritize stability, implementation simplicity or |
| 20 | +//! security over feature support. This target is for them, and it promises that |
| 21 | +//! the wasm code it generates will not go beyond the proposals/features of the |
| 22 | +//! W3C WebAssembly core 1.0 spec, which (as far as I can tell) is approximately |
| 23 | +//! "the wasm MVP plus mutable globals". Mutable globals was proposed in 2018 |
| 24 | +//! and made it in. |
| 25 | +//! |
| 26 | +//! See https://www.w3.org/TR/wasm-core-1/ |
| 27 | +//! |
| 28 | +//! Notably this feature-set _excludes_: |
| 29 | +//! |
| 30 | +//! - sign-extension operators |
| 31 | +//! - non-trapping / saturating float-to-int conversions |
| 32 | +//! - multi-value |
| 33 | +//! - reference types |
| 34 | +//! - bulk memory operations |
| 35 | +//! - SIMD |
| 36 | +//! |
| 37 | +//! These are all listed as additions in the core 2.0 spec. Also they were all |
| 38 | +//! proposed after 2020, and core 1.0 shipped in 2019. It also excludes even |
| 39 | +//! later proposals such as: |
| 40 | +//! |
| 41 | +//! - exception handling |
| 42 | +//! - tail calls |
| 43 | +//! - extended consts |
| 44 | +//! - function references |
| 45 | +//! - multi-memory |
| 46 | +//! - component model |
| 47 | +//! - gc |
| 48 | +//! - threads |
| 49 | +//! - relaxed SIMD |
| 50 | +//! - custom annotations |
| 51 | +//! - branch hinting |
| 52 | +//! |
| 53 | +
|
| 54 | +use crate::spec::{Cc, LinkerFlavor, Target, base}; |
| 55 | + |
| 56 | +pub(crate) fn target() -> Target { |
| 57 | + let mut options = base::wasm::options(); |
| 58 | + options.os = "none".into(); |
| 59 | + |
| 60 | + options.cpu = "mvp".into(); |
| 61 | + options.features = "+mutable-globals".into(); |
| 62 | + |
| 63 | + options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::No), &[ |
| 64 | + // For now this target just never has an entry symbol no matter the output |
| 65 | + // type, so unconditionally pass this. |
| 66 | + "--no-entry", |
| 67 | + ]); |
| 68 | + options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::Yes), &[ |
| 69 | + // Make sure clang uses LLD as its linker and is configured appropriately |
| 70 | + // otherwise |
| 71 | + "--target=wasm32-unknown-unknown", |
| 72 | + "-Wl,--no-entry", |
| 73 | + ]); |
| 74 | + |
| 75 | + Target { |
| 76 | + llvm_target: "wasm32-unknown-unknown".into(), |
| 77 | + metadata: crate::spec::TargetMetadata { |
| 78 | + description: Some("WebAssembly".into()), |
| 79 | + tier: Some(2), |
| 80 | + host_tools: Some(false), |
| 81 | + std: Some(false), |
| 82 | + }, |
| 83 | + pointer_width: 32, |
| 84 | + data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(), |
| 85 | + arch: "wasm32".into(), |
| 86 | + options, |
| 87 | + } |
| 88 | +} |
0 commit comments