Skip to content

Commit

Permalink
deps: updates TinyGo to v0.28.1 (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt authored Jun 12, 2023
1 parent ae25bc5 commit 27f49b7
Show file tree
Hide file tree
Showing 31 changed files with 84 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
go-version: # Note: Go only supports 2 versions: https://go.dev/doc/devel/release#policy
- "1.20"
tinygo-version: # Note: TinyGo only supports latest: https://github.com/tinygo-org/tinygo/releases
- "0.27.0" # Latest
- "0.28.1" # Latest

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testdata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
go-version: # Note: Go only supports 2 versions: https://go.dev/doc/devel/release#policy
- "1.20"
tinygo-version: # Note: TinyGo only supports latest: https://github.com/tinygo-org/tinygo/releases
- "0.27.0" # Latest
- "0.28.1" # Latest

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func handleRequest(req api.Request, resp api.Response) (next bool, reqCtx uint32
}
```

If you make changes, you can rebuild it like so:
If you make changes, you can rebuild this with TinyGo v0.28 or higher like so:
```sh
tinygo build -o examples/router/main.wasm -scheduler=none --no-debug -target=wasi examples/router/main.go
```
Expand Down
Binary file modified examples/router/main.wasm
Binary file not shown.
Binary file modified examples/wasi/main.wasm
Binary file not shown.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
module github.com/http-wasm/http-wasm-guest-tinygo

// TinyGo 0.27 doesn't fully support Go 1.20, but it supports what we need.
// Particularly, unsafe.SliceData, unsafe.StringData were added to TinyGo 0.27.
// See https://github.com/tinygo-org/tinygo/commit/c43958972c3ffcd51e65414a346e53779edb9f97
go 1.20
8 changes: 4 additions & 4 deletions handler/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func (b wasmBody) Read(bytes []byte) (size uint32, eof bool) {
return // invalid, but prevent crashing.
}

size, eof = read(b, uintptr(ptr), limit)
size, eof = read(b, ptr, limit)
runtime.KeepAlive(bytes) // keep bytes alive until ptr is no longer needed.
return
}

func read(b wasmBody, ptr uintptr, limit imports.BufLimit) (size uint32, eof bool) {
func read(b wasmBody, ptr uint32, limit imports.BufLimit) (size uint32, eof bool) {
eofLen := imports.ReadBody(imports.BodyKind(b), ptr, limit)
eof = (eofLen >> 32) == 1
size = uint32(eofLen)
Expand All @@ -64,7 +64,7 @@ func (b wasmBody) Write(bytes []byte) {
return
}

imports.WriteBody(imports.BodyKind(b), uintptr(ptr), size)
imports.WriteBody(imports.BodyKind(b), ptr, size)
runtime.KeepAlive(bytes) // keep bytes alive until ptr is no longer needed.
}

Expand All @@ -75,6 +75,6 @@ func (b wasmBody) WriteString(s string) {
return
}

imports.WriteBody(imports.BodyKind(b), uintptr(ptr), size)
imports.WriteBody(imports.BodyKind(b), ptr, size)
runtime.KeepAlive(s) // keep s alive until ptr is no longer needed.
}
16 changes: 8 additions & 8 deletions handler/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (w wasmHeader) Names() (names []string) {
}
// Otherwise, we have to allocate a new buffer for the large entry.
buf := make([]byte, size)
ptr := unsafe.Pointer(unsafe.SliceData(buf))
_ = imports.GetHeaderNames(imports.HeaderKind(w), uintptr(ptr), size)
ptr := uint32(uintptr(unsafe.Pointer(unsafe.SliceData(buf))))
_ = imports.GetHeaderNames(imports.HeaderKind(w), ptr, size)
names = mem.GetNULTerminated(buf)
runtime.KeepAlive(buf) // keep buf alive until ptr is no longer needed.
return
Expand All @@ -51,7 +51,7 @@ func (w wasmHeader) Get(name string) (value string, ok bool) {
// GetAll implements the same method as documented on api.Request.
func (w wasmHeader) GetAll(name string) (names []string) {
namePtr, nameSize := mem.StringToPtr(name)
countLen := imports.GetHeaderValues(imports.HeaderKind(w), uintptr(namePtr), nameSize, mem.ReadBufPtr, mem.ReadBufLimit)
countLen := imports.GetHeaderValues(imports.HeaderKind(w), namePtr, nameSize, mem.ReadBufPtr, mem.ReadBufLimit)
runtime.KeepAlive(name) // keep name alive until ptr is no longer needed.
if countLen == 0 {
return
Expand All @@ -66,8 +66,8 @@ func (w wasmHeader) GetAll(name string) (names []string) {
}
// Otherwise, we have to allocate a new buffer for the large entry.
buf := make([]byte, size)
ptr := unsafe.Pointer(unsafe.SliceData(buf))
_ = imports.GetHeaderValues(imports.HeaderKind(w), uintptr(namePtr), nameSize, uintptr(ptr), size)
ptr := uint32(uintptr(unsafe.Pointer(unsafe.SliceData(buf))))
_ = imports.GetHeaderValues(imports.HeaderKind(w), namePtr, nameSize, ptr, size)
names = mem.GetNULTerminated(buf)
runtime.KeepAlive(name) // keep name alive until ptr is no longer needed.
runtime.KeepAlive(buf) // keep buf alive until ptr is no longer needed.
Expand All @@ -78,7 +78,7 @@ func (w wasmHeader) GetAll(name string) (names []string) {
func (w wasmHeader) Set(name, value string) {
namePtr, nameSize := mem.StringToPtr(name)
valuePtr, valueSize := mem.StringToPtr(value)
imports.SetHeaderValue(imports.HeaderKind(w), uintptr(namePtr), nameSize, uintptr(valuePtr), valueSize)
imports.SetHeaderValue(imports.HeaderKind(w), namePtr, nameSize, valuePtr, valueSize)
runtime.KeepAlive(name) // keep name alive until ptr is no longer needed.
runtime.KeepAlive(value) // keep value alive until ptr is no longer needed.
}
Expand All @@ -87,14 +87,14 @@ func (w wasmHeader) Set(name, value string) {
func (w wasmHeader) Add(name, value string) {
namePtr, nameSize := mem.StringToPtr(name)
valuePtr, valueSize := mem.StringToPtr(value)
imports.AddHeaderValue(imports.HeaderKind(w), uintptr(namePtr), nameSize, uintptr(valuePtr), valueSize)
imports.AddHeaderValue(imports.HeaderKind(w), namePtr, nameSize, valuePtr, valueSize)
runtime.KeepAlive(name) // keep name alive until ptr is no longer needed.
runtime.KeepAlive(value) // keep value alive until ptr is no longer needed.
}

// Remove implements the same method as documented on api.Request.
func (w wasmHeader) Remove(name string) {
namePtr, nameSize := mem.StringToPtr(name)
imports.RemoveHeader(imports.HeaderKind(w), uintptr(namePtr), nameSize)
imports.RemoveHeader(imports.HeaderKind(w), namePtr, nameSize)
runtime.KeepAlive(name) // keep name alive until ptr is no longer needed.
}
2 changes: 1 addition & 1 deletion handler/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ func (wasmHost) Log(level api.LogLevel, message string) {
return // don't incur host call overhead
}
ptr, size := mem.StringToPtr(message)
imports.Log(level, uintptr(ptr), size)
imports.Log(level, ptr, size)
runtime.KeepAlive(message) // keep message alive until ptr is no longer needed.
}
28 changes: 14 additions & 14 deletions handler/internal/imports/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,63 +111,63 @@ func EnableFeatures(features api.Features) api.Features {
return enableFeatures(features)
}

func GetConfig(ptr uintptr, limit BufLimit) (len uint32) {
func GetConfig(ptr uint32, limit BufLimit) (len uint32) {
return getConfig(ptr, limit)
}

func LogEnabled(level api.LogLevel) uint32 {
return logEnabled(level)
}

func Log(level api.LogLevel, ptr uintptr, size uint32) {
func Log(level api.LogLevel, ptr, size uint32) {
log(level, ptr, size)
}

func GetMethod(ptr uintptr, limit BufLimit) (len uint32) {
func GetMethod(ptr uint32, limit BufLimit) (len uint32) {
return getMethod(ptr, limit)
}

func SetMethod(ptr uintptr, size uint32) {
func SetMethod(ptr, size uint32) {
setMethod(ptr, size)
}

func GetURI(ptr uintptr, limit BufLimit) (len uint32) {
func GetURI(ptr uint32, limit BufLimit) (len uint32) {
return getURI(ptr, limit)
}

func SetURI(ptr uintptr, size uint32) {
func SetURI(ptr, size uint32) {
setURI(ptr, size)
}

func GetProtocolVersion(ptr uintptr, limit BufLimit) (len uint32) {
func GetProtocolVersion(ptr uint32, limit BufLimit) (len uint32) {
return getProtocolVersion(ptr, limit)
}

func GetHeaderNames(kind HeaderKind, ptr uintptr, limit BufLimit) CountLen {
func GetHeaderNames(kind HeaderKind, ptr uint32, limit BufLimit) CountLen {
return getHeaderNames(kind, ptr, limit)
}

func GetHeaderValues(kind HeaderKind, namePtr uintptr, nameSize uint32, bufPtr uintptr, bufLimit BufLimit) CountLen {
func GetHeaderValues(kind HeaderKind, namePtr, nameSize uint32, bufPtr uint32, bufLimit BufLimit) CountLen {
return getHeaderValues(kind, namePtr, nameSize, bufPtr, bufLimit)
}

func SetHeaderValue(kind HeaderKind, namePtr uintptr, nameSize uint32, valuePtr uintptr, valueSize uint32) {
func SetHeaderValue(kind HeaderKind, namePtr, nameSize uint32, valuePtr uint32, valueSize uint32) {
setHeaderValue(kind, namePtr, nameSize, valuePtr, valueSize)
}

func AddHeaderValue(kind HeaderKind, namePtr uintptr, nameSize uint32, valuePtr uintptr, valueSize uint32) {
func AddHeaderValue(kind HeaderKind, namePtr, nameSize uint32, valuePtr uint32, valueSize uint32) {
addHeaderValue(kind, namePtr, nameSize, valuePtr, valueSize)
}

func RemoveHeader(kind HeaderKind, namePtr uintptr, nameSize uint32) {
func RemoveHeader(kind HeaderKind, namePtr, nameSize uint32) {
removeHeader(kind, namePtr, nameSize)
}

func ReadBody(kind BodyKind, bufPtr uintptr, bufLimit BufLimit) EOFLen {
func ReadBody(kind BodyKind, bufPtr uint32, bufLimit BufLimit) EOFLen {
return readBody(kind, bufPtr, bufLimit)
}

func WriteBody(kind BodyKind, bufPtr uintptr, bufSize uint32) {
func WriteBody(kind BodyKind, bufPtr uint32, bufSize uint32) {
writeBody(kind, bufPtr, bufSize)
}

Expand Down
82 changes: 32 additions & 50 deletions handler/internal/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,56 @@ package imports

import "github.com/http-wasm/http-wasm-guest-tinygo/handler/api"

//go:wasm-module http_handler
//go:export enable_features
//go:wasmimport http_handler enable_features
func enableFeatures(features api.Features) api.Features

//go:wasm-module http_handler
//go:export get_config
func getConfig(ptr uintptr, limit BufLimit) (len uint32)
//go:wasmimport http_handler get_config
func getConfig(ptr uint32, limit BufLimit) (len uint32)

//go:wasm-module http_handler
//go:export log
func log(level api.LogLevel, ptr uintptr, size uint32)
//go:wasmimport http_handler log
func log(level api.LogLevel, ptr, size uint32)

//go:wasm-module http_handler
//go:export log_enabled
//go:wasmimport http_handler log_enabled
func logEnabled(level api.LogLevel) uint32

//go:wasm-module http_handler
//go:export get_method
func getMethod(ptr uintptr, limit BufLimit) (len uint32)
//go:wasmimport http_handler get_method
func getMethod(ptr uint32, limit BufLimit) (len uint32)

//go:wasm-module http_handler
//go:export set_method
func setMethod(ptr uintptr, size uint32)
//go:wasmimport http_handler set_method
func setMethod(ptr, size uint32)

//go:wasm-module http_handler
//go:export get_uri
func getURI(ptr uintptr, limit BufLimit) (len uint32)
//go:wasmimport http_handler get_uri
func getURI(ptr uint32, limit BufLimit) (len uint32)

//go:wasm-module http_handler
//go:export set_uri
func setURI(ptr uintptr, size uint32)
//go:wasmimport http_handler set_uri
func setURI(ptr, size uint32)

//go:wasm-module http_handler
//go:export get_protocol_version
func getProtocolVersion(ptr uintptr, limit BufLimit) (len uint32)
//go:wasmimport http_handler get_protocol_version
func getProtocolVersion(ptr uint32, limit BufLimit) (len uint32)

//go:wasm-module http_handler
//go:export get_header_names
func getHeaderNames(kind HeaderKind, ptr uintptr, limit BufLimit) (countLen CountLen)
//go:wasmimport http_handler get_header_names
func getHeaderNames(kind HeaderKind, ptr uint32, limit BufLimit) (countLen CountLen)

//go:wasm-module http_handler
//go:export get_header_values
func getHeaderValues(kind HeaderKind, namePtr uintptr, nameSize uint32, bufPtr uintptr, buflimit BufLimit) (countLen CountLen)
//go:wasmimport http_handler get_header_values
func getHeaderValues(kind HeaderKind, namePtr, nameSize uint32, bufPtr uint32, buflimit BufLimit) (countLen CountLen)

//go:wasm-module http_handler
//go:export set_header_value
func setHeaderValue(kind HeaderKind, namePtr uintptr, nameSize uint32, valuePtr uintptr, valueLen uint32)
//go:wasmimport http_handler set_header_value
func setHeaderValue(kind HeaderKind, namePtr, nameSize uint32, valuePtr, valueLen uint32)

//go:wasm-module http_handler
//go:export add_header_value
func addHeaderValue(kind HeaderKind, namePtr uintptr, nameSize uint32, valuePtr uintptr, valueLen uint32)
//go:wasmimport http_handler add_header_value
func addHeaderValue(kind HeaderKind, namePtr, nameSize uint32, valuePtr, valueLen uint32)

//go:wasm-module http_handler
//go:export remove_header
func removeHeader(kind HeaderKind, namePtr uintptr, nameSize uint32)
//go:wasmimport http_handler remove_header
func removeHeader(kind HeaderKind, namePtr, nameSize uint32)

//go:wasm-module http_handler
//go:export read_body
func readBody(kind BodyKind, bufPtr uintptr, buflimit BufLimit) (eofLen EOFLen)
//go:wasmimport http_handler read_body
func readBody(kind BodyKind, bufPtr uint32, buflimit BufLimit) (eofLen EOFLen)

//go:wasm-module http_handler
//go:export write_body
func writeBody(kind BodyKind, bufPtr uintptr, bufLen uint32)
//go:wasmimport http_handler write_body
func writeBody(kind BodyKind, bufPtr uint32, bufLen uint32)

//go:wasm-module http_handler
//go:export get_status_code
//go:wasmimport http_handler get_status_code
func getStatusCode() uint32

//go:wasm-module http_handler
//go:export set_status_code
//go:wasmimport http_handler set_status_code
func setStatusCode(statusCode uint32)
28 changes: 14 additions & 14 deletions handler/internal/imports/imports_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,65 @@ func enableFeatures(features api.Features) api.Features {
}

// getConfig is stubbed for compilation outside TinyGo.
func getConfig(ptr uintptr, limit BufLimit) (len uint32) {
func getConfig(ptr uint32, limit BufLimit) (len uint32) {
return 0
}

// log is stubbed for compilation outside TinyGo.
func log(level api.LogLevel, ptr uintptr, size uint32) {}
func log(level api.LogLevel, ptr, size uint32) {}

// logEnabled is stubbed for compilation outside TinyGo.
func logEnabled(level api.LogLevel) uint32 { return 0 }

// getMethod is stubbed for compilation outside TinyGo.
func getMethod(ptr uintptr, limit BufLimit) (len uint32) {
func getMethod(ptr uint32, limit BufLimit) (len uint32) {
return 0
}

// setMethod is stubbed for compilation outside TinyGo.
func setMethod(ptr uintptr, size uint32) {}
func setMethod(ptr, size uint32) {}

// getURI is stubbed for compilation outside TinyGo.
func getURI(ptr uintptr, limit BufLimit) (len uint32) {
func getURI(ptr uint32, limit BufLimit) (len uint32) {
return 0
}

// setURI is stubbed for compilation outside TinyGo.
func setURI(ptr uintptr, size uint32) {}
func setURI(ptr, size uint32) {}

// getProtocolVersion is stubbed for compilation outside TinyGo.
func getProtocolVersion(ptr uintptr, limit BufLimit) (len uint32) {
func getProtocolVersion(ptr uint32, limit BufLimit) (len uint32) {
return 0
}

// getHeaderNames is stubbed for compilation outside TinyGo.
func getHeaderNames(kind HeaderKind, ptr uintptr, limit BufLimit) (countLen CountLen) {
func getHeaderNames(kind HeaderKind, ptr uint32, limit BufLimit) (countLen CountLen) {
return 0
}

// getHeaderValues is stubbed for compilation outside TinyGo.
func getHeaderValues(kind HeaderKind, namePtr uintptr, nameSize uint32, bufPtr uintptr, bufLimit BufLimit) (countLen CountLen) {
func getHeaderValues(kind HeaderKind, namePtr, nameSize uint32, bufPtr uint32, bufLimit BufLimit) (countLen CountLen) {
return 0
}

// setHeaderValue is stubbed for compilation outside TinyGo.
func setHeaderValue(kind HeaderKind, namePtr uintptr, nameSize uint32, valuePtr uintptr, valueLen uint32) {
func setHeaderValue(kind HeaderKind, namePtr, nameSize uint32, valuePtr, valueLen uint32) {
}

// addHeaderValue is stubbed for compilation outside TinyGo.
func addHeaderValue(kind HeaderKind, namePtr uintptr, nameSize uint32, valuePtr uintptr, valueLen uint32) {
func addHeaderValue(kind HeaderKind, namePtr, nameSize uint32, valuePtr, valueLen uint32) {
}

// removeHeader is stubbed for compilation outside TinyGo.
func removeHeader(kind HeaderKind, namePtr uintptr, nameSize uint32) {}
func removeHeader(kind HeaderKind, namePtr, nameSize uint32) {}

// readBody is stubbed for compilation outside TinyGo.
func readBody(kind BodyKind, bufPtr uintptr, bufLimit BufLimit) (eofLen EOFLen) {
func readBody(kind BodyKind, bufPtr uint32, bufLimit BufLimit) (eofLen EOFLen) {
return 0
}

// writeBody is stubbed for compilation outside TinyGo.
func writeBody(kind BodyKind, bufPtr uintptr, bufLen uint32) {}
func writeBody(kind BodyKind, bufPtr uint32, bufLen uint32) {}

// getStatusCode is stubbed for compilation outside TinyGo.
func getStatusCode() uint32 {
Expand Down
Loading

0 comments on commit 27f49b7

Please sign in to comment.