diff --git a/Cargo.lock b/Cargo.lock
index 01083d7c43f49..0cc8e9ffb6cd8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -43,6 +43,12 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
+[[package]]
+name = "ambient-authority"
+version = "0.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b"
+
[[package]]
name = "android_system_properties"
version = "0.1.5"
@@ -264,6 +270,17 @@ dependencies = [
"wait-timeout",
]
+[[package]]
+name = "async-trait"
+version = "0.1.89"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
[[package]]
name = "autocfg"
version = "1.5.0"
@@ -282,7 +299,7 @@ dependencies = [
"miniz_oxide",
"object 0.36.7",
"rustc-demangle",
- "windows-targets",
+ "windows-targets 0.52.6",
]
[[package]]
@@ -442,6 +459,72 @@ dependencies = [
"serde_core",
]
+[[package]]
+name = "cap-fs-ext"
+version = "3.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d5528f85b1e134ae811704e41ef80930f56e795923f866813255bc342cc20654"
+dependencies = [
+ "cap-primitives",
+ "cap-std",
+ "io-lifetimes",
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "cap-primitives"
+version = "3.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6cf3aea8a5081171859ef57bc1606b1df6999df4f1110f8eef68b30098d1d3a"
+dependencies = [
+ "ambient-authority",
+ "fs-set-times",
+ "io-extras",
+ "io-lifetimes",
+ "ipnet",
+ "maybe-owned",
+ "rustix 1.1.2",
+ "rustix-linux-procfs",
+ "windows-sys 0.59.0",
+ "winx",
+]
+
+[[package]]
+name = "cap-rand"
+version = "3.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d8144c22e24bbcf26ade86cb6501a0916c46b7e4787abdb0045a467eb1645a1d"
+dependencies = [
+ "ambient-authority",
+ "rand 0.8.7",
+]
+
+[[package]]
+name = "cap-std"
+version = "3.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6dc3090992a735d23219de5c204927163d922f42f575a0189b005c62d37549a"
+dependencies = [
+ "cap-primitives",
+ "io-extras",
+ "io-lifetimes",
+ "rustix 1.1.2",
+]
+
+[[package]]
+name = "cap-time-ext"
+version = "3.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "def102506ce40c11710a9b16e614af0cde8e76ae51b1f48c04b8d79f4b671a80"
+dependencies = [
+ "ambient-authority",
+ "cap-primitives",
+ "iana-time-zone",
+ "once_cell",
+ "rustix 1.1.2",
+ "winx",
+]
+
[[package]]
name = "capstone"
version = "0.14.0"
@@ -1413,6 +1496,17 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
+[[package]]
+name = "fd-lock"
+version = "4.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ce92ff622d6dadf7349484f42c93271a0d49b7cc4d466a936405bacbe10aa78"
+dependencies = [
+ "cfg-if",
+ "rustix 1.1.2",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "features-status-dump"
version = "0.1.0"
@@ -1523,6 +1617,17 @@ dependencies = [
"autocfg",
]
+[[package]]
+name = "fs-set-times"
+version = "0.20.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94e7099f6313ecacbe1256e8ff9d617b75d1bcb16a6fddef94866d225a01a14a"
+dependencies = [
+ "io-lifetimes",
+ "rustix 1.1.2",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "fs_extra"
version = "1.3.0"
@@ -1626,7 +1731,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1033caf0b349c518623b5396bfb2cf0bddf44f0306d543a250e5743297aafd10"
dependencies = [
"fnv",
- "hashbrown",
+ "hashbrown 0.17.1",
"indexmap",
"stable_deref_trait",
]
@@ -1674,6 +1779,15 @@ dependencies = [
"serde",
]
+[[package]]
+name = "hashbrown"
+version = "0.15.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
+dependencies = [
+ "foldhash 0.1.5",
+]
+
[[package]]
name = "hashbrown"
version = "0.17.1"
@@ -1976,7 +2090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
dependencies = [
"equivalent",
- "hashbrown",
+ "hashbrown 0.17.1",
"serde",
"serde_core",
]
@@ -2041,6 +2155,22 @@ dependencies = [
"unic-langid",
]
+[[package]]
+name = "io-extras"
+version = "0.18.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2285ddfe3054097ef4b2fe909ef8c3bcd1ea52a8f0d274416caebeef39f04a65"
+dependencies = [
+ "io-lifetimes",
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "io-lifetimes"
+version = "2.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06432fb54d3be7964ecd3649233cddf80db2832f47fec34c01f65b3d9d774983"
+
[[package]]
name = "ipc-channel"
version = "0.22.0"
@@ -2060,6 +2190,12 @@ dependencies = [
"windows 0.61.3",
]
+[[package]]
+name = "ipnet"
+version = "2.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
+
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
@@ -2366,6 +2502,12 @@ dependencies = [
"walkdir",
]
+[[package]]
+name = "linux-raw-sys"
+version = "0.4.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
+
[[package]]
name = "linux-raw-sys"
version = "0.11.0"
@@ -2439,6 +2581,12 @@ dependencies = [
"regex-automata",
]
+[[package]]
+name = "maybe-owned"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4"
+
[[package]]
name = "md-5"
version = "0.10.6"
@@ -2755,7 +2903,7 @@ checksum = "2e5a6c098c7a3b6547378093f5cc30bc54fd361ce711e05293a5cc589562739b"
dependencies = [
"crc32fast",
"flate2",
- "hashbrown",
+ "hashbrown 0.17.1",
"indexmap",
"memchr",
"ruzstd",
@@ -3227,13 +3375,24 @@ dependencies = [
"ptr_meta",
]
+[[package]]
+name = "rand"
+version = "0.8.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22f6172bdec972074665ed81ed53b71da00bfc44b65a753cfde883ec4c702a1a"
+dependencies = [
+ "libc",
+ "rand_chacha 0.3.1",
+ "rand_core 0.6.4",
+]
+
[[package]]
name = "rand"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ec095654a25171c2124e9e3393a930bddbffdc939556c914957a4c3e0a87166"
dependencies = [
- "rand_chacha",
+ "rand_chacha 0.9.0",
"rand_core 0.9.3",
]
@@ -3248,6 +3407,16 @@ dependencies = [
"rand_core 0.10.1",
]
+[[package]]
+name = "rand_chacha"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
+dependencies = [
+ "ppv-lite86",
+ "rand_core 0.6.4",
+]
+
[[package]]
name = "rand_chacha"
version = "0.9.0"
@@ -3258,6 +3427,15 @@ dependencies = [
"rand_core 0.9.3",
]
+[[package]]
+name = "rand_core"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
+dependencies = [
+ "getrandom 0.2.16",
+]
+
[[package]]
name = "rand_core"
version = "0.9.3"
@@ -3428,7 +3606,7 @@ checksum = "d9776093b7ca170454ab1406954f7b7d97a57c51dc6c0642957fb2ef25c2d399"
dependencies = [
"bytecheck",
"bytes",
- "hashbrown",
+ "hashbrown 0.17.1",
"indexmap",
"munge",
"ptr_meta",
@@ -3882,7 +4060,7 @@ dependencies = [
"either",
"elsa",
"ena",
- "hashbrown",
+ "hashbrown 0.17.1",
"indexmap",
"jobserver",
"libc",
@@ -4376,6 +4554,8 @@ dependencies = [
"rustc_target",
"tempfile",
"tracing",
+ "wasmi",
+ "wasmi_wasi",
]
[[package]]
@@ -5078,6 +5258,19 @@ dependencies = [
"unicode-width 0.1.14",
]
+[[package]]
+name = "rustix"
+version = "0.38.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
+dependencies = [
+ "bitflags",
+ "errno",
+ "libc",
+ "linux-raw-sys 0.4.15",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "rustix"
version = "1.1.2"
@@ -5087,10 +5280,20 @@ dependencies = [
"bitflags",
"errno",
"libc",
- "linux-raw-sys",
+ "linux-raw-sys 0.11.0",
"windows-sys 0.61.2",
]
+[[package]]
+name = "rustix-linux-procfs"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2fc84bf7e9aa16c4f2c758f27412dc9841341e16aa682d9c7ac308fe3ee12056"
+dependencies = [
+ "once_cell",
+ "rustix 1.1.2",
+]
+
[[package]]
name = "rustversion"
version = "1.0.22"
@@ -5389,6 +5592,12 @@ dependencies = [
"color-eyre",
]
+[[package]]
+name = "spin"
+version = "0.9.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
+
[[package]]
name = "stable_deref_trait"
version = "1.2.1"
@@ -5414,6 +5623,16 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+[[package]]
+name = "string-interner"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23de088478b31c349c9ba67816fa55d9355232d63c3afea8bf513e31f0f1d2c0"
+dependencies = [
+ "hashbrown 0.15.5",
+ "serde",
+]
+
[[package]]
name = "string_cache"
version = "0.9.0"
@@ -5498,6 +5717,22 @@ dependencies = [
"windows 0.62.2",
]
+[[package]]
+name = "system-interface"
+version = "0.27.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc4592f674ce18521c2a81483873a49596655b179f71c5e05d10c1fe66c78745"
+dependencies = [
+ "bitflags",
+ "cap-fs-ext",
+ "cap-std",
+ "fd-lock",
+ "io-lifetimes",
+ "rustix 0.38.44",
+ "windows-sys 0.59.0",
+ "winx",
+]
+
[[package]]
name = "tabled"
version = "0.15.0"
@@ -5528,7 +5763,7 @@ dependencies = [
"fastrand",
"getrandom 0.3.3",
"once_cell",
- "rustix",
+ "rustix 1.1.2",
"windows-sys 0.61.2",
]
@@ -5583,7 +5818,7 @@ dependencies = [
"indicatif",
"num",
"rand 0.9.3",
- "rand_chacha",
+ "rand_chacha 0.9.0",
"rayon",
]
@@ -5640,7 +5875,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5938a79ecf9cb8198d525ddb37cd8841f66ab98073f6a123af7ed7cdcbb73ae"
dependencies = [
"gimli 0.34.0",
- "hashbrown",
+ "hashbrown 0.17.1",
"itertools",
"object 0.39.1",
"tracing",
@@ -6281,6 +6516,30 @@ dependencies = [
"wit-bindgen-rt",
]
+[[package]]
+name = "wasi-common"
+version = "36.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c12f0cd37e6a4513802e3918a9d891ce846d69a7594225b558eafc588c16e7fb"
+dependencies = [
+ "anyhow",
+ "bitflags",
+ "cap-fs-ext",
+ "cap-rand",
+ "cap-std",
+ "cap-time-ext",
+ "fs-set-times",
+ "io-extras",
+ "io-lifetimes",
+ "log",
+ "rustix 1.1.2",
+ "system-interface",
+ "thiserror 2.0.17",
+ "tracing",
+ "wiggle",
+ "windows-sys 0.60.2",
+]
+
[[package]]
name = "wasi-preview1-component-adapter-provider"
version = "46.0.1"
@@ -6392,6 +6651,68 @@ dependencies = [
"wasmparser 0.257.1",
]
+[[package]]
+name = "wasmi"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22bf475363d09d960b48275c4ea9403051add498a9d80c64dbc91edabab9d1d0"
+dependencies = [
+ "spin",
+ "wasmi_collections",
+ "wasmi_core",
+ "wasmi_ir",
+ "wasmparser 0.228.0",
+ "wat",
+]
+
+[[package]]
+name = "wasmi_collections"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85851acbdffd675a9b699b3590406a1d37fc1e1fd073743c7c9cf47c59caacba"
+dependencies = [
+ "string-interner",
+]
+
+[[package]]
+name = "wasmi_core"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef64cf60195d1f937dbaed592a5afce3e6d86868fb8070c5255bc41539d68f9d"
+dependencies = [
+ "libm",
+]
+
+[[package]]
+name = "wasmi_ir"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5dcb572ce4400e06b5475819f3d6b9048513efbca785f0b9ef3a41747f944fd8"
+dependencies = [
+ "wasmi_core",
+]
+
+[[package]]
+name = "wasmi_wasi"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd3c9f1b4e454adae2feccb7d4606263b978b2211e93bb8338d17d563f4b3821"
+dependencies = [
+ "wasi-common",
+ "wasmi",
+ "wiggle",
+]
+
+[[package]]
+name = "wasmparser"
+version = "0.228.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4abf1132c1fdf747d56bbc1bb52152400c70f336870f968b85e89ea422198ae3"
+dependencies = [
+ "bitflags",
+ "indexmap",
+]
+
[[package]]
name = "wasmparser"
version = "0.247.0"
@@ -6410,12 +6731,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d92fc335fb6d48f46bda1d8b26b69e28320c15ac3272208333833d6e217e2b4a"
dependencies = [
"bitflags",
- "hashbrown",
+ "hashbrown 0.17.1",
"indexmap",
"semver",
"serde",
]
+[[package]]
+name = "wast"
+version = "35.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ef140f1b49946586078353a453a1d28ba90adfc54dde75710bc1931de204d68"
+dependencies = [
+ "leb128",
+]
+
[[package]]
name = "wast"
version = "257.0.1"
@@ -6435,7 +6765,7 @@ version = "1.257.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "672e5495f00c5fc6c6b502205bae4708aa4dd13d969754438743afe0a8af0f1d"
dependencies = [
- "wast",
+ "wast 257.0.1",
]
[[package]]
@@ -6460,6 +6790,46 @@ dependencies = [
"string_cache_codegen",
]
+[[package]]
+name = "wiggle"
+version = "36.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7aed7ef247a05956b0a25e7905fdb709ae89e506547af42897e40301b0658d07"
+dependencies = [
+ "anyhow",
+ "async-trait",
+ "bitflags",
+ "thiserror 2.0.17",
+ "tracing",
+ "wiggle-macro",
+]
+
+[[package]]
+name = "wiggle-generate"
+version = "36.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c9d5550c5f49730d0a8babd089771ff7412e598cf8f7bbe3b647b8e2147a11b"
+dependencies = [
+ "anyhow",
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+ "witx",
+]
+
+[[package]]
+name = "wiggle-macro"
+version = "36.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "602175405f0c04fd47439ad6afc5e151c4864883259254d3676562bfb00a7ce8"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+ "wiggle-generate",
+]
+
[[package]]
name = "winapi-util"
version = "0.1.11"
@@ -6667,7 +7037,16 @@ version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
- "windows-targets",
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "windows-sys"
+version = "0.60.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
+dependencies = [
+ "windows-targets 0.53.5",
]
[[package]]
@@ -6685,14 +7064,31 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
- "windows_aarch64_gnullvm",
- "windows_aarch64_msvc",
- "windows_i686_gnu",
- "windows_i686_gnullvm",
- "windows_i686_msvc",
- "windows_x86_64_gnu",
- "windows_x86_64_gnullvm",
- "windows_x86_64_msvc",
+ "windows_aarch64_gnullvm 0.52.6",
+ "windows_aarch64_msvc 0.52.6",
+ "windows_i686_gnu 0.52.6",
+ "windows_i686_gnullvm 0.52.6",
+ "windows_i686_msvc 0.52.6",
+ "windows_x86_64_gnu 0.52.6",
+ "windows_x86_64_gnullvm 0.52.6",
+ "windows_x86_64_msvc 0.52.6",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.53.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
+dependencies = [
+ "windows-link 0.2.1",
+ "windows_aarch64_gnullvm 0.53.1",
+ "windows_aarch64_msvc 0.53.1",
+ "windows_i686_gnu 0.53.1",
+ "windows_i686_gnullvm 0.53.1",
+ "windows_i686_msvc 0.53.1",
+ "windows_x86_64_gnu 0.53.1",
+ "windows_x86_64_gnullvm 0.53.1",
+ "windows_x86_64_msvc 0.53.1",
]
[[package]]
@@ -6719,48 +7115,96 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
+
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
+
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
+[[package]]
+name = "windows_i686_gnu"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
+
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
+
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
+[[package]]
+name = "windows_i686_msvc"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
+
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
+
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
+
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.53.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
+
[[package]]
name = "winnow"
version = "0.5.40"
@@ -6794,6 +7238,16 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab703352da6a72f35c39a533526393725640575bb211f61987a2748323ad956"
+[[package]]
+name = "winx"
+version = "0.36.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d"
+dependencies = [
+ "bitflags",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
@@ -6829,7 +7283,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f815340f0bb65d9775ae21e56b503b496683557b9b627b195d2766c25fb24ae"
dependencies = [
"anyhow",
- "hashbrown",
+ "hashbrown 0.17.1",
"id-arena",
"indexmap",
"log",
@@ -6841,6 +7295,18 @@ dependencies = [
"wasmparser 0.257.1",
]
+[[package]]
+name = "witx"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e366f27a5cabcddb2706a78296a40b8fcc451e1a6aba2fc1d94b4a01bdaaef4b"
+dependencies = [
+ "anyhow",
+ "log",
+ "thiserror 1.0.69",
+ "wast 35.0.2",
+]
+
[[package]]
name = "writeable"
version = "0.6.2"
@@ -6858,7 +7324,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156"
dependencies = [
"libc",
- "rustix",
+ "rustix 1.1.2",
]
[[package]]
diff --git a/README.md b/README.md
index ed35016eb3a23..3e84fdab3312b 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,11 @@
+```
+WASI_SDK_PATH=../wasi-sdk-33.0-x86_64-linux ./x.py build library --target wasm32-wasip1,x86_64-unknown-linux-gnu
+echo 'extern crate proc_macro; #[proc_macro] pub fn foo(a: proc_macro::TokenStream) -> proc_macro::TokenStream { println!("foo"); (a.to_string() + ";println!(\"Hello from wasm proc macro!\");").parse().unwrap() }' | rustc +stage1 - --crate-type proc-macro --target wasm32-wasip1 -Zwasm-proc-macros
+echo 'fn main() { foo::foo!(println!("Hello World")); }' | rustc +stage1 --extern foo=rust_out.wasm - --edition 2024 && ./rust_out
+WASI_SDK_PATH=../wasi-sdk-33.0-x86_64-linux ./x.py test tests/ui/proc-macro --set rust.wasm-proc-macros=true
+```
+
+
diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs
index 8f8d8b3149440..b470048310273 100644
--- a/compiler/rustc_builtin_macros/src/lib.rs
+++ b/compiler/rustc_builtin_macros/src/lib.rs
@@ -14,6 +14,7 @@
use std::sync::Arc;
+use rustc_data_structures::sync::IntoDynSyncSend;
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
use rustc_expand::proc_macro::BangProcMacro;
use rustc_span::sym;
@@ -145,8 +146,12 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
From: from::expand_deriving_from,
}
- let client = rustc_proc_macro::bridge::client::Client::expand1(rustc_proc_macro::quote);
- register(sym::quote, SyntaxExtensionKind::Bang(Arc::new(BangProcMacro { client })));
+ let client = rustc_proc_macro::bridge::client::Client::expand1(rustc_proc_macro::quote)
+ .into_dyn_client();
+ register(
+ sym::quote,
+ SyntaxExtensionKind::Bang(Arc::new(BangProcMacro { client: IntoDynSyncSend(client) })),
+ );
let requires = SyntaxExtensionKind::Attr(Arc::new(contracts::ExpandRequires));
register(sym::contracts_requires, requires);
let ensures = SyntaxExtensionKind::Attr(Arc::new(contracts::ExpandEnsures));
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs
index 40e2f60ca6442..59fddc205c090 100644
--- a/compiler/rustc_codegen_ssa/src/back/linker.rs
+++ b/compiler/rustc_codegen_ssa/src/back/linker.rs
@@ -1738,7 +1738,38 @@ fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec {
let stable_crate_id = tcx.stable_crate_id(LOCAL_CRATE);
let proc_macro_decls_name = rustc_session::generate_proc_macro_decls_symbol(stable_crate_id);
- vec![symbol_export_from_raw_name(tcx, proc_macro_decls_name, SymbolExportKind::Data)]
+ if tcx.sess.target.is_like_wasm {
+ vec![
+ symbol_export_from_raw_name(tcx, proc_macro_decls_name, SymbolExportKind::Data),
+ symbol_export_from_raw_name(
+ tcx,
+ "__rustc_proc_macro_alloc_buffer".to_owned(),
+ SymbolExportKind::Text,
+ ),
+ symbol_export_from_raw_name(
+ tcx,
+ "__rustc_proc_macro_buffer_replace".to_owned(),
+ SymbolExportKind::Text,
+ ),
+ symbol_export_from_raw_name(
+ tcx,
+ "__rustc_proc_macro_buffer_ptr".to_owned(),
+ SymbolExportKind::Text,
+ ),
+ symbol_export_from_raw_name(
+ tcx,
+ "__rustc_proc_macro_buffer_len".to_owned(),
+ SymbolExportKind::Text,
+ ),
+ symbol_export_from_raw_name(
+ tcx,
+ "__rustc_proc_macro_call_client".to_owned(),
+ SymbolExportKind::Text,
+ ),
+ ]
+ } else {
+ vec![symbol_export_from_raw_name(tcx, proc_macro_decls_name, SymbolExportKind::Data)]
+ }
}
pub(crate) fn linked_symbols(
diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs
index 105d2d796aa80..5a87d3e211e20 100644
--- a/compiler/rustc_expand/src/proc_macro.rs
+++ b/compiler/rustc_expand/src/proc_macro.rs
@@ -1,5 +1,6 @@
use rustc_ast as ast;
use rustc_ast::tokenstream::TokenStream;
+use rustc_data_structures::marker::IntoDynSyncSend;
use rustc_data_structures::profiling::TimingGuard;
use rustc_errors::ErrorGuaranteed;
use rustc_middle::ty::{self, TyCtxt};
@@ -31,7 +32,7 @@ fn record_expand_proc_macro<'a>(
}
pub struct BangProcMacro {
- pub client: pm::bridge::client::Client,
+ pub client: IntoDynSyncSend,
}
impl base::BangProcMacro for BangProcMacro {
@@ -58,7 +59,7 @@ impl base::BangProcMacro for BangProcMacro {
}
pub struct AttrProcMacro {
- pub client: pm::bridge::client::Client,
+ pub client: IntoDynSyncSend,
}
impl base::AttrProcMacro for AttrProcMacro {
@@ -88,7 +89,7 @@ impl base::AttrProcMacro for AttrProcMacro {
}
pub struct DeriveProcMacro {
- pub client: DeriveClient,
+ pub client: IntoDynSyncSend,
}
impl MultiItemModifier for DeriveProcMacro {
@@ -117,12 +118,12 @@ impl MultiItemModifier for DeriveProcMacro {
let input = &*tcx.arena.alloc(input);
let key: (LocalExpnId, &TokenStream) = (invoc_id, input);
- QueryDeriveExpandCtx::enter(ecx, self.client, move || {
+ QueryDeriveExpandCtx::enter(ecx, self.client.0.clone(), move || {
tcx.derive_macro_expansion(key).cloned()
})
})
} else {
- expand_derive_macro(invoc_id, input, ecx, self.client)
+ expand_derive_macro(invoc_id, input, ecx, &self.client)
};
let Ok(output) = res else {
@@ -178,13 +179,13 @@ pub(super) fn provide_derive_macro_expansion<'tcx>(
})
}
-type DeriveClient = pm::bridge::client::Client;
+type DeriveClient = pm::bridge::server::DynClient;
fn expand_derive_macro(
invoc_id: LocalExpnId,
input: TokenStream,
ecx: &mut ExtCtxt<'_>,
- client: DeriveClient,
+ client: &DeriveClient,
) -> Result {
let _timer =
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
@@ -239,7 +240,7 @@ impl QueryDeriveExpandCtx {
/// Must be called while the `enter` function is active.
fn with(f: F) -> R
where
- F: for<'a, 'b> FnOnce(&'b mut ExtCtxt<'a>, DeriveClient) -> R,
+ F: for<'a, 'b> FnOnce(&'b mut ExtCtxt<'a>, &DeriveClient) -> R,
{
DERIVE_EXPAND_CTX.with(|ctx| {
let ectx = {
@@ -252,7 +253,7 @@ impl QueryDeriveExpandCtx {
unsafe { casted.as_mut().unwrap() }
};
- f(ectx, ctx.client)
+ f(ectx, &ctx.client)
})
}
}
diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml
index 46a2f4b5114f9..b603aca87de8f 100644
--- a/compiler/rustc_metadata/Cargo.toml
+++ b/compiler/rustc_metadata/Cargo.toml
@@ -32,6 +32,8 @@ rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
tempfile = "3.7.1"
tracing = "0.1"
+wasmi = "1.0.9"
+wasmi_wasi = "1.0.9"
# tidy-alphabetical-end
[target.'cfg(target_os = "aix")'.dependencies]
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs
index 8feb1fbbb3d82..abd83d6f62395 100644
--- a/compiler/rustc_metadata/src/creader.rs
+++ b/compiler/rustc_metadata/src/creader.rs
@@ -11,7 +11,7 @@ use rustc_crate_store::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSourc
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::svh::Svh;
-use rustc_data_structures::sync::{self, FreezeReadGuard, FreezeWriteGuard};
+use rustc_data_structures::sync::{self, FreezeReadGuard, FreezeWriteGuard, IntoDynSyncSend};
use rustc_data_structures::unord::UnordMap;
use rustc_expand::base::SyntaxExtension;
use rustc_hir as hir;
@@ -23,7 +23,7 @@ use rustc_lint_defs::builtin::UNUSED_CRATE_DEPENDENCIES;
use rustc_middle::bug;
use rustc_middle::ty::data_structures::IndexSet;
use rustc_middle::ty::{TyCtxt, TyCtxtFeed};
-use rustc_proc_macro::bridge::client::Client as ProcMacroClient;
+use rustc_proc_macro::bridge::server::DynClient;
use rustc_session::Session;
use rustc_session::config::mitigation_coverage::DeniedPartialMitigationLevel;
use rustc_session::config::{
@@ -941,7 +941,7 @@ impl CStore {
&self,
path: &Path,
stable_crate_id: StableCrateId,
- ) -> Result<&'static [ProcMacroClient], CrateError> {
+ ) -> Result>, CrateError> {
Ok(crate::host_dylib::dlsym_proc_macros(path, stable_crate_id)?)
}
diff --git a/compiler/rustc_metadata/src/host_dylib.rs b/compiler/rustc_metadata/src/host_dylib.rs
index 8f446d2651207..53674bec1e1ba 100644
--- a/compiler/rustc_metadata/src/host_dylib.rs
+++ b/compiler/rustc_metadata/src/host_dylib.rs
@@ -1,9 +1,12 @@
use std::error::Error;
use std::path::Path;
+use std::sync::Arc;
use std::time::Duration;
+use rustc_data_structures::sync::IntoDynSyncSend;
use rustc_fs_util::try_canonicalize;
use rustc_proc_macro::bridge::client::Client as ProcMacroClient;
+use rustc_proc_macro::bridge::server::DynClient;
use rustc_session::StableCrateId;
use tracing::debug;
@@ -126,22 +129,182 @@ pub unsafe fn load_symbol_from_dylib(
pub(crate) fn dlsym_proc_macros(
path: &Path,
stable_crate_id: StableCrateId,
-) -> Result<&'static [ProcMacroClient], DylibError> {
+) -> Result>, DylibError> {
let sym_name = rustc_session::generate_proc_macro_decls_symbol(stable_crate_id);
debug!("trying to dlsym proc_macros {} for symbol `{}`", path.display(), sym_name);
unsafe {
// FIXME(bjorn3) this depends on the unstable slice memory layout
- let result = crate::load_symbol_from_dylib::<*const &[ProcMacroClient]>(path, &sym_name);
+ let result = load_symbol_from_dylib::<*const &[ProcMacroClient]>(path, &sym_name);
match result {
Ok(result) => {
debug!("loaded dlsym proc_macros {} for symbol `{}`", path.display(), sym_name);
- Ok(*result)
+ Ok((*result)
+ .iter()
+ .map(|proc_macro| IntoDynSyncSend(proc_macro.into_dyn_client()))
+ .collect())
}
- Err(err) => {
- debug!("failed to dlsym proc_macros {} for symbol `{}`", path.display(), sym_name);
- Err(err.into())
+ Err(_err) => {
+ let engine = wasmi::Engine::default();
+ let module = wasmi::Module::new(&engine, std::fs::read(path).unwrap()).unwrap();
+
+ let mut store =
+ wasmi::Store::new(&engine, wasmi_wasi::WasiCtxBuilder::new().build());
+ let mut linker = wasmi::Linker::new(&engine);
+ linker
+ .func_wrap("env", "__rustc_proc_macro_dispatch", |_: u32, _: u32| -> () {
+ unreachable!()
+ })
+ .unwrap();
+ wasmi_wasi::add_to_linker(&mut linker, |ctx| ctx).unwrap();
+ let instance = linker.instantiate_and_start(&mut store, &module).unwrap();
+
+ let memory = instance.get_export(&store, "memory").unwrap().into_memory().unwrap();
+
+ let sym = instance
+ .get_export(&store, &sym_name)
+ .unwrap()
+ .into_global()
+ .unwrap()
+ .get(&store)
+ .i32()
+ .unwrap();
+
+ let mut data = [0; 8];
+ memory.read(&store, sym as usize, &mut data).unwrap();
+ let ptr = u32::from_le_bytes(data[..4].try_into().unwrap());
+ let len = u32::from_le_bytes(data[4..8].try_into().unwrap());
+
+ Ok((0..len)
+ .map(|i| {
+ let mut data = [0; 4];
+ memory.read(&store, (ptr + 4 * i) as usize, &mut data).unwrap();
+ let func_ptr = u32::from_le_bytes(data);
+
+ IntoDynSyncSend(wasm_macro_client(engine.clone(), module.clone(), func_ptr))
+ })
+ .collect::>())
}
}
}
}
+
+fn wasm_macro_client(engine: wasmi::Engine, module: wasmi::Module, func_ptr: u32) -> DynClient {
+ DynClient {
+ run: Arc::new(move |config| {
+ struct Ctx<'a> {
+ wasi_ctx: wasmi_wasi::WasiCtx,
+ dispatch: rustc_proc_macro::bridge::Closure<'a>,
+ client_refs: Option,
+ }
+
+ #[derive(Clone)]
+ struct ClientRefs {
+ memory: wasmi::Memory,
+ buffer_replace: wasmi::TypedFunc<(u32, u32), ()>,
+ buffer_ptr: wasmi::TypedFunc<(u32,), (u32,)>,
+ buffer_len: wasmi::TypedFunc<(u32,), (u32,)>,
+ }
+
+ impl ClientRefs {
+ fn read(
+ &self,
+ store: &mut impl wasmi::AsContextMut,
+ buffer: u32,
+ ) -> Result, wasmi::Error> {
+ let (buffer_ptr,) = self.buffer_ptr.call(&mut *store, (buffer,))?;
+ let (buffer_len,) = self.buffer_len.call(&mut *store, (buffer,))?;
+ let mut data = vec![0; buffer_len as usize];
+ self.memory.read(store, buffer_ptr as usize, &mut data)?;
+ Ok(data)
+ }
+ }
+
+ let mut store = wasmi::Store::new(
+ &engine,
+ Ctx {
+ wasi_ctx: wasmi_wasi::WasiCtxBuilder::new()
+ .inherit_stdout()
+ .inherit_stderr()
+ .build(),
+ dispatch: config.dispatch,
+ client_refs: None,
+ },
+ );
+ let mut linker: wasmi::Linker> = wasmi::Linker::new(&engine);
+ linker
+ .func_new(
+ "env",
+ "__rustc_proc_macro_dispatch",
+ wasmi::FuncType::new([wasmi::ValType::I32, wasmi::ValType::I32], []),
+ |mut caller, inputs, _outputs| {
+ let client_refs = caller.data().client_refs.clone().unwrap();
+ let input_buffer = inputs[0].i32().unwrap().cast_unsigned();
+ let output_buffer = inputs[1].i32().unwrap().cast_unsigned();
+
+ let input_buffer_data = client_refs.read(&mut caller, input_buffer)?;
+
+ let output_buffer_data =
+ caller.data_mut().dispatch.call(input_buffer_data.into());
+
+ client_refs.buffer_replace.call(
+ &mut caller,
+ (output_buffer, output_buffer_data.len().try_into().unwrap()),
+ )?;
+ let (output_buffer_ptr,) =
+ client_refs.buffer_ptr.call(&mut caller, (output_buffer,))?;
+ client_refs.memory.write(
+ &mut caller,
+ output_buffer_ptr as usize,
+ &output_buffer_data,
+ )?;
+
+ Ok(())
+ },
+ )
+ .unwrap();
+ wasmi_wasi::add_to_linker(&mut linker, |ctx| &mut ctx.wasi_ctx).unwrap();
+ let instance = linker.instantiate_and_start(&mut store, &module).unwrap();
+
+ fn get_func(
+ instance: &wasmi::Instance,
+ store: &impl wasmi::AsContext,
+ name: &str,
+ ) -> wasmi::TypedFunc {
+ instance.get_export(store, name).unwrap().into_func().unwrap().typed(store).unwrap()
+ }
+
+ let client_refs = ClientRefs {
+ memory: instance.get_export(&store, "memory").unwrap().into_memory().unwrap(),
+ buffer_replace: get_func(&instance, &store, "__rustc_proc_macro_buffer_replace"),
+ buffer_ptr: get_func(&instance, &store, "__rustc_proc_macro_buffer_ptr"),
+ buffer_len: get_func(&instance, &store, "__rustc_proc_macro_buffer_len"),
+ };
+ store.data_mut().client_refs = Some(client_refs.clone());
+
+ let alloc_buffer: wasmi::TypedFunc<(u32,), (u32,)> =
+ get_func(&instance, &store, "__rustc_proc_macro_alloc_buffer");
+
+ let call_client: wasmi::TypedFunc<(u32, u32), (u32,)> =
+ get_func(&instance, &store, "__rustc_proc_macro_call_client");
+
+ let (input_buffer,) =
+ alloc_buffer.call(&mut store, (config.input.len().try_into().unwrap(),)).unwrap();
+ let input_buffer_ptr =
+ client_refs.buffer_ptr.call(&mut store, (input_buffer,)).unwrap().0;
+ instance
+ .get_export(&store, "memory")
+ .unwrap()
+ .into_memory()
+ .unwrap()
+ .write(&mut store, input_buffer_ptr as usize, &config.input)
+ .unwrap();
+
+ let (output_buffer,) = call_client.call(&mut store, (input_buffer, func_ptr)).unwrap();
+
+ let output_buffer_data = client_refs.read(&mut store, output_buffer).unwrap();
+
+ output_buffer_data.into()
+ }),
+ }
+}
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs
index 23b51dfbf62c6..1bd5b87cbfe26 100644
--- a/compiler/rustc_metadata/src/locator.rs
+++ b/compiler/rustc_metadata/src/locator.rs
@@ -223,9 +223,10 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::{OwnedSlice, slice_owned};
use rustc_data_structures::svh::Svh;
+use rustc_data_structures::sync::IntoDynSyncSend;
use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_fs_util::try_canonicalize;
-use rustc_proc_macro::bridge::client::Client as ProcMacroClient;
+use rustc_proc_macro::bridge::server::DynClient;
use rustc_session::filesearch::FileSearch;
use rustc_session::search_paths::PathKind;
use rustc_session::utils::CanonicalizedPath;
@@ -987,7 +988,8 @@ pub fn get_proc_macros(
path: &Path,
metadata_loader: &dyn MetadataLoader,
cfg_version: &'static str,
-) -> IoResult> {
+) -> IoResult, ProcMacroKind)>> {
+ // FIXME support wasm proc-macros
let host_tuple = TargetTuple::from_tuple(config::host_tuple());
let (host, _) = Target::search(&host_tuple, Path::new(""), false).unwrap();
@@ -1004,7 +1006,7 @@ pub fn get_proc_macros(
let proc_macro_info = metadata.get_proc_macro_info();
assert_eq!(proc_macro_info.len(), clients.len());
- Ok(clients.into_iter().copied().zip(proc_macro_info).collect())
+ Ok(clients.into_iter().zip(proc_macro_info).collect())
}
// ------------------------------------------ Error reporting -------------------------------------
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index 8a565369d7610..f42c3f0041e0c 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -12,7 +12,7 @@ use rustc_crate_store::{CrateSource, ExternCrate};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::owned_slice::OwnedSlice;
-use rustc_data_structures::sync::Lock;
+use rustc_data_structures::sync::{IntoDynSyncSend, Lock};
use rustc_data_structures::unhash::UnhashMap;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};
@@ -28,7 +28,7 @@ use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use rustc_middle::ty::codec::TyDecoder;
use rustc_middle::ty::{RestrictionKind, Visibility};
use rustc_middle::{bug, implement_ty_decoder};
-use rustc_proc_macro::bridge::client::Client as ProcMacroClient;
+use rustc_proc_macro::bridge::server::DynClient;
use rustc_serialize::opaque::MemDecoder;
use rustc_serialize::{Decodable, Decoder};
use rustc_session::config::TargetModifier;
@@ -107,7 +107,7 @@ pub(crate) struct CrateMetadata {
/// or `#[rustc_allow_incoherent_impl]`.
incoherent_impls: FxIndexMap>,
/// Proc macro function pointers for this crate, if it's a proc macro crate.
- raw_proc_macros: Option<&'static [ProcMacroClient]>,
+ raw_proc_macros: Option>>,
/// Source maps for code from the crate.
source_map_import_info: Lock>>,
/// For every definition in this crate, maps its `DefPathHash` to its `DefIndex`.
@@ -1010,7 +1010,11 @@ impl CrateMetadata {
bug!("missing `{descr}` for {:?}", self.local_def_id(id))
}
- fn raw_proc_macro(&self, tcx: TyCtxt<'_>, id: DefIndex) -> (ProcMacroClient, ProcMacroKind) {
+ fn raw_proc_macro(
+ &self,
+ tcx: TyCtxt<'_>,
+ id: DefIndex,
+ ) -> (IntoDynSyncSend, ProcMacroKind) {
// DefIndex's in root.proc_macro_data have a one-to-one correspondence
// with items in 'raw_proc_macros'.
let (pos, (_id, kind)) = self
@@ -1023,7 +1027,7 @@ impl CrateMetadata {
.enumerate()
.find(|(_pos, (i, _))| *i == id)
.unwrap();
- (self.raw_proc_macros.unwrap()[pos], kind.decode((self, tcx)))
+ (self.raw_proc_macros.as_ref().unwrap()[pos].clone(), kind.decode((self, tcx)))
}
fn opt_item_name(&self, item_index: DefIndex) -> Option {
@@ -1944,7 +1948,7 @@ impl CrateMetadata {
tcx: TyCtxt<'_>,
blob: MetadataBlob,
root: CrateRoot,
- raw_proc_macros: Option<&'static [ProcMacroClient]>,
+ raw_proc_macros: Option>>,
cnum: CrateNum,
cnum_map: CrateNumMap,
dep_kind: CrateDepKind,
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs
index 74f533e11e66f..8d1c49f064a7d 100644
--- a/compiler/rustc_session/src/session.rs
+++ b/compiler/rustc_session/src/session.rs
@@ -1296,7 +1296,7 @@ pub fn build_session(
dcx.handle().warn(warning)
}
- let wasm_proc_macro_tuple = TargetTuple::from_tuple("wasm32-wasip2");
+ let wasm_proc_macro_tuple = TargetTuple::from_tuple("wasm32-wasip1");
let (wasm_proc_macro_target, target_warnings) = Target::search(
&wasm_proc_macro_tuple,
sopts.sysroot.path(),
diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/bridge/buffer.rs
index 3176b9ea35c8c..1e6d12ec877b5 100644
--- a/library/proc_macro/src/bridge/buffer.rs
+++ b/library/proc_macro/src/bridge/buffer.rs
@@ -1,7 +1,7 @@
//! Buffer management for same-process client<->server communication.
use std::mem::{self, ManuallyDrop};
-use std::ops::Deref;
+use std::ops::{Deref, DerefMut};
use std::slice;
#[repr(C)]
@@ -31,6 +31,13 @@ impl Deref for Buffer {
}
}
+impl DerefMut for Buffer {
+ #[inline]
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe { slice::from_raw_parts_mut(self.data as *mut u8, self.len) }
+ }
+}
+
impl Buffer {
#[inline]
pub(super) fn new() -> Self {
diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/bridge/client.rs
index 48e6245ecf98b..0907971679842 100644
--- a/library/proc_macro/src/bridge/client.rs
+++ b/library/proc_macro/src/bridge/client.rs
@@ -297,3 +297,56 @@ impl Client {
}
}
}
+
+#[cfg(target_family = "wasm")]
+#[allow(unsafe_code)]
+#[unsafe(no_mangle)]
+fn __rustc_proc_macro_alloc_buffer(len: usize) -> *mut Buffer {
+ Box::into_raw(Box::new(Buffer::from(vec![0; len])))
+}
+
+#[cfg(target_family = "wasm")]
+#[allow(unsafe_code)]
+#[unsafe(no_mangle)]
+unsafe fn __rustc_proc_macro_buffer_replace(buffer: *mut Buffer, len: usize) {
+ unsafe { (*buffer) = Buffer::from(vec![0; len]) }
+}
+
+#[cfg(target_family = "wasm")]
+#[allow(unsafe_code)]
+#[unsafe(no_mangle)]
+unsafe fn __rustc_proc_macro_buffer_ptr(buffer: *mut Buffer) -> *mut u8 {
+ unsafe { (*buffer).as_mut_ptr() }
+}
+
+#[cfg(target_family = "wasm")]
+#[allow(unsafe_code)]
+#[unsafe(no_mangle)]
+unsafe fn __rustc_proc_macro_buffer_len(buffer: *mut Buffer) -> usize {
+ unsafe { (&*buffer).len() }
+}
+
+#[cfg(target_family = "wasm")]
+#[allow(unsafe_code)]
+#[unsafe(no_mangle)]
+fn __rustc_proc_macro_call_client(
+ input: &mut Buffer,
+ client: extern "C" fn(BridgeConfig<'_>) -> Buffer,
+) -> *mut Buffer {
+ #[link(wasm_import_module = "env")]
+ unsafe extern "C" {
+ fn __rustc_proc_macro_dispatch(input: &Buffer, output: &mut Buffer);
+ }
+
+ let dispatch = closure::Closure::from(Box::leak(Box::new(|input| {
+ let mut output = Buffer::new();
+ unsafe { __rustc_proc_macro_dispatch(&input, &mut output) }
+ output
+ })));
+
+ Box::into_raw(Box::new(client(BridgeConfig {
+ input: input.take(),
+ dispatch,
+ force_show_panics: true,
+ })))
+}
diff --git a/library/proc_macro/src/bridge/closure.rs b/library/proc_macro/src/bridge/closure.rs
index 88c4dd6630b15..56e06b9438427 100644
--- a/library/proc_macro/src/bridge/closure.rs
+++ b/library/proc_macro/src/bridge/closure.rs
@@ -5,7 +5,7 @@ use std::marker::PhantomData;
use super::Buffer;
#[repr(C)]
-pub(super) struct Closure<'a> {
+pub struct Closure<'a> {
call: extern "C" fn(*mut Env, Buffer) -> Buffer,
env: *mut Env,
// Prevent Send and Sync impls.
@@ -26,7 +26,7 @@ impl<'a, F: FnMut(Buffer) -> Buffer> From<&'a mut F> for Closure<'a> {
}
impl<'a> Closure<'a> {
- pub(super) fn call(&mut self, arg: Buffer) -> Buffer {
+ pub fn call(&mut self, arg: Buffer) -> Buffer {
(self.call)(self.env, arg)
}
}
diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs
index 8b60043f5dc2a..76e1a391d4925 100644
--- a/library/proc_macro/src/bridge/mod.rs
+++ b/library/proc_macro/src/bridge/mod.rs
@@ -109,6 +109,7 @@ pub mod server;
mod symbol;
use buffer::Buffer;
+pub use closure::Closure;
pub use panic_message::PanicMessage;
use rpc::{Decode, Encode};
@@ -120,13 +121,13 @@ use rpc::{Decode, Encode};
#[repr(C)]
pub struct BridgeConfig<'a> {
/// Buffer used to pass initial input to the client.
- input: Buffer,
+ pub input: Buffer,
/// Server-side function that the client uses to make requests.
- dispatch: closure::Closure<'a>,
+ pub dispatch: closure::Closure<'a>,
/// If 'true', always invoke the default panic hook
- force_show_panics: bool,
+ pub force_show_panics: bool,
}
impl !Send for BridgeConfig<'_> {}
diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/bridge/server.rs
index ff525c6cd7735..55b8496171bd6 100644
--- a/library/proc_macro/src/bridge/server.rs
+++ b/library/proc_macro/src/bridge/server.rs
@@ -4,7 +4,7 @@ use std::cell::Cell;
use std::hash::Hash;
use std::ops::{Bound, Range};
use std::sync::atomic::AtomicU32;
-use std::sync::mpsc;
+use std::sync::{Arc, mpsc};
use std::{panic, thread};
use crate::bridge::{
@@ -139,7 +139,7 @@ pub trait ExecutionStrategy {
&self,
dispatcher: &mut Dispatcher,
input: Buffer,
- run_client: extern "C" fn(BridgeConfig<'_>) -> Buffer,
+ run_client: &(dyn Fn(BridgeConfig<'_>) -> Buffer + Sync),
force_show_panics: bool,
) -> Buffer;
}
@@ -188,30 +188,32 @@ impl ExecutionStrategy for MaybeCrossThread {
&self,
dispatcher: &mut Dispatcher,
input: Buffer,
- run_client: extern "C" fn(BridgeConfig<'_>) -> Buffer,
+ run_client: &(dyn Fn(BridgeConfig<'_>) -> Buffer + Sync),
force_show_panics: bool,
) -> Buffer {
if self.cross_thread || ALREADY_RUNNING_SAME_THREAD.get() {
let (mut server, mut client) = MessagePipe::new();
- let join_handle = thread::spawn(move || {
- let mut dispatch = |b: Buffer| -> Buffer {
- client.send(b);
- client.recv().expect("server died while client waiting for reply")
- };
-
- run_client(BridgeConfig {
- input,
- dispatch: (&mut dispatch).into(),
- force_show_panics,
- })
- });
-
- while let Some(b) = server.recv() {
- server.send(dispatcher.dispatch(b));
- }
+ thread::scope(|scope| {
+ let join_handle = scope.spawn(move || {
+ let mut dispatch = |b: Buffer| -> Buffer {
+ client.send(b);
+ client.recv().expect("server died while client waiting for reply")
+ };
+
+ run_client(BridgeConfig {
+ input,
+ dispatch: (&mut dispatch).into(),
+ force_show_panics,
+ })
+ });
+
+ while let Some(b) = server.recv() {
+ server.send(dispatcher.dispatch(b));
+ }
- join_handle.join().unwrap()
+ join_handle.join().unwrap()
+ })
} else {
let _guard = RunningSameThreadGuard::new();
@@ -258,7 +260,7 @@ fn run_server<
strategy: &impl ExecutionStrategy,
server: S,
input: I,
- run_client: extern "C" fn(BridgeConfig<'_>) -> Buffer,
+ run_client: &(dyn Fn(BridgeConfig<'_>) -> Buffer + Sync),
force_show_panics: bool,
) -> Result {
let mut dispatcher = Dispatcher { handle_store: HandleStore::new(), server };
@@ -274,7 +276,18 @@ fn run_server<
Result::decode(&mut &buf[..], &mut dispatcher.handle_store)
}
+#[derive(Clone)]
+pub struct DynClient {
+ pub run: Arc) -> Buffer + Send + Sync>,
+}
+
impl client::Client {
+ pub fn into_dyn_client(self) -> DynClient {
+ DynClient { run: Arc::new(move |config| (self.run)(config)) }
+ }
+}
+
+impl DynClient {
pub fn run1(
&self,
strategy: &impl ExecutionStrategy,
@@ -285,8 +298,8 @@ impl client::Client {
where
S: Server,
{
- let client::Client { run } = *self;
- run_server(strategy, server, >::mark(input), run, force_show_panics)
+ let DynClient { run } = self;
+ run_server(strategy, server, >::mark(input), &**run, force_show_panics)
.map(|s|