Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
32670f9
runtime/wasm: add single-worker Asyncify scheduler
cpunion Jul 27, 2026
8b69b75
test(runtime): exercise wasm scheduler in Node
cpunion Jul 27, 2026
fe0d36d
build/wasm: distinguish Go Memory64 from wasm32 target
cpunion Jul 27, 2026
76f2b78
test(crosscompile): cover wasm target setup errors
cpunion Jul 27, 2026
0e631e5
runtime/wasm: make scheduler invariant failures fatal
cpunion Jul 27, 2026
6c7c3a7
runtime/wasm: add WASI single-worker scheduler
cpunion Jul 27, 2026
dfe6bcb
test(runtime): exercise WASI Asyncify scheduler
cpunion Jul 27, 2026
2cdb3cb
fix(runtime/wasm): initialize scheduler for minimal P1 mains
cpunion Jul 27, 2026
16feeaa
ci: install Binaryen for wasm cache tests
cpunion Jul 27, 2026
e3e8ea8
runtime/wasm: keep fiber host calls out of method roots
cpunion Jul 27, 2026
22f3cef
runtime: isolate non-moving GC platform hooks
cpunion Jul 28, 2026
f362bdf
runtime/wasm: add opt-in non-moving collector
cpunion Jul 28, 2026
1dfae34
ci: exercise opt-in wasm collector
cpunion Jul 28, 2026
abbc8b7
test: size wasm heap growth probe dynamically
cpunion Jul 28, 2026
8bb5f64
build/wasm: reject GC with threaded WASI
cpunion Jul 28, 2026
b7e6cfa
ci: select single-worker P1 for wasm GC
cpunion Jul 28, 2026
64cef9a
runtime: preserve ReadMemStats nil panic
cpunion Jul 28, 2026
cf0377e
build/wasm: centralize post-link output lifecycle
cpunion Jul 28, 2026
95fb9a7
ci: allow wasm runtime macOS tests to finish
cpunion Jul 28, 2026
7261611
Merge branch 'codex/wasm-single-worker-asyncify-scheduler' into codex…
cpunion Jul 28, 2026
3f31ec5
Merge branch 'codex/wasm-single-worker-asyncify-scheduler' into codex…
cpunion Jul 28, 2026
b2481ee
Merge remote-tracking branch 'upstream/main' into codex/wasm-single-w…
cpunion Jul 28, 2026
10b459e
Merge branch 'codex/wasm-single-worker-asyncify-scheduler' into codex…
cpunion Jul 28, 2026
45a4c50
Merge branch 'codex/wasm-single-worker-asyncify-scheduler' into codex…
cpunion Jul 28, 2026
0ac88a0
Merge branch 'codex/wasm-wasi-single-worker' into codex/tinygogc-wasm
cpunion Jul 29, 2026
c7d37eb
Merge remote-tracking branch 'upstream/main' into codex/wasm-single-w…
cpunion Jul 29, 2026
1b9ad7a
Merge branch 'codex/wasm-single-worker-asyncify-scheduler' into codex…
cpunion Jul 29, 2026
93eb05e
ssa/wasm: use static defer continuation dispatch
cpunion Jul 28, 2026
0da6714
Merge branch 'codex/wasm-static-defer-dispatch' into codex/wasm-wasi-…
cpunion Jul 29, 2026
3345423
Merge branch 'codex/wasm-wasi-single-worker' into codex/tinygogc-wasm
cpunion Jul 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/actions/setup-binaryen/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Setup Binaryen"
description: "Install a pinned Binaryen release"
inputs:
version:
description: "Binaryen release version"
required: false
default: "131"

runs:
using: "composite"
steps:
- name: Install Binaryen
shell: bash
run: |
set -euo pipefail

version="${{ inputs.version }}"
case "$(uname -s):$(uname -m)" in
Linux:x86_64) platform="x86_64-linux" ;;
Linux:aarch64|Linux:arm64) platform="aarch64-linux" ;;
Darwin:x86_64) platform="x86_64-macos" ;;
Darwin:arm64) platform="arm64-macos" ;;
*)
echo "Unsupported Binaryen host: $(uname -s) $(uname -m)" >&2
exit 1
;;
esac

