feat: turn on compiler optimizations for the wasm

This commit is contained in:
Jet Pham 2026-03-05 00:26:21 -08:00
parent 7b726be760
commit 3364a6ae9b
No known key found for this signature in database
3 changed files with 21 additions and 12 deletions

View file

@ -1,2 +1,8 @@
[build] [build]
target = "wasm32-unknown-unknown" target = "wasm32-unknown-unknown"
[target.wasm32-unknown-unknown]
rustflags = ["-C", "link-arg=--strip-all"]
[unstable]
build-std = ["core", "alloc", "std", "panic_abort"]

View file

@ -1,3 +1,5 @@
cargo-features = ["panic-immediate-abort"]
[package] [package]
name = "cgol" name = "cgol"
version = "0.1.0" version = "0.1.0"
@ -5,16 +7,12 @@ authors = ["jet"]
edition = "2021" edition = "2021"
[lib] [lib]
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib"]
[features]
default = ["console_error_panic_hook"]
[dependencies] [dependencies]
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
js-sys = "0.3" js-sys = "0.3"
web-sys = { version = "0.3", features = [ web-sys = { version = "0.3", features = [
"console",
"CanvasRenderingContext2d", "CanvasRenderingContext2d",
"Document", "Document",
"HtmlCanvasElement", "HtmlCanvasElement",
@ -23,23 +21,28 @@ web-sys = { version = "0.3", features = [
"Element", "Element",
"EventTarget", "EventTarget",
"Performance", "Performance",
"DomRect",
"TouchEvent", "TouchEvent",
"Touch", "Touch",
"TouchList", "TouchList",
"ImageData", "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 } console_error_panic_hook = { version = "0.1", optional = true }
[features]
default = ["console_error_panic_hook"]
[dev-dependencies] [dev-dependencies]
wasm-bindgen-test = "0.3" wasm-bindgen-test = "0.3"
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
[profile.dev]
debug = "line-tables-only"
[profile.release] [profile.release]
opt-level = 3 opt-level = 3
lto = true lto = true
codegen-units = 1 codegen-units = 1
panic = "immediate-abort"
strip = true

View file

@ -5,7 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "vite build", "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", "check": "npm run lint && tsc --noEmit",
"dev": "vite", "dev": "vite",
"format:check": "prettier --check \"**/*.{ts,tsx,js,jsx,mdx}\" --cache", "format:check": "prettier --check \"**/*.{ts,tsx,js,jsx,mdx}\" --cache",