diff options
| author | daxpedda <daxpedda@gmail.com> | 2024-02-27 23:06:44 +0100 |
|---|---|---|
| committer | daxpedda <daxpedda@gmail.com> | 2024-03-10 09:00:01 +0100 |
| commit | f09c19ac3a514a0f74e25443f48898f80bde561c (patch) | |
| tree | 47cea8b1b80cf11cc4e6e9271b398517efeaea0b /compiler/rustc_target/src/spec | |
| parent | 5bc7b9ac8ace5312e1d2cdc2722715cf58d4f926 (diff) | |
| download | rust-f09c19ac3a514a0f74e25443f48898f80bde561c.tar.gz rust-f09c19ac3a514a0f74e25443f48898f80bde561c.zip | |
Introduce perma-unstable `wasm-c-abi` flag
Diffstat (limited to 'compiler/rustc_target/src/spec')
| -rw-r--r-- | compiler/rustc_target/src/spec/mod.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 3b6e15fad46..c42e818167c 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1807,6 +1807,19 @@ impl HasTargetSpec for Target { } } +/// Which C ABI to use for `wasm32-unknown-unknown`. +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum WasmCAbi { + /// Spec-compliant C ABI. + Spec, + /// Legacy ABI. Which is non-spec-compliant. + Legacy, +} + +pub trait HasWasmCAbiOpt { + fn wasm_c_abi_opt(&self) -> WasmCAbi; +} + type StaticCow<T> = Cow<'static, T>; /// Optional aspects of a target specification. @@ -2417,9 +2430,21 @@ impl DerefMut for Target { impl Target { /// Given a function ABI, turn it into the correct ABI for this target. - pub fn adjust_abi(&self, abi: Abi, c_variadic: bool) -> Abi { + pub fn adjust_abi<C>(&self, cx: &C, abi: Abi, c_variadic: bool) -> Abi + where + C: HasWasmCAbiOpt, + { match abi { - Abi::C { .. } => self.default_adjusted_cabi.unwrap_or(abi), + Abi::C { .. } => { + if self.arch == "wasm32" + && self.os == "unknown" + && cx.wasm_c_abi_opt() == WasmCAbi::Spec + { + abi + } else { + self.default_adjusted_cabi.unwrap_or(abi) + } + } // On Windows, `extern "system"` behaves like msvc's `__stdcall`. // `__stdcall` only applies on x86 and on non-variadic functions: |