archive="binaryen-version_${version}-${platform}.tar.gz"
base_url="https://github.com/WebAssembly/binaryen/releases/download/version_${version}"
cd "$RUNNER_TEMP"
curl --retry 3 --retry-all-errors -fsSLO "${base_url}/${archive}"
curl --retry 3 --retry-all-errors -fsSLO "${base_url}/${archive}.sha256"
if command -v sha256sum >/dev/null; then
sha256sum --check "${archive}.sha256"
else
shasum -a 256 --check "${archive}.sha256"
fi
tar -xzf "$archive" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/binaryen-version_${version}/bin" >> "$GITHUB_PATH"
3 changes: 3 additions & 0 deletions .github/workflows/build-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Set up Go
uses: ./.github/actions/setup-go

- name: Set up Binaryen
uses: ./.github/actions/setup-binaryen

- name: Install wamr (for wasm tests)
if: startsWith(matrix.os, 'macos')
run: |
Expand Down
71 changes: 69 additions & 2 deletions .github/workflows/llgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ jobs:
test:
name: test (${{ matrix.lane }}, ${{ matrix.os }}, LLVM ${{ matrix.llvm }}, Go ${{ matrix.go }}, shard ${{ matrix.shard }})
continue-on-error: ${{ matrix.lane == 'compatibility' }}
timeout-minutes: 30
# macOS runs the full package set in one shard and is normally just over
# 30 minutes once the wasm runtime sources are present.
timeout-minutes: 40
strategy:
matrix:
# Keep compatibility and primary toolchains pinned to exact patches.
Expand Down Expand Up @@ -366,6 +368,9 @@ jobs:
- name: Set up Go for building llgo
uses: ./.github/actions/setup-go

- name: Set up Binaryen
uses: ./.github/actions/setup-binaryen

- name: Install wamr
run: |
git clone --branch WAMR-2.4.4 --depth 1 https://github.com/bytecodealliance/wasm-micro-runtime.git
Expand Down Expand Up @@ -414,6 +419,24 @@ jobs:
with:
version: "4.0.21"

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: "25"

- name: Set up Binaryen
uses: ./.github/actions/setup-binaryen

- name: Set up Wasmtime
uses: bytecodealliance/actions/wasmtime/setup@v1
with:
version: "39.0.1"

- name: Set up wasm-tools
uses: bytecodealliance/actions/wasm-tools/setup@v1
with:
version: "1.243.0"

- name: Set up Go for building llgo
uses: ./.github/actions/setup-go

Expand All @@ -430,6 +453,50 @@ jobs:
- name: Build standard runtime for wasm
shell: bash
run: |
run_wasm_scheduler() {
local module="$1"
local output
node --input-type=module -e "import Module from '$module'; await Module();"
if output=$(node --input-type=module -e "import Module from '$module'; await Module({preRun: [module => { module.ENV.LLGO_WASM_SCHEDULER_DEADLOCK = '1'; }]});" 2>&1); then
echo "deadlock scheduler fixture unexpectedly succeeded"
return 1
fi
grep -Fq "fatal error: all goroutines are asleep - deadlock!" <<<"$output"
}

run_wasi_scheduler() {
local module="$1"
local output
wasm-tools validate --features all "$module"
output=$(wasmtime run -W exceptions=y "$module" 2>&1)
grep -Fq "wasm scheduler ok" <<<"$output"
if output=$(wasmtime run -W exceptions=y \
--env LLGO_WASM_SCHEDULER_DEADLOCK=1 "$module" 2>&1); then
echo "deadlock scheduler fixture unexpectedly succeeded"
return 1
fi
grep -Fq "fatal error: all goroutines are asleep - deadlock!" <<<"$output"
}

