From 3364a6ae9b6a7268666fa0274783ecad9cf3e411 Mon Sep 17 00:00:00 2001 From: Jet Pham Date: Thu, 5 Mar 2026 00:26:21 -0800 Subject: [PATCH] feat: turn on compiler optimizations for the wasm --- cgol/.cargo/config.toml | 6 ++++++ cgol/Cargo.toml | 25 ++++++++++++++----------- package.json | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cgol/.cargo/config.toml b/cgol/.cargo/config.toml index f4e8c00..df3f713 100644 --- a/cgol/.cargo/config.toml +++ b/cgol/.cargo/config.toml @@ -1,2 +1,8 @@ [build] target = "wasm32-unknown-unknown" + +[target.wasm32-unknown-unknown] +rustflags = ["-C", "link-arg=--strip-all"] + +[unstable] +build-std = ["core", "alloc", "std", "panic_abort"] diff --git a/cgol/Cargo.toml b/cgol/Cargo.toml index a8d6dec..870a5d0 100644 --- a/cgol/Cargo.toml +++ b/cgol/Cargo.toml @@ -1,3 +1,5 @@ +cargo-features = ["panic-immediate-abort"] + [package] name = "cgol" version = "0.1.0" @@ -5,16 +7,12 @@ authors = ["jet"] edition = "2021" [lib] -crate-type = ["cdylib", "rlib"] - -[features] -default = ["console_error_panic_hook"] +crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2" js-sys = "0.3" web-sys = { version = "0.3", features = [ - "console", "CanvasRenderingContext2d", "Document", "HtmlCanvasElement", @@ -23,23 +21,28 @@ web-sys = { version = "0.3", features = [ "Element", "EventTarget", "Performance", - "DomRect", "TouchEvent", "Touch", "TouchList", "ImageData", ] } - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. console_error_panic_hook = { version = "0.1", optional = true } +[features] +default = ["console_error_panic_hook"] + [dev-dependencies] wasm-bindgen-test = "0.3" +[package.metadata.wasm-pack.profile.release] +wasm-opt = false + +[profile.dev] +debug = "line-tables-only" + [profile.release] opt-level = 3 lto = true codegen-units = 1 +panic = "immediate-abort" +strip = true diff --git a/package.json b/package.json index 2e34aa0..bc37431 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "build": "vite build", - "build:wasm": "cd cgol && wasm-pack build --release --target web", + "build:wasm": "cd cgol && wasm-pack build --release --target web && wasm-opt pkg/cgol_bg.wasm -o pkg/cgol_bg.wasm -O4 --enable-bulk-memory --enable-nontrapping-float-to-int --enable-sign-ext --low-memory-unused --converge", "check": "npm run lint && tsc --noEmit", "dev": "vite", "format:check": "prettier --check \"**/*.{ts,tsx,js,jsx,mdx}\" --cache",