Skip to content

Commit

Permalink
Use wasilibs nottinygc (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Feb 3, 2023
1 parent 21ebf45 commit 13492e3
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 223 deletions.
20 changes: 0 additions & 20 deletions buildtools/bdwgc/Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions buildtools/mimalloc/Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/wasilibs/go-aho-corasick v0.2.0
github.com/wasilibs/go-libinjection v0.1.0
github.com/wasilibs/go-re2 v0.1.0
github.com/wasilibs/nottinygc v0.0.0-20230202022930-bb230a97db8e
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ github.com/wasilibs/go-libinjection v0.1.0 h1:WivsHc8c0cNWETEVhG0NpCezxvCn9zlVli
github.com/wasilibs/go-libinjection v0.1.0/go.mod h1:yRoVK5Ks0kH65fJB1uzppuEn77pJmP8hagoAdPcgbtI=
github.com/wasilibs/go-re2 v0.1.0 h1:+pcjlvge6E9WWU4eaMlULRikEUkhPDXSFfCF5p7htMI=
github.com/wasilibs/go-re2 v0.1.0/go.mod h1:F91Yac+zPNDFrrd8fl4mSd7+TTu2tYiX56BEIEPQl2M=
github.com/wasilibs/nottinygc v0.0.0-20230202022930-bb230a97db8e h1:xzrL/Fd514ijzrySqTQgCLyGVOWbQBs7qhwLqSrR/2s=
github.com/wasilibs/nottinygc v0.0.0-20230202022930-bb230a97db8e/go.mod h1:oDcIotskuYNMpqMF23l7Z8uzD4TC0WXHK8jetlB3HIo=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
Expand Down
12 changes: 9 additions & 3 deletions init_tinygo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

package main

import _ "github.com/corazawaf/coraza-proxy-wasm/internal/gc"
import _ "github.com/wasilibs/nottinygc"

// #cgo LDFLAGS: lib/libmimalloc.a lib/libgc.a
import "C"
// Compiled by nottinygc for delayed free but Envoy doesn't stub it yet,
// luckily nottinygc doesn't actually call the function, so it's fine to
// stub it out.

//export sched_yield
func sched_yield() int32 {
return 0
}
6 changes: 0 additions & 6 deletions internal/gc/doc.go

This file was deleted.

74 changes: 0 additions & 74 deletions internal/gc/gc_conservative.go

This file was deleted.

19 changes: 0 additions & 19 deletions internal/gc/mem.go

This file was deleted.

56 changes: 0 additions & 56 deletions internal/gc/memstats.go

This file was deleted.

Binary file removed lib/libgc.a
Binary file not shown.
Binary file removed lib/libinjection.a
Binary file not shown.
Binary file removed lib/libmimalloc.a
Binary file not shown.
Binary file removed lib/libre2.a
Binary file not shown.
22 changes: 2 additions & 20 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func Build() error {
return err
}

var buildTags []string
buildTags := []string{"custommalloc"}
if os.Getenv("TIMING") == "true" {
buildTags = append(buildTags, "timing", "proxywasm_timing")
}
Expand Down Expand Up @@ -193,32 +193,14 @@ func Build() error {
script := fmt.Sprintf(`
cd /src && \
tinygo build -gc=custom -opt=2 -o %s -scheduler=none -target=wasi %s`, filepath.Join("build", "mainraw.wasm"), buildTagArg)
if err := sh.RunV("docker", "run", "--pull=always", "--rm", "-v", fmt.Sprintf("%s:/src", wd), "ghcr.io/corazawaf/coraza-proxy-wasm/buildtools-tinygo:sha-63723e9",
if err := sh.RunV("docker", "run", "--pull=always", "--rm", "-v", fmt.Sprintf("%s:/src", wd), "ghcr.io/corazawaf/coraza-proxy-wasm/buildtools-tinygo:sha-96443bb",
"bash", "-c", script); err != nil {
return err
}

return patchWasm(filepath.Join("build", "mainraw.wasm"), filepath.Join("build", "main.wasm"), initialPages)
}

// UpdateLibs updates the C++ filter dependencies.
func UpdateLibs() error {
libs := []string{"bdwgc", "mimalloc"}
for _, lib := range libs {
if err := sh.RunV("docker", "build", "-t", "ghcr.io/corazawaf/coraza-proxy-wasm/buildtools-"+lib, filepath.Join("buildtools", lib)); err != nil {
return err
}
wd, err := os.Getwd()
if err != nil {
return err
}
if err := sh.RunV("docker", "run", "-it", "--rm", "-v", fmt.Sprintf("%s:/out", filepath.Join(wd, "lib")), "ghcr.io/corazawaf/coraza-proxy-wasm/buildtools-"+lib); err != nil {
return err
}
}
return nil
}

// E2e runs e2e tests with a built plugin against the example deployment. Requires docker-compose.
func E2e() error {
if err := sh.RunV("docker-compose", "--file", "e2e/docker-compose.yml", "build", "--pull"); err != nil {
Expand Down
15 changes: 6 additions & 9 deletions wasmplugin/memstats_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
package wasmplugin

import (
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
"runtime"

"github.com/corazawaf/coraza-proxy-wasm/internal/gc"
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
)

func logMemStats() {
ms := gc.MemStats{}
gc.ReadMemStats(&ms)
ms := runtime.MemStats{}
runtime.ReadMemStats(&ms)
proxywasm.LogDebugf(
"Sys: %d, HeapSys: %d, HeapAlloc: %d, HeapIdle: %d, HeapReleased: %d, TotalAlloc: %d, NumGC: %d, BytesSinceGC: %d",
"Sys: %d, HeapSys: %d, HeapIdle: %d, HeapReleased: %d, TotalAlloc: %d",
ms.Sys,
ms.HeapSys,
ms.HeapAlloc,
ms.HeapIdle,
ms.HeapReleased,
ms.TotalAlloc,
ms.NumGC,
ms.BytesSinceGC)
ms.TotalAlloc)
}

0 comments on commit 13492e3

Please sign in to comment.