Skip to content

Commit 22da5c6

Browse files
tannevaledclaude
andauthored
fix: compile on every GOOS/GOARCH Go supports except plan9 (#829)
A type-check of every package and test for each of the 47 pairs in `go tool dist list` found 31 that did not compile. 44 now do; android and ios compile their library packages (they only link through cgo). - Store gems (SQLite3, Sequel, ActiveRecord's adapter, Bolt, Bleve, Etcd, Confd) are constrained to the targets modernc.org/sqlite v1.60.1 has a port for (its lib/ directory: darwin amd64/arm64, freebsd 4, linux 8, netbsd/amd64, openbsd amd64/arm64, windows). Elsewhere bindings_store_stub.go, generalised from the wasm stubs, keeps `require` working and raises NotImplementedError "<gem> is not supported on <goos/goarch>" on use ("on wasm" stays as it was). classOfExtBinding's store cases moved to classOfStoreBinding so the other bindings keep their classes on those targets. - Errno: EMULTIHOP and ENOLINK join the per-target names (OpenBSD lacks them), ENOTRECOVERABLE and EOWNERDEAD are undefined on NetBSD and DragonFly; MRI's undefined_error treatment, as for js/wasm. - Process::RLIMIT_*: AS, MEMLOCK, NPROC and RSS come from per-OS tables (OpenBSD has no AS, AIX no MEMLOCK, Solaris/illumos only AS), as MRI defines them #ifdef. Setrlimit stores through a generic setter: the Rlimit fields are int64 on FreeBSD and DragonFly. - flock: x/sys/unix instead of syscall (Solaris has no syscall.Flock); on AIX, which has no flock(2), the fcntl(2) emulation of MRI's missing/flock.c. - Test-only servers: mysql_test.go also needs go-mysql-server's sockstate (Linux, macOS, Windows, FreeBSD); nats_bind_internal_test.go needs nats-server (not on AIX, nor FreeBSD 386/arm). CI gains `compile on every target`, one job per GOOS: go vet for each GOARCH, default and rbgo_core builds. plan9 stays out and the README says why: no errno numbers, Kill, Flock, Getrlimit or Stat_t in its syscall package, and four gem drivers that do not build there. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 447ed1c commit 22da5c6

44 files changed

Lines changed: 604 additions & 280 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,45 @@ jobs:
132132
- name: Test (GOARCH=386)
133133
run: GOARCH=386 go test -timeout=60m ./...
134134

135+
# Every GOOS/GOARCH pair Go supports must at least compile rbgo, its tests
136+
# and the rbgo_core build: a target that does not compile is one nobody can
137+
# embed rbgo on, and nothing else here would notice (the lanes above run six
138+
# of them). go vet type-checks every package with its tests for the target.
139+
# android and ios link only through cgo, so there the library packages are
140+
# built (no link) instead. plan9 is excluded: its syscall package has no
141+
# errno numbers and no POSIX process or file-lock calls, which rbgo's IO,
142+
# Errno and Process layers are written against (see README "Platforms").
143+
every-target:
144+
name: compile on every target (${{ matrix.goos }})
145+
runs-on: ubuntu-latest
146+
env:
147+
CGO_ENABLED: "0"
148+
strategy:
149+
fail-fast: false
150+
matrix:
151+
goos: [aix, android, darwin, dragonfly, freebsd, illumos, ios, js, linux, netbsd, openbsd, solaris, wasip1, windows]
152+
steps:
153+
- uses: actions/checkout@v7
154+
- uses: actions/setup-go@v7
155+
with:
156+
go-version: 1.27.2
157+
- name: Vet (or build) every GOARCH of ${{ matrix.goos }}, both builds
158+
shell: bash
159+
run: |
160+
fail=0
161+
for t in $(go tool dist list | grep "^${{ matrix.goos }}/"); do
162+
arch=${t#*/}
163+
for tags in "" rbgo_core; do
164+
case "${{ matrix.goos }}" in
165+
android|ios) cmd="go build -tags=$tags . ./internal/..." ;;
166+
*) cmd="go vet -tags=$tags ./..." ;;
167+
esac
168+
echo "== $t [$tags]: $cmd"
169+
GOOS=${{ matrix.goos }} GOARCH=$arch $cmd || { echo "::error::$t [$tags] does not compile"; fail=1; }
170+
done
171+
done
172+
exit $fail
173+
135174
# WebAssembly (WASI preview 1) gate: the same interpreter compiled for
136175
# GOOS=wasip1 GOARCH=wasm and RUN under a real wasm runtime. The database /
137176
# search / KV / heavy-network gem backends are compiled out on wasm (their

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,15 @@ Otherwise:
775775
| **wasip1/wasm** | built with `CGO_ENABLED=0 GOOS=wasip1 GOARCH=wasm` and **run** under [wazero](https://wazero.io), a pure-Go runtime — verified here: `wazero run rbgo.wasm -e 'puts (1..10).sum'` prints `55` |
776776
| **js/wasm (browser)** | `CGO_ENABLED=0 GOOS=js GOARCH=wasm go build ./...` plus `go vet` over `./cmd/wasm ./cmd/rbgo ./internal/vm`, then the playground module is **run** in node by `web/smoke.mjs` (`wasm (js, browser)` in `ci.yml`). Added with #684, which fixed the three `syscall` constants the `js` port does not define |
777777
| **rbgo_core** | `go vet` and the `internal/vm` suite with `-tags rbgo_core`, then the core playground module is built for js/wasm, its size bounded, and **run** in node by `web/smoke.mjs --core` (`rbgo_core (core build)` in `ci.yml`). See [the `rbgo_core` build](#the-rbgo_core-build-the-language-and-the-numeric-stack-no-gems) |
778+
| **every other target** | `go vet ./...`, default and `rbgo_core` builds, for **every GOOS/GOARCH pair `go tool dist list` names except plan9** — aix, android, darwin, dragonfly, freebsd, illumos, ios, js, linux (all 13 arches, mips and ppc64 included), netbsd, openbsd, solaris, wasip1, windows (`compile on every target` in `ci.yml`; android and ios link only through cgo, so their library packages are built instead). Compiling is all it checks there |
779+
780+
What a target lacks, rbgo leaves out the way MRI does:
781+
782+
- **The store gems** — SQLite3, Sequel, ActiveRecord's adapter, Bolt, Bleve, Etcd and Confd — need modernc.org/sqlite, which has a port for darwin/{amd64,arm64}, freebsd/{386,amd64,arm,arm64}, linux/{386,amd64,arm,arm64,loong64,ppc64le,riscv64,s390x}, netbsd/amd64, openbsd/{amd64,arm64} and windows. Elsewhere (wasm included) `require` still works and the modules exist, and the first real operation raises `NotImplementedError: sqlite3 is not supported on linux/mips64le` (or the gem and target in question).
783+
- **Errno**: a name the system's `<errno.h>` lacks is still a constant, naming `Errno::NOERROR`, as MRI's `undefined_error` does: `EMULTIHOP` and `ENOLINK` on OpenBSD, `ENOTRECOVERABLE` and `EOWNERDEAD` on NetBSD and DragonFly.
784+
- **`Process::RLIMIT_*`** exist only where the system has the resource: no `RLIMIT_AS` on OpenBSD, no `RLIMIT_MEMLOCK` on AIX, only `RLIMIT_AS` of the four optional ones on Solaris and illumos.
785+
- **`File#flock`** and PStore's lock use `flock(2)`; AIX has none, so there it is emulated with `fcntl(2)` record locks, exactly as MRI's `missing/flock.c` does.
786+
- **plan9 does not compile.** Its `syscall` package has no errno numbers (`syscall.EINVAL` is a string error there), no `Kill`, `Flock`, `Getrlimit` or `Stat_t`, and several gem drivers (nats, Kafka's franz-go, Thrift, gopher-lua) do not build for it; a port means a plan9 variant of rbgo's Errno, IO and Process layers.
778787

779788
**Not on the pull-request path** — validated on a nightly schedule instead:
780789
`riscv64`, `loong64`, `ppc64le`, `s390x` and 32-bit `arm`, under QEMU

‎internal/vm/activerecord_adapter.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5-
//go:build !wasm && !rbgo_core
5+
//go:build !wasm && !rbgo_core && ((darwin && (amd64 || arm64)) || (freebsd && (386 || amd64 || arm || arm64)) || (linux && (386 || amd64 || arm || arm64 || loong64 || ppc64le || riscv64 || s390x)) || (netbsd && amd64) || (openbsd && (amd64 || arm64)) || windows)
66

77
package vm
88

‎internal/vm/batch6_internal_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5-
//go:build !wasm && !rbgo_core
5+
//go:build !wasm && !rbgo_core && ((darwin && (amd64 || arm64)) || (freebsd && (386 || amd64 || arm || arm64)) || (linux && (386 || amd64 || arm || arm64 || loong64 || ppc64le || riscv64 || s390x)) || (netbsd && amd64) || (openbsd && (amd64 || arm64)) || windows)
66

77
package vm
88

‎internal/vm/bindings_native.go‎

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -101,68 +101,10 @@ func (vm *VM) classOfExtBinding(v object.Value) (*RClass, bool) {
101101
return vm.consts["OpenStack::Image"].(*RClass), true
102102
case *OpenStackIdentity:
103103
return vm.consts["OpenStack::Identity"].(*RClass), true
104-
case *SQLite3Database:
105-
return vm.consts["SQLite3::Database"].(*RClass), true
106-
case *SQLite3Statement:
107-
return vm.consts["SQLite3::Statement"].(*RClass), true
108-
case *SequelDBObj:
109-
return x.cls, true
110-
case *SequelDatasetObj:
111-
return x.cls, true
112-
case *SequelSchemaObj:
113-
return x.cls, true
114-
case *BoltDB:
115-
return x.cls, true
116-
case *BoltTx:
117-
return x.cls, true
118-
case *BoltBucket:
119-
return x.cls, true
120-
case *BoltCursor:
121-
return x.cls, true
122-
case *BleveIndex:
123-
return x.cls, true
124-
case *BleveMapping:
125-
return x.cls, true
126-
case *BleveQuery:
127-
return x.cls, true
128-
case *BleveSearchResult:
129-
return x.cls, true
130-
case *BleveHit:
131-
return x.cls, true
132-
case *BleveBatch:
133-
return x.cls, true
134-
case *BleveFacet:
135-
return x.cls, true
136-
case *EtcdClient:
137-
return x.cls, true
138-
case *EtcdKeyValue:
139-
return x.cls, true
140-
case *EtcdGetResult:
141-
return x.cls, true
142-
case *EtcdPutResult:
143-
return x.cls, true
144-
case *EtcdDelResult:
145-
return x.cls, true
146-
case *EtcdLease:
147-
return x.cls, true
148-
case *EtcdEvent:
149-
return x.cls, true
150-
case *EtcdTxn:
151-
return x.cls, true
152-
case *EtcdCmp:
153-
return x.cls, true
154-
case *EtcdOp:
155-
return x.cls, true
156-
case *EtcdTxnResult:
157-
return x.cls, true
158-
case *EtcdLock:
159-
return x.cls, true
160-
case *EtcdMember:
161-
return x.cls, true
162-
case *EtcdStatus:
163-
return x.cls, true
164104
}
165-
return nil, false
105+
// SQLite3, Sequel, Bolt, Bleve and Etcd are a separate seam: their drivers
106+
// build on fewer targets than the rest (see bindings_store.go).
107+
return vm.classOfStoreBinding(v)
166108
}
167109

168110
// valueEqualExtBinding is the native half of the value-equality seam for the

‎internal/vm/bindings_store.go‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright (c) the go-embedded-ruby/ruby authors
2+
//
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
//go:build !wasm && !rbgo_core && ((darwin && (amd64 || arm64)) || (freebsd && (386 || amd64 || arm || arm64)) || (linux && (386 || amd64 || arm || arm64 || loong64 || ppc64le || riscv64 || s390x)) || (netbsd && amd64) || (openbsd && (amd64 || arm64)) || windows)
6+
7+
package vm
8+
9+
import "github.com/go-embedded-ruby/ruby/internal/object"
10+
11+
// The store bindings — SQLite3, Sequel and ActiveRecord's adapter (all three over
12+
// modernc.org/sqlite), Bolt, Bleve and Etcd/Confd — build only where
13+
// modernc.org/sqlite has a port: the targets listed in this file's constraint,
14+
// which are exactly the GOOS_GOARCH pairs of modernc.org/sqlite v1.60.1's lib/
15+
// directory (its pure-Go translation is generated per target, and
16+
// modernc.org/libc under it likewise). Everywhere else — js/wasm and wasip1,
17+
// linux/mips*, linux/ppc64, AIX, Solaris and illumos, DragonFly, NetBSD and
18+
// OpenBSD on their smaller ports — bindings_store_stub.go installs graceful
19+
// modules whose operations raise NotImplementedError. Bolt, Bleve and Etcd
20+
// share the constraint rather than carrying their own: they are one seam, and
21+
// on AIX, the only further target where they would build without SQLite,
22+
// Bleve's mmap-go and Etcd's fileutil do not.
23+
24+
// classOfStoreBinding maps the store bindings' value types to their Ruby class,
25+
// the tail of classOfExtBinding. ok is false for any other value.
26+
func (vm *VM) classOfStoreBinding(v object.Value) (*RClass, bool) {
27+
switch x := v.(type) {
28+
case *SQLite3Database:
29+
return vm.consts["SQLite3::Database"].(*RClass), true
30+
case *SQLite3Statement:
31+
return vm.consts["SQLite3::Statement"].(*RClass), true
32+
case *SequelDBObj:
33+
return x.cls, true
34+
case *SequelDatasetObj:
35+
return x.cls, true
36+
case *SequelSchemaObj:
37+
return x.cls, true
38+
case *BoltDB:
39+
return x.cls, true
40+
case *BoltTx:
41+
return x.cls, true
42+
case *BoltBucket:
43+
return x.cls, true
44+
case *BoltCursor:
45+
return x.cls, true
46+
case *BleveIndex:
47+
return x.cls, true
48+
case *BleveMapping:
49+
return x.cls, true
50+
case *BleveQuery:
51+
return x.cls, true
52+
case *BleveSearchResult:
53+
return x.cls, true
54+
case *BleveHit:
55+
return x.cls, true
56+
case *BleveBatch:
57+
return x.cls, true
58+
case *BleveFacet:
59+
return x.cls, true
60+
case *EtcdClient:
61+
return x.cls, true
62+
case *EtcdKeyValue:
63+
return x.cls, true
64+
case *EtcdGetResult:
65+
return x.cls, true
66+
case *EtcdPutResult:
67+
return x.cls, true
68+
case *EtcdDelResult:
69+
return x.cls, true
70+
case *EtcdLease:
71+
return x.cls, true
72+
case *EtcdEvent:
73+
return x.cls, true
74+
case *EtcdTxn:
75+
return x.cls, true
76+
case *EtcdCmp:
77+
return x.cls, true
78+
case *EtcdOp:
79+
return x.cls, true
80+
case *EtcdTxnResult:
81+
return x.cls, true
82+
case *EtcdLock:
83+
return x.cls, true
84+
case *EtcdMember:
85+
return x.cls, true
86+
case *EtcdStatus:
87+
return x.cls, true
88+
}
89+
return nil, false
90+
}

0 commit comments

Comments
 (0)