From d992373ea79f018e757e7d2fe822e58ca50b3798 Mon Sep 17 00:00:00 2001 From: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com> Date: Fri, 27 May 2022 17:32:26 -0700 Subject: [PATCH] Moves test-only symbols out of wazero package (#597) 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. Signed-off-by: Adrian Cole --- config_supported.go | 3 --- config_unsupported.go | 3 --- internal/engine/compiler/arch.go | 3 +++ internal/engine/compiler/arch_amd64.go | 2 ++ internal/engine/compiler/arch_arm64.go | 2 ++ internal/engine/compiler/arch_other.go | 2 ++ internal/integration_test/engine/adhoc_test.go | 3 ++- internal/integration_test/engine/hammer_test.go | 3 ++- internal/{ => testing}/modgen/modgen.go | 0 internal/{ => testing}/modgen/modgen_test.go | 0 wasm.go | 1 + 11 files changed, 14 insertions(+), 8 deletions(-) rename internal/{ => testing}/modgen/modgen.go (100%) rename internal/{ => testing}/modgen/modgen_test.go (100%) 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/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()) 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()) }