GOOS=js GOARCH=wasm llgo build -o "$RUNNER_TEMP/runtime-js.wasm" ./internal/build/testdata/wasm-runtime
GOOS=wasip1 GOARCH=wasm llgo build -o "$RUNNER_TEMP/runtime-wasip1.wasm" ./internal/build/testdata/wasm-runtime
file "$RUNNER_TEMP/runtime-js.wasm" "$RUNNER_TEMP/runtime-wasip1.wasm"
LLGO_WASI_THREADS=1 GOOS=wasip1 GOARCH=wasm llgo build \
-o "$RUNNER_TEMP/runtime-wasip1-threads.wasm" ./internal/build/testdata/wasm-runtime
test "$(wasmtime run -W exceptions=y "$RUNNER_TEMP/runtime-wasip1.wasm" 2>&1)" = "wasip1"
GOOS=js GOARCH=wasm llgo build -o "$RUNNER_TEMP/wasm-scheduler-go.mjs" ./internal/build/testdata/wasm-scheduler
run_wasm_scheduler "$RUNNER_TEMP/wasm-scheduler-go.mjs"
llgo build -target wasm -o "$RUNNER_TEMP/wasm-scheduler.mjs" ./internal/build/testdata/wasm-scheduler
run_wasm_scheduler "$RUNNER_TEMP/wasm-scheduler.mjs"
GOOS=wasip1 GOARCH=wasm llgo build -o "$RUNNER_TEMP/wasm-scheduler-wasip1.wasm" ./internal/build/testdata/wasm-scheduler
run_wasi_scheduler "$RUNNER_TEMP/wasm-scheduler-wasip1.wasm"
GOOS=js GOARCH=wasm llgo build -tags=llgo_wasm_gc -o "$RUNNER_TEMP/wasm-gc-go.mjs" ./internal/build/testdata/wasm-gc
node --input-type=module -e "import Module from '$RUNNER_TEMP/wasm-gc-go.mjs'; await Module();"
llgo build -target wasm -tags=llgo_wasm_gc -o "$RUNNER_TEMP/wasm-gc.mjs" ./internal/build/testdata/wasm-gc
node --input-type=module -e "import Module from '$RUNNER_TEMP/wasm-gc.mjs'; await Module();"
GOOS=wasip1 GOARCH=wasm LLGO_WASI_THREADS=0 llgo build -tags=llgo_wasm_gc -o "$RUNNER_TEMP/wasm-gc-wasip1.wasm" ./internal/build/testdata/wasm-gc
wasm-tools validate --features all "$RUNNER_TEMP/wasm-gc-wasip1.wasm"
test "$(wasmtime run -W exceptions=y "$RUNNER_TEMP/wasm-gc-wasip1.wasm" 2>&1)" = "wasm gc ok"
file "$RUNNER_TEMP/runtime-js.wasm" \
"$RUNNER_TEMP/runtime-wasip1.wasm" \
"$RUNNER_TEMP/runtime-wasip1-threads.wasm" \
"$RUNNER_TEMP/wasm-gc-wasip1.wasm"
5 changes: 5 additions & 0 deletions .github/workflows/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
with:
llvm-version: ${{matrix.llvm}}

- name: Set up Emscripten
uses: emscripten-core/setup-emsdk@v15
with:
version: "4.0.21"

- name: Set up Go for build
uses: ./.github/actions/setup-go

Expand Down
72 changes: 56 additions & 16 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"strings"
"sync"
"sync/atomic"
"unicode"

"golang.org/x/tools/go/ssa"

