Skip to content

Commit 78b9887

Browse files
authored
feat: Wasm optimization failure issues a warning instead of error (#4461)
1 parent 52ad9b8 commit 78b9887

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
# UNRELEASED
44

5+
### feat: Wasm optimization failure issues a warning instead of error
6+
7+
The optimization functionality provided by `ic_wasm::optimize" cannot handle Wasm modules that contains 64-bit table.
8+
Instead of blocking the build, such optimization failure will issue a warning.
9+
510
### Frontend canister
611

712
Sets the `ic_env` cookie for all HTML files only if the canister environment changed in the `commit_batch` method.

e2e/assets/memory64/dfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "custom",
66
"candid": "empty.did",
77
"wasm": "m64.wasm",
8-
"build": "echo \"generated from (module (memory i64 0 0))\"",
8+
"build": "echo \"generated from (module (memory i64 0 0) (table i64 1 10 funcref))\"",
99
"shrink": true,
1010
"optimize": "Oz",
1111
"gzip": true

e2e/assets/memory64/m64.wasm

7 Bytes
Binary file not shown.

e2e/tests-dfx/build.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,7 @@ teardown() {
370370
@test "dfx build can post-process memory64 Wasm module" {
371371
install_asset memory64
372372
assert_command dfx build --check
373+
# the module contains table64 which is not supported by ic_wasm::optimize
374+
# optimization failure doesn't fail the build, but a warning is issued
375+
assert_contains "WARN: Failed to optimize the Wasm module:"
373376
}

src/dfx/src/lib/models/canister.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,20 @@ impl Canister {
153153
// optimize or shrink
154154
if let Some(level) = info.get_optimize() {
155155
trace!(logger, "Optimizing Wasm at level {}", level);
156-
ic_wasm::optimize::optimize(&mut m, &wasm_opt_level_convert(level), false, &None, true)
157-
.context("Failed to optimize the Wasm module.")?;
158-
modified = true;
156+
match ic_wasm::optimize::optimize(
157+
&mut m,
158+
&wasm_opt_level_convert(level),
159+
false,
160+
&None,
161+
true,
162+
) {
163+
Ok(()) => {
164+
modified = true;
165+
}
166+
Err(e) => {
167+
warn!(logger, "Failed to optimize the Wasm module: {}", e);
168+
}
169+
}
159170
} else if info.get_shrink() == Some(true)
160171
|| (info.get_shrink().is_none() && (info.is_rust() || info.is_motoko()))
161172
{

0 commit comments

Comments
 (0)