Skip to content

Commit e5290ff

Browse files
committed
cm: extract into separate module
This depends on golang/go#34055 and https://go-review.googlesource.com/c/go/+/625577
1 parent f4ad832 commit e5290ff

File tree

8 files changed

+31
-29
lines changed

8 files changed

+31
-29
lines changed

.github/dependabot.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ updates:
1212
interval: weekly
1313
open-pull-requests-limit: 10
1414

15+
- package-ecosystem: gomod
16+
directory: "/cm"
17+
schedule:
18+
interval: weekly
19+
open-pull-requests-limit: 10
20+
1521
- package-ecosystem: gomod
1622
directory: "/tests"
1723
schedule:

.github/workflows/test.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
go-version-file: go.mod
3535

3636
- name: Vet Go code
37-
run: go vet ./...
37+
run: go vet ./... ./cm/... ./tests/...
3838

3939
# Test with Go
4040
test-go:
@@ -61,15 +61,15 @@ jobs:
6161
version: ${{ env.wasm-tools-version }}
6262

6363
- name: Run Go tests
64-
run: go test -v ./...
64+
run: go test -v ./... ./cm/...
6565

6666
- name: Run Go tests with race detector
67-
run: go test -v -race ./...
67+
run: go test -v -race ./... ./cm/...
6868

6969
- name: Test Go without cgo
7070
env:
7171
CGO_ENABLED: 0
72-
run: go test -v ./...
72+
run: go test -v ./... ./cm/...
7373

7474
- name: Verify repo is unchanged
7575
run: git diff --exit-code HEAD
@@ -108,7 +108,7 @@ jobs:
108108
version: ${{ env.wasm-tools-version }}
109109

110110
- name: Test with TinyGo
111-
run: tinygo test -v ./...
111+
run: tinygo test -v ./... ./cm/...
112112

113113
- name: Verify repo is unchanged
114114
run: git diff --exit-code HEAD
@@ -164,19 +164,19 @@ jobs:
164164
env:
165165
GOARCH: wasm
166166
GOOS: wasip1
167-
run: go test -v ./...
167+
run: go test -v ./... ./cm/...
168168

169169
- name: Test wasm/wasip1 with TinyGo 0.32.0
170170
if: ${{ matrix.tinygo-version == '0.32.0' }}
171-
run: tinygo test -v -target=wasi ./...
171+
run: tinygo test -v -target=wasi ./... ./cm/...
172172

173173
- name: Test wasm/wasip1 with TinyGo >= 0.33.0
174174
if: ${{ matrix.tinygo-version != '0.32.0' }}
175-
run: tinygo test -v -target=wasip1 ./...
175+
run: tinygo test -v -target=wasip1 ./... ./cm/...
176176

177177
- name: Test wasm/wasip2 with TinyGo >= 0.33.0
178178
if: ${{ matrix.tinygo-version != '0.32.0' }}
179-
run: tinygo test -v -target=wasip2 ./...
179+
run: tinygo test -v -target=wasip2 ./... ./cm/...
180180

181181
- name: Test generated Go with TinyGo >= 0.34.0
182182
if: ${{ matrix.tinygo-version != '0.32.0' && matrix.tinygo-version != '0.33.0' }}

cm/debug_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"reflect"
55
"strings"
66
"unsafe"
7-
8-
"go.bytecodealliance.org/internal/tinyunsafe"
97
)
108

119
func typeName(v any) string {
@@ -33,6 +31,11 @@ func zeroPtr[T any]() *T {
3331
return &zero
3432
}
3533

34+
// TODO: remove this when TinyGo supports unsafe.Offsetof
35+
func offsetOf[Struct any, Field any](s *Struct, f *Field) uintptr {
36+
return uintptr(unsafe.Pointer(f)) - uintptr(unsafe.Pointer(s))
37+
}
38+
3639
// VariantDebug is an interface used in tests to validate layout of variant types.
3740
type VariantDebug interface {
3841
Size() uintptr
@@ -42,7 +45,7 @@ type VariantDebug interface {
4245

4346
func (v variant[Disc, Shape, Align]) Size() uintptr { return unsafe.Sizeof(v) }
4447
func (v variant[Disc, Shape, Align]) DataAlign() uintptr { return unsafe.Alignof(v.data) }
45-
func (v variant[Disc, Shape, Align]) DataOffset() uintptr { return tinyunsafe.OffsetOf(&v, &v.data) }
48+
func (v variant[Disc, Shape, Align]) DataOffset() uintptr { return offsetOf(&v, &v.data) }
4649

4750
// ResultDebug is an interface used in tests to validate layout of result types.
4851
type ResultDebug interface {
@@ -55,4 +58,4 @@ func (r BoolResult) DataOffset() uintptr { return 0 }
5558

5659
func (r result[Shape, OK, Err]) Size() uintptr { return unsafe.Sizeof(r) }
5760
func (r result[Shape, OK, Err]) DataAlign() uintptr { return unsafe.Alignof(r.data) }
58-
func (r result[Shape, OK, Err]) DataOffset() uintptr { return tinyunsafe.OffsetOf(&r, &r.data) }
61+
func (r result[Shape, OK, Err]) DataOffset() uintptr { return offsetOf(&r, &r.data) }

cm/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module go.bytecodealliance.org/cm
2+
3+
go 1.22.0

cm/hostlayout_test.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"runtime"
55
"testing"
66
"unsafe"
7-
8-
"go.bytecodealliance.org/internal/tinyunsafe"
97
)
108

119
func TestFieldAlignment(t *testing.T) {
@@ -18,7 +16,7 @@ func TestFieldAlignment(t *testing.T) {
1816
if got, want := unsafe.Sizeof(v1), uintptr(16); got != want {
1917
t.Errorf("unsafe.Sizeof(v1): %d, expected %d", got, want)
2018
}
21-
if got, want := tinyunsafe.OffsetOf(&v1, &v1.u64), uintptr(8); got != want {
19+
if got, want := offsetOf(&v1, &v1.u64), uintptr(8); got != want {
2220
t.Errorf("unsafe.Offsetof(v1.u64): %d, expected %d", got, want)
2321
}
2422

@@ -36,7 +34,7 @@ func TestFieldAlignment(t *testing.T) {
3634
if got, want := unsafe.Sizeof(v2), uintptr(16); got != want {
3735
t.Errorf("unsafe.Sizeof(v2): %d, expected %d", got, want)
3836
}
39-
if got, want := tinyunsafe.OffsetOf(&v2, &v2.u64), uintptr(8); got != want {
37+
if got, want := offsetOf(&v2, &v2.u64), uintptr(8); got != want {
4038
t.Errorf("unsafe.Offsetof(v2.u64): %d, expected %d", got, want)
4139
}
4240

@@ -49,7 +47,7 @@ func TestFieldAlignment(t *testing.T) {
4947
if got, want := unsafe.Sizeof(v3), uintptr(1); got != want {
5048
t.Errorf("unsafe.Sizeof(v3): %d, expected %d", got, want)
5149
}
52-
if got, want := tinyunsafe.OffsetOf(&v3, &v3.b), uintptr(0); got != want {
50+
if got, want := offsetOf(&v3, &v3.b), uintptr(0); got != want {
5351
t.Errorf("unsafe.Offsetof(v3.b): %d, expected %d", got, want)
5452
}
5553

@@ -62,7 +60,7 @@ func TestFieldAlignment(t *testing.T) {
6260
if got, want := unsafe.Sizeof(v4), uintptr(4); got != want {
6361
t.Errorf("unsafe.Sizeof(v4): %d, expected %d", got, want)
6462
}
65-
if got, want := tinyunsafe.OffsetOf(&v4, &v4.b), uintptr(0); got != want {
63+
if got, want := offsetOf(&v4, &v4.b), uintptr(0); got != want {
6664
t.Errorf("unsafe.Offsetof(v4.b): %d, expected %d", got, want)
6765
}
6866
}

go.work

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ go 1.22.0
22

33
use (
44
.
5+
./cm
56
./tests
67
)

go.work.sum

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
1010
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
1111
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
1212
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
13+
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
1314
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1415
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
1516
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=

internal/tinyunsafe/tinyunsafe.go

-10
This file was deleted.

0 commit comments

Comments
 (0)