Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
d3dc940
runtime: support sync source patches with Go 1.24
cpunion Jul 27, 2026
61a5252
runtime/pthread: correct attribute ABI signatures
cpunion Jul 27, 2026
d49f8f9
runtime/wasm: add blocking primitive scheduler hooks
cpunion Jul 27, 2026
c45e243
test(runtime): cover wasm blocking primitives
cpunion Jul 27, 2026
3af38d6
runtime/wasm: add host event timer queue
cpunion Jul 28, 2026
3e775cd
ssa/wasm: use static defer continuation dispatch
cpunion Jul 28, 2026
fe3dc83
cl/wasm: lower go:wasmimport directives
cpunion Jul 28, 2026
fa2728b
runtime/wasm: update host runtime contracts
cpunion Jul 28, 2026
8c0ec5f
runtime/wasm: drive timers from host wakeups
cpunion Jul 28, 2026
cf0377e
build/wasm: centralize post-link output lifecycle
cpunion Jul 28, 2026
e3ed3c3
Merge branch 'codex/wasm-wasi-single-worker' into codex/wasm-blocking…
cpunion Jul 28, 2026
45ef9c9
Merge branch 'codex/wasm-blocking-primitives' into codex/wasm-timers-…
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
e1368d4
Merge branch 'codex/wasm-wasi-single-worker' into codex/wasm-blocking…
cpunion Jul 28, 2026
13ce085
Merge branch 'codex/wasm-blocking-primitives' into codex/wasm-timers-…
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
fcbd964
Merge branch 'codex/wasm-wasi-single-worker' into codex/wasm-blocking…
cpunion Jul 28, 2026
669f46f
test(build): adapt wasm sync patch coverage
cpunion Jul 28, 2026
d0fd0db
Merge branch 'codex/wasm-blocking-primitives' into codex/wasm-timers-…
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
cbbb130
Merge branch 'codex/wasm-wasi-single-worker' into codex/wasm-blocking…
cpunion Jul 29, 2026
3832c73
Merge branch 'codex/wasm-blocking-primitives' into codex/wasm-timers-…
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
82 changes: 80 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,61 @@ 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"
}

run_wasm_timers() {
local output
output=$(node --input-type=module -e "import Module from '$1'; await Module();" 2>&1)
test "$output" = "wasm timers ok"
}

run_wasi_timers() {
local output
wasm-tools validate --features all "$1"
output=$(wasmtime run -W exceptions=y "$1" 2>&1)
test "$output" = "wasm timers ok"
}

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-blocking
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 -o "$RUNNER_TEMP/wasm-timers-go.mjs" ./internal/build/testdata/wasm-timers
run_wasm_timers "$RUNNER_TEMP/wasm-timers-go.mjs"
llgo build -target wasm -o "$RUNNER_TEMP/wasm-timers.mjs" ./internal/build/testdata/wasm-timers
run_wasm_timers "$RUNNER_TEMP/wasm-timers.mjs"
GOOS=wasip1 GOARCH=wasm llgo build -o "$RUNNER_TEMP/wasm-timers-wasip1.wasm" ./internal/build/testdata/wasm-timers
run_wasi_timers "$RUNNER_TEMP/wasm-timers-wasip1.wasm"
file "$RUNNER_TEMP/runtime-js.wasm" \
"$RUNNER_TEMP/runtime-wasip1.wasm" \
"$RUNNER_TEMP/runtime-wasip1-threads.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
7 changes: 7 additions & 0 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
if fn == nil {
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx, p.needsLinkOnce(f))
}
if target := p.prog.Target(); target.GOARCH == "wasm" {
if decl, ok := f.Syntax().(*ast.FuncDecl); ok {
if module, importName, ok := wasmImportByDoc(decl.Doc); ok {
fn.SetWasmImport(module, importName)
}
}
}
noInlineDirective := hasNoInlineDirective(f)
runtimeStackNoInline := needsRuntimeStackNoInline(pkgTypes, f)
pcLineNoInline := p.needsPCLineNoInline(f)
Expand Down
21 changes: 21 additions & 0 deletions cl/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,27 @@ func (p *context) processNoInterfaceByDoc(doc *ast.CommentGroup, fullName string
}
}

func wasmImportByDoc(doc *ast.CommentGroup) (module, name string, ok bool) {
if doc == nil {
return
}
const prefix = "//go:wasmimport "
for n := len(doc.List) - 1; n >= 0; n-- {
line := doc.List[n].Text
if strings.HasPrefix(line, prefix) {
fields := strings.Fields(line[len(prefix):])
if len(fields) == 2 {
return fields[0], fields[1], true
}
return
}
if !strings.HasPrefix(line, "//go:") {
return
}
}
return
}

const (
noDirective = iota
hasLinkname
Expand Down
21 changes: 21 additions & 0 deletions cl/import_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ func TestParsePkgSyntaxReportsLocalityErrors(t *testing.T) {
}
}

func TestWasmImportByDoc(t *testing.T) {
module, name, ok := wasmImportByDoc(&ast.CommentGroup{List: []*ast.Comment{
{Text: "//go:noescape"},
{Text: "//go:wasmimport wasi_snapshot_preview1 fd_read"},
}})
if !ok || module != "wasi_snapshot_preview1" || name != "fd_read" {
t.Fatalf("wasm import = (%q, %q, %v)", module, name, ok)
}

for _, doc := range []*ast.CommentGroup{
nil,
{List: []*ast.Comment{{Text: "// ordinary comment"}}},
{List: []*ast.Comment{{Text: "//go:noescape"}}},
{List: []*ast.Comment{{Text: "//go:wasmimport missing-name"}}},
} {
if _, _, ok := wasmImportByDoc(doc); ok {
t.Fatalf("unexpected wasm import from %#v", doc)
}
}
}

func TestPkgSymInfoAddSymAndInitLinknamesCoverage(t *testing.T) {
dir := t.TempDir()
srcPath := filepath.Join(dir, "p.go")
Expand Down
35 changes: 35 additions & 0 deletions cl/wasm_import_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//go:build !llgo

package cl_test

import (
"strings"
"testing"

"github.com/goplus/llgo/cl/cltest"
llssa "github.com/goplus/llgo/ssa"
)

func TestWasmImportDirective(t *testing.T) {
const src = `package foo

//go:wasmimport wasi_snapshot_preview1 fd_read
func fdRead(fd int32, buf *byte, size uint32) uint32

func read(buf *byte) uint32 {
return fdRead(0, buf, 1)
}
`
ir := cltest.CompileIREx(t, src, "foo.go", false, func(prog llssa.Program) {
prog.Target().GOOS = "wasip1"
prog.Target().GOARCH = "wasm"
})
for _, want := range []string{
`"wasm-import-module"="wasi_snapshot_preview1"`,
`"wasm-import-name"="fd_read"`,
} {
if !strings.Contains(ir, want) {
t.Fatalf("missing %s in wasm import IR:\n%s", want, ir)
}
}
}
38 changes: 22 additions & 16 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,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 +336,9 @@ func Do(args []string, conf *Config) ([]Package, error) {
if conf.Target != "" && export.GOARCH != "" {
conf.Goarch = export.GOARCH
}
if conf.AppExt == "" {
conf.AppExt = defaultAppExt(conf)
}
if err := validateLinkOptions(conf, &export); err != nil {
return nil, err
}
Expand Down Expand Up @@ -418,10 +418,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 +724,22 @@ 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 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 +1362,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 +2366,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