Repository: tetratelabs/wazero
Pull request #597 (2022-05-28 00:29:26)

Moves test-only symbols out of wazero package
This moves the compiler support flag out of the public package as it was
only put there for tests. This also files modgen under the testing
subdir so that it isn't mistaken for main code.



Patch:
diff --git a/config_supported.go b/config_supported.go
index b56058b4..ae2085cc 100644
--- a/config_supported.go
+++ b/config_supported.go
@@ -2,9 +2,6 @@
 
 package wazero
 
-// CompilerSupported returns whether the compiler is supported in this environment.
-const CompilerSupported = true
-
 // NewRuntimeConfig returns NewRuntimeConfigCompiler
 func NewRuntimeConfig() RuntimeConfig {
 	return NewRuntimeConfigCompiler()
diff --git a/config_unsupported.go b/config_unsupported.go
index 0454cd3d..d88e9ac4 100644
--- a/config_unsupported.go
+++ b/config_unsupported.go
@@ -2,9 +2,6 @@
 
 package wazero
 
-// CompilerSupported returns whether the compiler is supported in this environment.
-const CompilerSupported = false
-
 // NewRuntimeConfig returns NewRuntimeConfigInterpreter
 func NewRuntimeConfig() RuntimeConfig {
 	return NewRuntimeConfigInterpreter()
diff --git a/internal/engine/compiler/arch.go b/internal/engine/compiler/arch.go
index 4acbb378..e216231c 100644
--- a/internal/engine/compiler/arch.go
+++ b/internal/engine/compiler/arch.go
@@ -6,6 +6,9 @@ var (
 	newArchContext func() archContext
 )
 
+// IsSupported returns whether the compiler is supported on this architecture.
+const IsSupported = isSupported
+
 // nativecall is used by callEngine.execWasmFunction and the entrypoint to enter the compiled native code.
 // codeSegment is the pointer to the initial instruction of the compiled native code.
 // ce is "*callEngine" as uintptr.
diff --git a/internal/engine/compiler/arch_amd64.go b/internal/engine/compiler/arch_amd64.go
index 1454e2e0..c2ead961 100644
--- a/internal/engine/compiler/arch_amd64.go
+++ b/internal/engine/compiler/arch_amd64.go
@@ -4,6 +4,8 @@ import (
 	"github.com/tetratelabs/wazero/internal/wazeroir"
 )
 
+const isSupported = true
+
 // init initializes variables for the amd64 architecture
 func init() {
 	newArchContext = newArchContextImpl
diff --git a/internal/engine/compiler/arch_arm64.go b/internal/engine/compiler/arch_arm64.go
index 0ace96ef..da2e317b 100644
--- a/internal/engine/compiler/arch_arm64.go
+++ b/internal/engine/compiler/arch_arm64.go
@@ -6,6 +6,8 @@ import (
 	"github.com/tetratelabs/wazero/internal/wazeroir"
 )
 
+const isSupported = true
+
 // init initializes variables for the arm64 architecture
 func init() {
 	newArchContext = newArchContextImpl
diff --git a/internal/engine/compiler/arch_other.go b/internal/engine/compiler/arch_other.go
index 962ee3d9..bede0e6f 100644
--- a/internal/engine/compiler/arch_other.go
+++ b/internal/engine/compiler/arch_other.go
@@ -9,6 +9,8 @@ import (
 	"github.com/tetratelabs/wazero/internal/wazeroir"
 )
 
+const isSupported = false
+
 // archContext is empty on an unsupported architecture.
 type archContext struct{}
 
diff --git a/internal/modgen/modgen.go b/internal/testing/modgen/modgen.go
similarity index 100%
rename from internal/modgen/modgen.go
rename to internal/testing/modgen/modgen.go
diff --git a/internal/modgen/modgen_test.go b/internal/testing/modgen/modgen_test.go
similarity index 100%
rename from internal/modgen/modgen_test.go
rename to internal/testing/modgen/modgen_test.go
diff --git a/wasm.go b/wasm.go
index 168896b4..4eb9fd46 100644
--- a/wasm.go
+++ b/wasm.go
@@ -116,6 +116,7 @@ type Runtime interface {
 	api.Closer
 }
 
+// NewRuntime returns a runtime with a configuration assigned by NewRuntimeConfig.
 func NewRuntime() Runtime {
 	return NewRuntimeWithConfig(NewRuntimeConfig())
 }


Test patch:
diff --git a/internal/integration_test/engine/adhoc_test.go b/internal/integration_test/engine/adhoc_test.go
index 63a654f8..f787f9d8 100644
--- a/internal/integration_test/engine/adhoc_test.go
+++ b/internal/integration_test/engine/adhoc_test.go
@@ -11,6 +11,7 @@ import (
 
 	"github.com/tetratelabs/wazero"
 	"github.com/tetratelabs/wazero/api"
+	"github.com/tetratelabs/wazero/internal/engine/compiler"
 	"github.com/tetratelabs/wazero/internal/testing/require"
 	"github.com/tetratelabs/wazero/internal/wasm"
 	"github.com/tetratelabs/wazero/sys"
@@ -46,7 +47,7 @@ var tests = map[string]func(t *testing.T, r wazero.Runtime){
 }
 
 func TestEngineCompiler(t *testing.T) {
-	if !wazero.CompilerSupported {
+	if !compiler.IsSupported {
 		t.Skip()
 	}
 	runAllTests(t, tests, wazero.NewRuntimeConfigCompiler())
diff --git a/internal/integration_test/engine/hammer_test.go b/internal/integration_test/engine/hammer_test.go
index afe6ef76..3cdac903 100644
--- a/internal/integration_test/engine/hammer_test.go
+++ b/internal/integration_test/engine/hammer_test.go
@@ -6,6 +6,7 @@ import (
 
 	"github.com/tetratelabs/wazero"
 	"github.com/tetratelabs/wazero/api"
+	"github.com/tetratelabs/wazero/internal/engine/compiler"
 	"github.com/tetratelabs/wazero/internal/testing/hammer"
 	"github.com/tetratelabs/wazero/internal/testing/require"
 	"github.com/tetratelabs/wazero/sys"
@@ -18,7 +19,7 @@ var hammers = map[string]func(t *testing.T, r wazero.Runtime){
 }
 
 func TestEngineCompiler_hammer(t *testing.T) {
-	if !wazero.CompilerSupported {
+	if !compiler.IsSupported {
 		t.Skip()
 	}
 	runAllTests(t, hammers, wazero.NewRuntimeConfigCompiler())