mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
WIP: Replace wasm-gc with wasm-opt (#12280)
* Use wasm-opt on runtime * Optimize for size * Simplify fn compact_wasm_file * Run a lighter pass for non production builds * Disable optimizations and keep name section * Update wasm-opt * Remove dward sections * Update wasm-opt * Update wasm-opt
This commit is contained in:
committed by
GitHub
parent
a29624ab83
commit
9c748c74de
Generated
+129
-39
@@ -93,9 +93,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.38"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
|
||||
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
@@ -836,9 +836,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.71"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
|
||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
]
|
||||
@@ -1030,6 +1030,16 @@ dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
|
||||
dependencies = [
|
||||
"termcolor",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "comfy-table"
|
||||
version = "6.0.0"
|
||||
@@ -1489,6 +1499,50 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cxxbridge-flags",
|
||||
"cxxbridge-macro",
|
||||
"link-cplusplus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx-build"
|
||||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"codespan-reporting",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"scratch",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-flags"
|
||||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a"
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-macro"
|
||||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.13.0"
|
||||
@@ -3904,6 +3958,15 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "link-cplusplus"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.4"
|
||||
@@ -6451,15 +6514,6 @@ dependencies = [
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-wasm"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16ad52817c4d343339b3bc2e26861bd21478eda0b7509acf83505727000512ac"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-wasm"
|
||||
version = "0.45.0"
|
||||
@@ -7237,9 +7291,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.5"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
|
||||
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -7258,9 +7312,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.25"
|
||||
version = "0.6.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||
|
||||
[[package]]
|
||||
name = "region"
|
||||
@@ -8074,7 +8128,7 @@ dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"parity-scale-codec",
|
||||
"parity-wasm 0.45.0",
|
||||
"parity-wasm",
|
||||
"paste 1.0.6",
|
||||
"rustix",
|
||||
"sc-allocator",
|
||||
@@ -8924,6 +8978,12 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "scratch"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
|
||||
|
||||
[[package]]
|
||||
name = "sct"
|
||||
version = "0.7.0"
|
||||
@@ -10095,7 +10155,7 @@ version = "5.0.0"
|
||||
dependencies = [
|
||||
"impl-serde",
|
||||
"parity-scale-codec",
|
||||
"parity-wasm 0.45.0",
|
||||
"parity-wasm",
|
||||
"scale-info",
|
||||
"serde",
|
||||
"sp-core-hashing-proc-macro",
|
||||
@@ -10534,7 +10594,7 @@ dependencies = [
|
||||
"tempfile",
|
||||
"toml",
|
||||
"walkdir",
|
||||
"wasm-gc-api",
|
||||
"wasm-opt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -10633,18 +10693,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.30"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
|
||||
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.30"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
|
||||
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -11092,7 +11152,7 @@ version = "1.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"cfg-if 0.1.10",
|
||||
"digest 0.10.3",
|
||||
"rand 0.8.5",
|
||||
"static_assertions",
|
||||
@@ -11367,24 +11427,54 @@ version = "0.2.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-gc-api"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0c32691b6c7e6c14e7f8fd55361a9088b507aa49620fcd06c09b3a1082186b9"
|
||||
dependencies = [
|
||||
"log",
|
||||
"parity-wasm 0.32.0",
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-instrument"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa1dafb3e60065305741e83db35c6c2584bb3725b692b5b66148a38d72ace6cd"
|
||||
dependencies = [
|
||||
"parity-wasm 0.45.0",
|
||||
"parity-wasm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-opt"
|
||||
version = "0.110.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b68e8037b4daf711393f4be2056246d12d975651b14d581520ad5d1f19219cec"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"libc",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"wasm-opt-cxx-sys",
|
||||
"wasm-opt-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-opt-cxx-sys"
|
||||
version = "0.110.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91adbad477e97bba3fbd21dd7bfb594e7ad5ceb9169ab1c93ab9cb0ada636b6f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cxx",
|
||||
"cxx-build",
|
||||
"wasm-opt-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-opt-sys"
|
||||
version = "0.110.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec4fa5a322a4e6ac22fd141f498d56afbdbf9df5debeac32380d2dcaa3e06941"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cc",
|
||||
"cxx",
|
||||
"cxx-build",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -11621,7 +11711,7 @@ version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc13b3c219ca9aafeec59150d80d89851df02e0061bc357b4d66fc55a8d38787"
|
||||
dependencies = [
|
||||
"parity-wasm 0.45.0",
|
||||
"parity-wasm",
|
||||
"wasmi-validation",
|
||||
"wasmi_core",
|
||||
]
|
||||
@@ -11632,7 +11722,7 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91ff416ad1ff0c42e5a926ed5d5fab74c0f098749aa0ad8b2a34b982ce0e867b"
|
||||
dependencies = [
|
||||
"parity-wasm 0.45.0",
|
||||
"parity-wasm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -20,6 +20,6 @@ strum = { version = "0.24.1", features = ["derive"] }
|
||||
tempfile = "3.1.0"
|
||||
toml = "0.5.4"
|
||||
walkdir = "2.3.2"
|
||||
wasm-gc-api = "0.1.11"
|
||||
sp-maybe-compressed-blob = { version = "4.1.0-dev", path = "../../primitives/maybe-compressed-blob" }
|
||||
filetime = "0.2.16"
|
||||
wasm-opt = "0.110"
|
||||
@@ -656,50 +656,39 @@ fn compact_wasm_file(
|
||||
project: &Path,
|
||||
profile: Profile,
|
||||
cargo_manifest: &Path,
|
||||
wasm_binary_name: Option<String>,
|
||||
out_name: Option<String>,
|
||||
) -> (Option<WasmBinary>, Option<WasmBinary>, WasmBinaryBloaty) {
|
||||
let default_wasm_binary_name = get_wasm_binary_name(cargo_manifest);
|
||||
let wasm_file = project
|
||||
let default_out_name = get_wasm_binary_name(cargo_manifest);
|
||||
let out_name = out_name.unwrap_or_else(|| default_out_name.clone());
|
||||
let in_path = project
|
||||
.join("target/wasm32-unknown-unknown")
|
||||
.join(profile.directory())
|
||||
.join(format!("{}.wasm", default_wasm_binary_name));
|
||||
.join(format!("{}.wasm", default_out_name));
|
||||
|
||||
let wasm_compact_file = if profile.wants_compact() {
|
||||
let wasm_compact_file = project.join(format!(
|
||||
"{}.compact.wasm",
|
||||
wasm_binary_name.clone().unwrap_or_else(|| default_wasm_binary_name.clone()),
|
||||
));
|
||||
wasm_gc::garbage_collect_file(&wasm_file, &wasm_compact_file)
|
||||
let (wasm_compact_path, wasm_compact_compressed_path) = if profile.wants_compact() {
|
||||
let wasm_compact_path = project.join(format!("{}.compact.wasm", out_name,));
|
||||
wasm_opt::OptimizationOptions::new_opt_level_0()
|
||||
.mvp_features_only()
|
||||
.debug_info(true)
|
||||
.add_pass(wasm_opt::Pass::StripDwarf)
|
||||
.run(&in_path, &wasm_compact_path)
|
||||
.expect("Failed to compact generated WASM binary.");
|
||||
Some(WasmBinary(wasm_compact_file))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let wasm_compact_compressed_file = wasm_compact_file.as_ref().and_then(|compact_binary| {
|
||||
let file_name =
|
||||
wasm_binary_name.clone().unwrap_or_else(|| default_wasm_binary_name.clone());
|
||||
|
||||
let wasm_compact_compressed_file =
|
||||
project.join(format!("{}.compact.compressed.wasm", file_name));
|
||||
|
||||
if compress_wasm(&compact_binary.0, &wasm_compact_compressed_file) {
|
||||
Some(WasmBinary(wasm_compact_compressed_file))
|
||||
let wasm_compact_compressed_path =
|
||||
project.join(format!("{}.compact.compressed.wasm", out_name));
|
||||
if compress_wasm(&wasm_compact_path, &wasm_compact_compressed_path) {
|
||||
(Some(WasmBinary(wasm_compact_path)), Some(WasmBinary(wasm_compact_compressed_path)))
|
||||
} else {
|
||||
None
|
||||
(Some(WasmBinary(wasm_compact_path)), None)
|
||||
}
|
||||
});
|
||||
|
||||
let bloaty_file_name = if let Some(name) = wasm_binary_name {
|
||||
format!("{}.wasm", name)
|
||||
} else {
|
||||
format!("{}.wasm", default_wasm_binary_name)
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let bloaty_file = project.join(bloaty_file_name);
|
||||
fs::copy(wasm_file, &bloaty_file).expect("Copying the bloaty file to the project dir.");
|
||||
let bloaty_path = project.join(format!("{}.wasm", out_name));
|
||||
fs::copy(in_path, &bloaty_path).expect("Copying the bloaty file to the project dir.");
|
||||
|
||||
(wasm_compact_file, wasm_compact_compressed_file, WasmBinaryBloaty(bloaty_file))
|
||||
(wasm_compact_path, wasm_compact_compressed_path, WasmBinaryBloaty(bloaty_path))
|
||||
}
|
||||
|
||||
fn compress_wasm(wasm_binary_path: &Path, compressed_binary_out_path: &Path) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user