Repository: tetratelabs/wazero
Pull request #465 (2022-04-15 00:38:13)

Makes wazero complete dependency free
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>


Patch:
diff --git a/Makefile b/Makefile
index a9c96359..394e9973 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,7 @@ build.spectest: # Note: wabt by default uses >1.0 features, so wast2json flags m
 .PHONY: test
 test:
 	@go test ./... -timeout 120s
+	@cd ./internal/integration_test && go test ./... -timeout 120s
 
 golangci_lint_path := $(shell go env GOPATH)/bin/golangci-lint
 
diff --git a/go.mod b/go.mod
index f1eb04cf..4ccd9deb 100644
--- a/go.mod
+++ b/go.mod
@@ -2,6 +2,3 @@ module github.com/tetratelabs/wazero
 
 // This should be the minimum supported Go version per https://go.dev/doc/devel/release (1 version behind latest)
 go 1.17
-
-// Test-only dependency.
-require github.com/twitchyliquid64/golang-asm v0.15.1
diff --git a/go.sum b/go.sum
index 832898f2..e69de29b 100644
--- a/go.sum
+++ b/go.sum
@@ -1,2 +0,0 @@
-github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
-github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
diff --git a/internal/asm/amd64_debug/debug_assembler.go b/internal/integration_test/asm/amd64_debug/debug_assembler.go
similarity index 99%
rename from internal/asm/amd64_debug/debug_assembler.go
rename to internal/integration_test/asm/amd64_debug/debug_assembler.go
index c90787ff..03771751 100644
--- a/internal/asm/amd64_debug/debug_assembler.go
+++ b/internal/integration_test/asm/amd64_debug/debug_assembler.go
@@ -9,7 +9,7 @@ import (
 
 	"github.com/tetratelabs/wazero/internal/asm"
 	asm_amd64 "github.com/tetratelabs/wazero/internal/asm/amd64"
-	"github.com/tetratelabs/wazero/internal/asm/golang_asm"
+	"github.com/tetratelabs/wazero/internal/integration_test/asm/golang_asm"
 )
 
 // NewDebugAssembler can be used for ensuring that our assembler produces exactly the same binary as Go.
diff --git a/internal/asm/amd64_debug/golang_asm.go b/internal/integration_test/asm/amd64_debug/golang_asm.go
similarity index 99%
rename from internal/asm/amd64_debug/golang_asm.go
rename to internal/integration_test/asm/amd64_debug/golang_asm.go
index 99e9461d..0d0efb45 100644
--- a/internal/asm/amd64_debug/golang_asm.go
+++ b/internal/integration_test/asm/amd64_debug/golang_asm.go
@@ -9,7 +9,7 @@ import (
 
 	"github.com/tetratelabs/wazero/internal/asm"
 	asm_amd64 "github.com/tetratelabs/wazero/internal/asm/amd64"
-	"github.com/tetratelabs/wazero/internal/asm/golang_asm"
+	"github.com/tetratelabs/wazero/internal/integration_test/asm/golang_asm"
 )
 
 // assemblerGoAsmImpl implements asm_amd64.Assembler for golang-asm library.
diff --git a/internal/asm/amd64_debug/impl_test.go b/internal/integration_test/asm/amd64_debug/impl_test.go
similarity index 100%
rename from internal/asm/amd64_debug/impl_test.go
rename to internal/integration_test/asm/amd64_debug/impl_test.go
diff --git a/internal/asm/arm64_debug/debug_assembler.go b/internal/integration_test/asm/arm64_debug/debug_assembler.go
similarity index 99%
rename from internal/asm/arm64_debug/debug_assembler.go
rename to internal/integration_test/asm/arm64_debug/debug_assembler.go
index ab2768c1..2ac8744b 100644
--- a/internal/asm/arm64_debug/debug_assembler.go
+++ b/internal/integration_test/asm/arm64_debug/debug_assembler.go
@@ -7,7 +7,7 @@ import (
 
 	"github.com/tetratelabs/wazero/internal/asm"
 	asm_arm64 "github.com/tetratelabs/wazero/internal/asm/arm64"
-	"github.com/tetratelabs/wazero/internal/asm/golang_asm"
+	"github.com/tetratelabs/wazero/internal/integration_test/asm/golang_asm"
 )
 
 // NewDebugAssembler can be used for ensuring that our assembler produces exactly the same binary as Go.
diff --git a/internal/asm/arm64_debug/golang_asm.go b/internal/integration_test/asm/arm64_debug/golang_asm.go
similarity index 99%
rename from internal/asm/arm64_debug/golang_asm.go
rename to internal/integration_test/asm/arm64_debug/golang_asm.go
index 187cbbe7..0d9c2c99 100644
--- a/internal/asm/arm64_debug/golang_asm.go
+++ b/internal/integration_test/asm/arm64_debug/golang_asm.go
@@ -9,7 +9,7 @@ import (
 
 	"github.com/tetratelabs/wazero/internal/asm"
 	asm_arm64 "github.com/tetratelabs/wazero/internal/asm/arm64"
-	"github.com/tetratelabs/wazero/internal/asm/golang_asm"
+	"github.com/tetratelabs/wazero/internal/integration_test/asm/golang_asm"
 )
 
 // TODO: this comment seems wrong


