Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasmtime v29 #7333

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 18 additions & 3 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
variant_name: opa_no_ci
arch: arm64
- os: windows
run: ubuntu-22.04
targets: ci-go-ci-build-windows
run: windows-latest
targets: ci-build-windows
arch: amd64
- os: darwin
run: macos-13
Expand All @@ -75,7 +75,22 @@ jobs:
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ steps.go_version.outputs.go_version }}
if: matrix.os == 'darwin'
if: matrix.os != 'linux'

- name: Ready msys2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: git mingw-w64-x86_64-toolchain
path-type: inherit
if: matrix.os == 'windows'

# - run: C:/msys64/usr/bin/pacman.exe -S --needed mingw-w64-x86_64-gcc --noconfirm
# if: matrix.os == 'windows'
# - shell: pwsh
# run: echo "C:\msys64\mingw64\bin" >> $Env:GITHUB_PATH
# if: matrix.os == 'windows'

- name: Download generated artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
Expand Down
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TELEMETRY_URL ?= #Default empty

BUILD_HOSTNAME := $(shell ./build/get-build-hostname.sh)

RELEASE_BUILD_IMAGE := golang:$(GOVERSION)-bullseye
RELEASE_BUILD_IMAGE := golang:$(GOVERSION)-bookworm

RELEASE_DIR ?= _release/$(VERSION)

Expand Down Expand Up @@ -97,7 +97,7 @@ release-dir:

.PHONY: generate
generate: wasm-lib-build
$(GO) generate
#$(GO) generate # TODO(sr): ifeq this

.PHONY: build
build: go-build
Expand Down Expand Up @@ -204,9 +204,9 @@ wasm-test: wasm-lib-test wasm-rego-test
.PHONY: wasm-lib-build
wasm-lib-build:
ifeq ($(DOCKER_RUNNING), 1)
@$(MAKE) -C wasm ensure-builder build
cp wasm/_obj/opa.wasm internal/compiler/wasm/opa/opa.wasm
cp wasm/_obj/callgraph.csv internal/compiler/wasm/opa/callgraph.csv
# @$(MAKE) -C wasm ensure-builder build
# cp wasm/_obj/opa.wasm internal/compiler/wasm/opa/opa.wasm
# cp wasm/_obj/callgraph.csv internal/compiler/wasm/opa/callgraph.csv
else
@echo "Docker not installed or not running. Skipping OPA-WASM library build."
endif
Expand Down Expand Up @@ -301,7 +301,6 @@ ci-build-darwin-arm64-static: ensure-release-dir
# that can install the `gcc-mingw-w64-x86-64` package via apt-get.
.PHONY: ci-build-windows
ci-build-windows: ensure-release-dir
build/ensure-windows-toolchain.sh
@$(MAKE) build GOOS=windows CC=x86_64-w64-mingw32-gcc
mv opa_windows_$(GOARCH) $(RELEASE_DIR)/opa_windows_$(GOARCH).exe
cd $(RELEASE_DIR)/ && shasum -a 256 opa_windows_$(GOARCH).exe > opa_windows_$(GOARCH).exe.sha256
Expand Down
4 changes: 3 additions & 1 deletion build/ensure-windows-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CC=x86_64-w64-mingw32-gcc
PKG=gcc-mingw-w64-x86-64

type -f ${CC} 2>/dev/null && exit 0
echo "deb https://deb.debian.org/debian experimental main" >> /etc/apt/sources.list

apt-get update && \
apt-get install --no-install-recommends -y ${PKG}
apt-get install --no-install-recommends -y ${PKG} && \
apt-get install --no-install-recommends -y binutils-mingw-w64-x86-64
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/OneOfOne/xxhash v1.2.8
github.com/agnivade/levenshtein v1.2.1
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2
github.com/bytecodealliance/wasmtime-go/v29 v29.0.0
github.com/containerd/containerd v1.7.25
github.com/containerd/errdefs v1.0.0
github.com/dgraph-io/badger/v4 v4.5.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 h1:3uZCA/BLTIu+DqCfguByNMJa2HVHpXvjfy0Dy7g6fuA=
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2/go.mod h1:RnUjnIXxEJcL6BgCvNyzCCRzZcxCgsZCi+RNlvYor5Q=
github.com/bytecodealliance/wasmtime-go/v29 v29.0.0 h1:HEm2yVK6S3JMx9rTm0J0NiaLs5Y0K9si6C2ujFgx+q8=
github.com/bytecodealliance/wasmtime-go/v29 v29.0.0/go.mod h1:dGQy36rxkAWc+MxjtIWGRFSzQ89aEhQvOFGtkJ9eBJw=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
2 changes: 1 addition & 1 deletion internal/wasm/sdk/internal/wasm/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strconv"
"time"

wasmtime "github.com/bytecodealliance/wasmtime-go/v3"
wasmtime "github.com/bytecodealliance/wasmtime-go/v29"

"github.com/open-policy-agent/opa/v1/ast"
"github.com/open-policy-agent/opa/v1/metrics"
Expand Down
2 changes: 1 addition & 1 deletion internal/wasm/sdk/internal/wasm/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"context"
"sync"

wasmtime "github.com/bytecodealliance/wasmtime-go/v3"
wasmtime "github.com/bytecodealliance/wasmtime-go/v29"

"github.com/open-policy-agent/opa/internal/wasm/sdk/opa/errors"
"github.com/open-policy-agent/opa/internal/wasm/util"
Expand Down
13 changes: 9 additions & 4 deletions internal/wasm/sdk/internal/wasm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"time"

wasmtime "github.com/bytecodealliance/wasmtime-go/v3"
wasmtime "github.com/bytecodealliance/wasmtime-go/v29"

sdk_errors "github.com/open-policy-agent/opa/internal/wasm/sdk/opa/errors"
"github.com/open-policy-agent/opa/internal/wasm/util"
Expand Down Expand Up @@ -79,7 +79,12 @@ func newVM(opts vmOpts, engine *wasmtime.Engine) (*VM, error) {
v := &VM{engine: engine}
store := wasmtime.NewStore(engine)
store.SetEpochDeadline(1)
memorytype := wasmtime.NewMemoryType(opts.memoryMin, true, opts.memoryMax)
memorytype := wasmtime.NewMemoryType(
opts.memoryMin,
true,
opts.memoryMax,
false,
)
memory, err := wasmtime.NewMemory(store, memorytype)
if err != nil {
return nil, err
Expand All @@ -94,11 +99,11 @@ func newVM(opts vmOpts, engine *wasmtime.Engine) (*VM, error) {
v.dispatcher = newBuiltinDispatcher()
externs := opaFunctions(v.dispatcher, store)
for name, extern := range externs {
if err := linker.Define("env", name, extern); err != nil {
if err := linker.Define(store, "env", name, extern); err != nil {
return nil, fmt.Errorf("linker: env.%s: %w", name, err)
}
}
if err := linker.Define("env", "memory", memory); err != nil {
if err := linker.Define(store, "env", "memory", memory); err != nil {
return nil, fmt.Errorf("linker: env.memory: %w", err)
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading