Skip to content

Commit be3c8d6

Browse files
committed
all: Go 1.21 support
1 parent c83f712 commit be3c8d6

File tree

12 files changed

+61
-18
lines changed

12 files changed

+61
-18
lines changed

.github/workflows/build-macos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install Go
2828
uses: actions/setup-go@v3
2929
with:
30-
go-version: '1.20'
30+
go-version: '1.21.0-rc.2'
3131
cache: true
3232
- name: Restore LLVM source cache
3333
uses: actions/cache/restore@v3
@@ -126,7 +126,7 @@ jobs:
126126
- name: Install Go
127127
uses: actions/setup-go@v3
128128
with:
129-
go-version: '1.20'
129+
go-version: '1.21.0-rc.2'
130130
cache: true
131131
- name: Build TinyGo
132132
run: go install

.github/workflows/linux.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
# statically linked binary.
1919
runs-on: ubuntu-latest
2020
container:
21-
image: golang:1.20-alpine
21+
image: golang:1.21rc2-alpine
2222
steps:
2323
- name: Install apk dependencies
2424
# tar: needed for actions/cache@v3
@@ -135,7 +135,7 @@ jobs:
135135
- name: Install Go
136136
uses: actions/setup-go@v3
137137
with:
138-
go-version: '1.20'
138+
go-version: '1.21.0-rc.2'
139139
cache: true
140140
- name: Install wasmtime
141141
run: |
@@ -177,7 +177,7 @@ jobs:
177177
- name: Install Go
178178
uses: actions/setup-go@v3
179179
with:
180-
go-version: '1.20'
180+
go-version: '1.21.0-rc.2'
181181
cache: true
182182
- name: Install Node.js
183183
uses: actions/setup-node@v3
@@ -290,7 +290,7 @@ jobs:
290290
- name: Install Go
291291
uses: actions/setup-go@v3
292292
with:
293-
go-version: '1.20'
293+
go-version: '1.21.0-rc.2'
294294
cache: true
295295
- name: Restore LLVM source cache
296296
uses: actions/cache/restore@v3
@@ -407,7 +407,7 @@ jobs:
407407
- name: Install Go
408408
uses: actions/setup-go@v3
409409
with:
410-
go-version: '1.20'
410+
go-version: '1.21.0-rc.2'
411411
cache: true
412412
- name: Restore LLVM source cache
413413
uses: actions/cache/restore@v3

.github/workflows/windows.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install Go
3636
uses: actions/setup-go@v3
3737
with:
38-
go-version: '1.20'
38+
go-version: '1.21.0-rc.2'
3939
cache: true
4040
- name: Restore cached LLVM source
4141
uses: actions/cache/restore@v3
@@ -143,7 +143,7 @@ jobs:
143143
- name: Install Go
144144
uses: actions/setup-go@v3
145145
with:
146-
go-version: '1.20'
146+
go-version: '1.21.0-rc.2'
147147
cache: true
148148
- name: Download TinyGo build
149149
uses: actions/download-artifact@v2
@@ -173,7 +173,7 @@ jobs:
173173
- name: Install Go
174174
uses: actions/setup-go@v3
175175
with:
176-
go-version: '1.20'
176+
go-version: '1.21.0-rc.2'
177177
cache: true
178178
- name: Download TinyGo build
179179
uses: actions/download-artifact@v2
@@ -209,7 +209,7 @@ jobs:
209209
- name: Install Go
210210
uses: actions/setup-go@v3
211211
with:
212-
go-version: '1.20'
212+
go-version: '1.21.0-rc.2'
213213
cache: true
214214
- name: Download TinyGo build
215215
uses: actions/download-artifact@v2

builder/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
2727
if err != nil {
2828
return nil, err
2929
}
30-
if major != 1 || minor < 18 || minor > 20 {
30+
if major != 1 || minor < 18 || minor > 21 {
3131
// Note: when this gets updated, also update the Go compatibility matrix:
3232
// https://github.com/tinygo-org/tinygo-site/blob/dev/content/docs/reference/go-compat-matrix.md
3333
return nil, fmt.Errorf("requires go version 1.18 through 1.20, got go%d.%d", major, minor)

compiler/symbol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
367367
// The list of allowed types is based on this proposal:
368368
// https://github.com/golang/go/issues/59149
369369
func (c *compilerContext) checkWasmImport(f *ssa.Function, pragma string) {
370-
if c.pkg.Path() == "runtime" {
370+
if c.pkg.Path() == "runtime" || c.pkg.Path() == "syscall/js" {
371371
// The runtime is a special case. Allow all kinds of parameters
372372
// (importantly, including pointers).
373373
return

src/internal/bytealg/bytealg.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,13 @@ func IndexRabinKarp(s, substr string) int {
251251
}
252252
return -1
253253
}
254+
255+
// MakeNoZero makes a slice of length and capacity n without zeroing the bytes.
256+
// It is the caller's responsibility to ensure uninitialized bytes
257+
// do not leak to the end user.
258+
func MakeNoZero(n int) []byte {
259+
// Note: this does zero the buffer even though that's not necessary.
260+
// For performance reasons we might want to change this (similar to the
261+
// malloc function implemented in the runtime).
262+
return make([]byte, n)
263+
}

src/runtime/baremetal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func growHeap() bool {
3838

3939
//export malloc
4040
func libc_malloc(size uintptr) unsafe.Pointer {
41+
// Note: this zeroes the returned buffer which is not necessary.
42+
// The same goes for bytealg.MakeNoZero.
4143
return alloc(size, nil)
4244
}
4345

src/runtime/runtime.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,27 @@ func godebug_setUpdate(update func(string, string)) {
100100
// variable changes (for example, via os.Setenv).
101101
godebugUpdate = update
102102
}
103+
104+
//go:linkname godebug_setNewIncNonDefault internal/godebug.setNewIncNonDefault
105+
func godebug_setNewIncNonDefault(newIncNonDefault func(string) func()) {
106+
// Dummy function necessary in Go 1.21.
107+
}
108+
109+
// Write to the given file descriptor.
110+
// This is called from internal/godebug starting with Go 1.21, and only seems to
111+
// be called with the stderr file descriptor.
112+
func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
113+
if fd == 2 { // stderr
114+
// Convert to a string, because we know that p won't change during the
115+
// call to printstring.
116+
// TODO: use unsafe.String instead once we require Go 1.20.
117+
s := _string{
118+
ptr: (*byte)(p),
119+
length: uintptr(n),
120+
}
121+
str := *(*string)(unsafe.Pointer(&s))
122+
printstring(str)
123+
return n
124+
}
125+
return 0
126+
}

src/runtime/runtime_nintendoswitch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func abort() {
105105
}
106106

107107
//export write
108-
func write(fd int32, buf *byte, count int) int {
108+
func libc_write(fd int32, buf *byte, count int) int {
109109
// TODO: Proper handling write
110110
for i := 0; i < count; i++ {
111111
putchar(*buf)

src/runtime/runtime_wasm_js.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func nanosecondsToTicks(ns int64) timeUnit {
4444
// This function is called by the scheduler.
4545
// Schedule a call to runtime.scheduler, do not actually sleep.
4646
//
47-
//export runtime.sleepTicks
47+
//go:wasmimport gojs runtime.sleepTicks
4848
func sleepTicks(d timeUnit)
4949

50-
//export runtime.ticks
50+
//go:wasmimport gojs runtime.ticks
5151
func ticks() timeUnit

0 commit comments

Comments
 (0)