1
0

WIP: wasm compatible patcher?

This commit is contained in:
2026-03-15 21:43:16 +01:00
parent d646a4b766
commit 76d7e943e3
9 changed files with 1069 additions and 27 deletions

View File

@@ -4,43 +4,44 @@
- [x] Device detection proof of concept (File System Access API)
- [x] Serial prefix → model mapping (verified against official Kobo help page)
- [x] Architecture planning
- [x] Cloned kobopatch source (`kobopatch-src/`)
- [x] Architecture planning (updated: fully client-side, no PHP backend)
- [x] Installed Go via Homebrew (v1.26.1)
- [x] Verified all kobopatch tests pass natively
- [x] Verified all kobopatch tests pass under `GOOS=js GOARCH=wasm` (via Node.js)
- [x] Updated device identification doc with correct model list
- [x] Removed obsolete backend-api.md
- [x] Created `kobopatch-wasm/` with setup.sh, build.sh, go.mod, main.go
- [x] WASM wrapper compiles successfully (9.9MB)
- [x] All kobopatch tests still pass with our module's replace directives
- [x] Cleaned up .gitignore
## In Progress
### WASM Build of kobopatch
### Integration Testing
- [ ] Write Go WASM wrapper (`kobopatch-src/wasm/`) exposing `PatchFirmware()` to JS
- Accepts: config YAML (bytes), firmware zip (bytes), patch YAML files (bytes)
- Returns: KoboRoot.tgz (bytes) or error
- All I/O in-memory, no filesystem access
- [ ] Refactor `kobopatch/kobopatch.go` main logic into reusable function
- Strip `os.Open`/`os.Create` → use `io.Reader`/`io.Writer`
- Strip `os.Chdir` → resolve paths in memory
- Strip `exec.Command` (lrelease) → skip translations
- [ ] Compile with `GOOS=js GOARCH=wasm go build`
- [ ] Test WASM binary loads and runs in browser
- [ ] Test WASM binary in actual browser (load wasm_exec.js + kobopatch.wasm)
- [ ] Test `patchFirmware()` JS function end-to-end with real firmware zip + patches
### Frontend - Patch UI
- [ ] `patch-ui.js` - parse patch YAML client-side, render grouped toggles
- [ ] YAML parsing in JS (extract patch names, descriptions, enabled, PatchGroup)
- [ ] `patch-ui.js` — render grouped toggles per target file
- [ ] PatchGroup mutual exclusion (radio buttons)
- [ ] Bundle patch YAML files as static assets (or fetch from known URL)
- [ ] Generate kobopatch.yaml config from UI state
- [ ] Generate kobopatch.yaml config string from UI state
### Frontend - Build Flow
- [ ] User provides firmware zip (file input or drag-and-drop)
- [ ] Load WASM module, pass firmware + config + patches
- [ ] Receive KoboRoot.tgz blob from WASM
- [ ] Write KoboRoot.tgz to device via File System Access API
- [ ] Fallback: download KoboRoot.tgz if FS Access write fails
- [ ] User provides firmware zip (file input / drag-and-drop)
- [ ] Load WASM, call `patchFirmware()` with config + firmware + patch files
- [ ] Receive KoboRoot.tgz blob, write to `.kobo/` via File System Access API
- [ ] Fallback: download KoboRoot.tgz manually
- [ ] Bundle patch YAML files as static assets
## Future / Polish
- [ ] Browser compatibility warning with more detail
- [ ] Loading/progress states during WASM build (Web Worker?)
- [ ] Run WASM patching in a Web Worker (avoid blocking UI)
- [ ] Browser compatibility warning with detail
- [ ] Loading/progress states during build
- [ ] Error handling for common failure modes
- [ ] Host as static site (GitHub Pages / Netlify)
- [ ] NickelMenu install/uninstall support (bonus feature)

48
wip/wasm-feasibility.md Normal file
View File

@@ -0,0 +1,48 @@
# WASM Feasibility — Confirmed
## Test Results
All kobopatch tests pass under both native and WASM targets.
### Native (`go test ./...`)
```
ok github.com/pgaskin/kobopatch/kobopatch 0.003s
ok github.com/pgaskin/kobopatch/patchfile/kobopatch 0.003s
ok github.com/pgaskin/kobopatch/patchfile/patch32lsb 0.002s
ok github.com/pgaskin/kobopatch/patchlib 0.796s
```
### WASM (`GOOS=js GOARCH=wasm`, run via Node.js)
```
ok github.com/pgaskin/kobopatch/kobopatch 0.158s
ok github.com/pgaskin/kobopatch/patchfile/kobopatch 0.162s
ok github.com/pgaskin/kobopatch/patchfile/patch32lsb 0.133s
ok github.com/pgaskin/kobopatch/patchlib 9.755s
```
### Notes
- `patchlib` tests are ~12x slower under WASM (9.7s vs 0.8s) — expected overhead
- All pure Go dependencies compile to WASM without issues
- No CGO, no OS-specific syscalls in the core libraries
- Go WASM executor: `$(go env GOROOT)/lib/wasm/go_js_wasm_exec`
- Node.js v25.8.1 used for WASM test execution
## What Works in WASM
- Binary patching (`patchlib`)
- ARM Thumb-2 instruction assembly (`patchlib/asm`)
- ELF symbol table parsing (`patchlib/syms`)
- YAML patch format parsing (`patchfile/kobopatch`)
- Binary patch format parsing (`patchfile/patch32lsb`)
- CSS parsing (`patchlib/css`)
- Zlib compression/decompression
- tar.gz reading/writing
- ZIP extraction
## What Won't Work in WASM (and doesn't need to)
- `os.Open` / `os.Create` — replace with in-memory I/O
- `os.Chdir` — not needed, use in-memory paths
- `exec.Command` (lrelease for translations) — skip, rare use case
- `ioutil.TempDir` — not needed with in-memory approach