Skip to content

Commit 9d609c3

Browse files
authored
feat: add WASM build (#2)
* Add WASM build setup * Cleanup, reduce duplication * Significant reduction in binary size The `regex` crate is super heavy. * Add back removed packages * Add build workflow * Add tools flag
1 parent 2154c94 commit 9d609c3

File tree

14 files changed

+1052
-28
lines changed

14 files changed

+1052
-28
lines changed

.cargo/config.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.wasm32-unknown-unknown]
2+
rustflags = [
3+
"-C", "opt-level=z", # Optimize for size
4+
"-C", "panic=abort", # Use abort on panic (smaller binary)
5+
"-C", "codegen-units=1", # Single codegen unit for better optimization
6+
"-C", "strip=symbols", # Strip debug symbols
7+
"-C", "link-arg=-s", # Strip symbols in linker
8+
"-C", "link-arg=--gc-sections", # Remove unused sections
9+
"-C", "link-arg=--no-export-dynamic", # Prevent dynamic exports
10+
"-C", "link-arg=--import-memory", # Use imported memory (no file system access)
11+
]

.github/workflows/build.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-linux:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Rust nightly
17+
uses: dtolnay/rust-toolchain@nightly
18+
with:
19+
targets: wasm32-unknown-unknown
20+
21+
- name: Setup Node.js 24
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 24
25+
26+
- name: Enable Corepack
27+
run: corepack enable
28+
29+
- name: Install dependencies
30+
run: yarn install
31+
32+
- name: Build hmlanguagetools-rs
33+
run: cargo build --release --bin hmlanguagetools-rs --features="tools"
34+
35+
- name: Build WASM
36+
run: make wasm-optimized
37+
38+
- name: Upload hmlanguagetools-rs binary
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: hmlanguagetools-rs-linux
42+
path: target/release/hmlanguagetools-rs
43+
44+
- name: Upload WASM binary
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: tonytools-wasm
48+
path: target/wasm32-unknown-unknown/release/tonytools_optimized.wasm
49+
50+
- name: Run Cargo tests
51+
run: cargo test
52+
53+
build-windows:
54+
runs-on: windows-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Setup Rust nightly
59+
uses: dtolnay/rust-toolchain@nightly
60+
61+
- name: Build hmlanguagetools-rs
62+
run: cargo build --release --bin hmlanguagetools-rs --features="tools"
63+
64+
- name: Upload hmlanguagetools-rs binary
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: hmlanguagetools-rs-windows
68+
path: target/release/hmlanguagetools-rs.exe

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
debug/
44
target/
55

6-
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7-
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8-
Cargo.lock
9-
106
# These are backup files generated by rustfmt
117
**/*.rs.bk
128

@@ -19,11 +15,15 @@ Cargo.lock
1915
*.DLGE
2016
*.CLNG
2117
*.json
18+
!package.json
2219
*.DITL
2320
*.tga
2421
*.text
2522
*.texd
2623
*.tony
2724
*.tonymeta
2825
*.png
29-
*.dds
26+
*.dds
27+
28+
.yarn
29+
node_modules

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

0 commit comments

Comments
 (0)