Test patch:
diff --git a/internal/asm/arm64_debug/impl_test.go b/internal/integration_test/asm/arm64_debug/impl_test.go
similarity index 100%
rename from internal/asm/arm64_debug/impl_test.go
rename to internal/integration_test/asm/arm64_debug/impl_test.go
diff --git a/internal/asm/golang_asm/golang_asm.go b/internal/integration_test/asm/golang_asm/golang_asm.go
similarity index 100%
rename from internal/asm/golang_asm/golang_asm.go
rename to internal/integration_test/asm/golang_asm/golang_asm.go
diff --git a/internal/integration_test/go.mod b/internal/integration_test/go.mod
new file mode 100644
index 00000000..985f6a72
--- /dev/null
+++ b/internal/integration_test/go.mod
@@ -0,0 +1,10 @@
+module github.com/tetratelabs/wazero/internal/integration_test
+
+go 1.17
+
+require (
+	github.com/tetratelabs/wazero v0.0.0
+	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
+)
+
+replace github.com/tetratelabs/wazero => ../..
diff --git a/internal/integration_test/go.sum b/internal/integration_test/go.sum
new file mode 100644
index 00000000..37155b8a
--- /dev/null
+++ b/internal/integration_test/go.sum
@@ -0,0 +1,4 @@
+github.com/tetratelabs/wazero v0.0.0-20220414083743-1e383881edc0 h1:MYB8s3+HS4qaxvnEDJm3Qsn0NQXvBhowgSJVyBZeW+k=
+github.com/tetratelabs/wazero v0.0.0-20220414083743-1e383881edc0/go.mod h1:5JB7ectLUx/rulnLfKI628r3/wUm1grVYnHfmQ2hpBY=
+github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
+github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
diff --git a/internal/wasm/jit/jit_impl_amd64_test.go b/internal/wasm/jit/jit_impl_amd64_test.go
index b95701b3..c05c109f 100644
--- a/internal/wasm/jit/jit_impl_amd64_test.go
+++ b/internal/wasm/jit/jit_impl_amd64_test.go
@@ -5,26 +5,10 @@ import (
 
 	"github.com/tetratelabs/wazero/internal/asm"
 	amd64 "github.com/tetratelabs/wazero/internal/asm/amd64"
-	"github.com/tetratelabs/wazero/internal/asm/amd64_debug"
 	"github.com/tetratelabs/wazero/internal/testing/require"
-	"github.com/tetratelabs/wazero/internal/wasm"
 	"github.com/tetratelabs/wazero/internal/wazeroir"
 )
 
-// newDebugAmd64Compiler allows debugging in tests, without pinning a dependency in main code.
-func newDebugAmd64Compiler(f *wasm.FunctionInstance, ir *wazeroir.CompilationResult) (compiler, error) {
-	c, err := newAmd64Compiler(f, ir)
-	if err != nil {
-		return nil, err
-	}
-	a, err := amd64_debug.NewDebugAssembler()
-	if err != nil {
-		return nil, err
-	}
-	c.(*amd64Compiler).assembler = a
-	return c, nil
-}
-
 func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
 	for _, kind := range []wazeroir.OperationKind{
 		wazeroir.OperationKindMul,
@@ -87,7 +71,7 @@ func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
 						const x2Value uint32 = 51
 						const dxValue uint64 = 111111
 
-						compiler := env.requireNewCompiler(t, newDebugAmd64Compiler, nil).(*amd64Compiler)
+						compiler := env.requireNewCompiler(t, newAmd64Compiler, nil).(*amd64Compiler)
 						err := compiler.compilePreamble()
 						require.NoError(t, err)
 
@@ -209,7 +193,7 @@ func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
 						const dxValue uint64 = 111111
 
 						env := newJITEnvironment()
-						compiler := env.requireNewCompiler(t, newDebugAmd64Compiler, nil).(*amd64Compiler)
+						compiler := env.requireNewCompiler(t, newAmd64Compiler, nil).(*amd64Compiler)
 						err := compiler.compilePreamble()
 						require.NoError(t, err)
 
@@ -288,7 +272,7 @@ func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
 func TestAmd64Compiler_readInstructionAddress(t *testing.T) {
 	t.Run("invalid", func(t *testing.T) {
 		env := newJITEnvironment()
-		compiler := env.requireNewCompiler(t, newDebugAmd64Compiler, nil).(*amd64Compiler)
+		compiler := env.requireNewCompiler(t, newAmd64Compiler, nil).(*amd64Compiler)
 
 		err := compiler.compilePreamble()
 		require.NoError(t, err)
@@ -304,7 +288,7 @@ func TestAmd64Compiler_readInstructionAddress(t *testing.T) {
 
 	t.Run("ok", func(t *testing.T) {
 		env := newJITEnvironment()
-		compiler := env.requireNewCompiler(t, newDebugAmd64Compiler, nil).(*amd64Compiler)
+		compiler := env.requireNewCompiler(t, newAmd64Compiler, nil).(*amd64Compiler)
 
 		err := compiler.compilePreamble()
 		require.NoError(t, err)