feat(wasm): bundler build() minimal export + JS bridge round-trip 검증 (#1885 Phase 2 PR 6-2c-1)#1941
Merged
Merged
Conversation
…1885 PR 6-2c-1) Phase 2 핵심 — JS host ↔ WASM bundler 의 zts_fs callback round-trip 동작 검증. 실제 bundler.bundle() 호출은 PR 6-2c-2. 변경: - packages/wasm/src/wasm_bundler_entry.zig: * c_allocator (wasi-musl malloc, thread-safe) — Zig 0.15 wasm_allocator 가 multi-threaded 미지원 * main() stub — wasi-musl libc 가 main 심볼 강제 * alloc/dealloc export — JS 측 메모리 관리 * build(entry_path_ptr, len) export — fs.readFile 통과 echo (zts_fs 통과) - build.zig: wasm-bundler 에 linkLibC 추가 - packages/wasm/index.ts: * createWasiImports 확장 — wasi-musl 의존 fn 풀 stub (args/environ/proc_exit/ fd_*/path_*/sched_yield/poll_oneoff) * BundlerExports 갱신 (build/alloc/dealloc), bundlerMemory 별도 보관 (import_memory 라 instance.exports.memory undefined) * initBundler 가 SharedArrayBuffer 기반 WebAssembly.Memory 생성 + env.memory import * build() API — entry path → packed result decode - packages/wasm/index.test.ts: 통합 테스트 4개 (bundlerVersion/build/null) 검증: - zts-bundler.wasm = 5.5 KB - bun test 38 통과 (transpile 29 + VFS 5 + Bundler 4) - JS bridge round-trip: VFS.set → build("/foo.ts") → zts_fs.readFile callback → wasm → packed result → JS decode 다음: - PR 6-2c-2: wasm_bundler_entry build() 가 bundler.Bundler.init + bundle() 진짜 호출 - 호환성 검증 — Thread.Pool, fs.zig 의존, 기타 bundler 코드 wasm-musl link Refs #1885 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Bundler (minimal) test 가 zig-out/bin/zts-bundler.wasm 의존 — CI workflow 가 wasm-bundler 빌드 안 해서 ENOENT. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
/simplify 검토 — wasi-musl libc 의 fd_prestat_get / path_* 가 0 (success) 반환 시 gibberish 메모리 read 시도 → panic. EBADF 가 안전한 fallback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Smoke Test Results (CI)Smoke Test Results
Size Comparison (ZTS vs esbuild)
Average ratio: 0.82x | Smaller: 131 | Similar(±10%): 1 | Larger: 4
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 핵심 — JS host ↔ WASM bundler 의 `zts_fs` callback round-trip 동작 검증. 실제 `bundler.bundle()` 호출은 PR 6-2c-2.
핵심 검증:
```
VFS.set("/foo.ts", "...")
→ build("/foo.ts")
→ wasm bundler_entry.build()
→ fs.readFile (Zig)
→ zts_fs.readFile callback (JS)
→ VFS.get → packed result
→ wasm → JS decode
→ { code: "..." }
```
변경
`packages/wasm/src/wasm_bundler_entry.zig`
`build.zig`
`packages/wasm/index.ts`
`packages/wasm/index.test.ts`
검증
디자인 노트
wasi-musl 의존 이유: Zig 0.15 의 `wasm_allocator` (page_allocator 도 동일) 가 multi-threaded wasm 미지원. `wasm32-wasi-musl` + `linkLibC` 로 thread-safe `malloc` 사용.
WASI shim: bundler 가 wasi-musl libc 의존 → wasi_snapshot_preview1 의 다수 fn 호출. JS 측 stub (대부분 `return 0`) 으로 link 통과. bundler 가 실제 OS 의존 호출 안 한다는 가정.
SharedArrayBuffer: `shared_memory=true` + `import_memory=true` → JS 측이 `WebAssembly.Memory({ shared: true })` 생성, `env.memory` 로 import.
다음 단계
🤖 Generated with Claude Code