Expand Down Expand Up @@ -298,9 +299,6 @@ func Do(args []string, conf *Config) ([]Package, error) {
if conf.Goarch == "" {
conf.Goarch = runtime.GOARCH
}
if conf.AppExt == "" {
conf.AppExt = defaultAppExt(conf)
}
if conf.BuildMode == "" {
conf.BuildMode = BuildModeExe
}
Expand Down Expand Up @@ -339,6 +337,12 @@ func Do(args []string, conf *Config) ([]Package, error) {
if conf.Target != "" && export.GOARCH != "" {
conf.Goarch = export.GOARCH
}
if err := configureWasmGC(conf, &export); err != nil {
return nil, err
}
if conf.AppExt == "" {
conf.AppExt = defaultAppExt(conf)
}
if err := validateLinkOptions(conf, &export); err != nil {
return nil, err
}
Expand Down Expand Up @@ -418,10 +422,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
// final-PC sites for sidecar construction.
prog.EnableFuncInfoSites(shouldEnablePCLNSites(conf, funcInfo, emitDebugInfo))
sizes := func(sizes types.Sizes, compiler, arch string) types.Sizes {
if arch == "wasm" {
sizes = &types.StdSizes{WordSize: 4, MaxAlign: 4}
}
return prog.TypeSizes(sizes)
return prog.TypeSizes(effectiveTypeSizes(sizes, conf.Goos, arch, conf.Target))
}
dedup := packages.NewDeduper()
var syntaxErr error
Expand Down Expand Up @@ -727,16 +728,52 @@ func DefaultBuildTags(goarch, target string) string {

func defaultBuildTags(goarch, target string) string {
tags := "llgo,math_big_pure_go,purego"
// Raw GOOS/GOARCH wasm builds do not have a target configuration that
// selects a collector. BDWGC is not available in either wasm host, so use
// the supported collector-free runtime unless a named target supplies its
// own runtime configuration.
if goarch == "wasm" && target == "" {
// BDWGC is unavailable in both wasm hosts.
if goarch == "wasm" {
tags += ",nogc"
}
return tags
}

func configureWasmGC(conf *Config, export *crosscompile.Export) error {
if conf.Goarch != "wasm" || !hasBuildTag(conf.Tags, "llgo_wasm_gc") {
return nil
}
switch conf.Goos {
case "js":
if !slices.Contains(export.LDFLAGS, "-sMALLOC=none") {
export.LDFLAGS = append(export.LDFLAGS, "-sMALLOC=none")
}
case "wasip1":
if IsWasiThreadsEnabled() {
return errors.New("llgo_wasm_gc requires single-worker WASI (set LLGO_WASI_THREADS=0)")
}
default:
return fmt.Errorf("llgo_wasm_gc does not support GOOS=%s", conf.Goos)
}
return nil
}

func hasBuildTag(tags, want string) bool {
for _, tag := range strings.FieldsFunc(tags, func(r rune) bool {
return r == ',' || unicode.IsSpace(r)
}) {
if tag == want {
return true
}
}
return false
}

func effectiveTypeSizes(sizes types.Sizes, goos, goarch, target string) types.Sizes {
// Named wasm targets use the native wasm32 data model. The raw js/wasm
// entry point keeps Go's 64-bit word model and is emitted as Memory64.
if goarch == "wasm" && (target != "" || goos != "js") {
return &types.StdSizes{WordSize: 4, MaxAlign: 4}
}
return sizes
}

func allowMissingFunctionBodies(initial []*packages.Package) {
for _, pkg := range initial {
hasMissingBody := false
Expand Down Expand Up @@ -1359,12 +1396,15 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, outputPa
}
linkArgs = append(linkArgs, cSharedExportArgs(ctx, linkedOrder)...)

err = linkObjFiles(ctx, outputPath, linkInputs, linkArgs, verbose)
linkOutput, err := prepareWasmLinkOutput(ctx.buildConf, &ctx.crossCompile, outputPath)
if err != nil {
return err
}

return nil
defer cleanupWasmLinkOutput(linkOutput, outputPath)
if err := linkObjFiles(ctx, linkOutput, linkInputs, linkArgs, verbose); err != nil {
return err
}
return publishWasmLinkOutput(ctx, linkOutput, outputPath, verbose)
}

func linkedModuleGlobals(pkgs []Package) map[string]none {
Expand Down Expand Up @@ -2360,7 +2400,7 @@ func llvmPassPipeline(level optlevel.Level, ltoMode lto.Mode) string {
}

func IsWasiThreadsEnabled() bool {
return isEnvOn(llgoWasiThreads, true)
return isEnvOn(llgoWasiThreads, false)
}

func IsFullRpathEnabled() bool {
Expand Down
Loading
Loading