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

feat(config) Add the CompilerKind and EngineKind types #213

Merged
merged 3 commits into from
Feb 18, 2021

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Feb 18, 2021

This patch introduces the CompilerKind and EngineKind types.

This patch also introduces the IsCompilerAvailable and IsEngineAvailable functions. They must be used to check whether a specific compiler or engine is available, otherwise the Config.Use*Compiler or Config.Use*Engine may panic.

This patch also fixes a bug with the Config.Use*Compiler methods where the wasm_config_set_engine function was called instead of wasm_config_set_compiler.

@Hywan
Copy link
Contributor Author

Hywan commented Feb 18, 2021

bors try

bors bot added a commit that referenced this pull request Feb 18, 2021
@Hywan Hywan self-assigned this Feb 18, 2021
@Hywan Hywan added 🎉 enhancement New feature or request 🐞 bug Something isn't working 📚 documentation Do you like to read? 📦 component-extension About the Go extension labels Feb 18, 2021
Copy link
Contributor

@jubianchi jubianchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me, I would just have added a test for IsCompilerAvailable but it may only introduce code duplication 🤔

@Hywan
Copy link
Contributor Author

Hywan commented Feb 18, 2021

Yeah, it's not that simple to test actually. I consider that if the TestConfig_AllCombinations test passes, then it's fine enough for the moment (

func TestConfig_AllCombinations(t *testing.T) {
type Test struct {
compilerName string
engineName string
config *Config
}
var configs = []Test{}
is_amd64 := runtime.GOARCH == "amd64"
//is_aarch64 := runtime.GOARCH == "arm64"
is_linux := runtime.GOOS == "linux"
is_darwin := runtime.GOOS == "darwin"
//is_windows := runtime.GOOS == "windows"
// Cranelift with the JIT engine works everywhere
configs = append(configs, Test{"Cranelift", "JIT", NewConfig().UseCraneliftCompiler().UseJITEngine()})
// Cranelift with the Native engine works on Linux+Darwin/amd64.
if is_amd64 && (is_linux || is_darwin) {
configs = append(configs, Test{"Cranelift", "Native", NewConfig().UseCraneliftCompiler().UseNativeEngine()})
}
/*
LLVM isn't part of the prepacked `libwasmer` for the moment.
// LLVM with the JIT engine works on Linux+Darwin/amd64.
if is_amd64 && (is_linux || is_darwin) {
configs = append(configs, Test{"LLVM", "JIT", NewConfig().UseLLVMCompiler().UseJITEngine()})
}
// LLVM with the Native engine works on Linux+Darwin/amd64.
if is_amd64 && (is_linux || is_darwin) {
configs = append(configs, Test{"LLVM", "Native", NewConfig().UseLLVMCompiler().UseNativeEngine()})
}
*/
// Singlepass with the JIT engine works on Linux+Darwin/amd64.
if is_amd64 && (is_linux || is_darwin) {
configs = append(configs, Test{"Singlepass", "JIT", NewConfig().UseSinglepassCompiler().UseJITEngine()})
}
for _, test := range configs {
t.Run(
fmt.Sprintf("compiler=%s, engine=%s", test.compilerName, test.engineName),
func(t *testing.T) {
engine := NewEngineWithConfig(test.config)
store := NewStore(engine)
module, err := NewModule(store, testGetBytes("tests.wasm"))
assert.NoError(t, err)
instance, err := NewInstance(module, NewImportObject())
assert.NoError(t, err)
sum, err := instance.Exports.GetFunction("sum")
assert.NoError(t, err)
result, err := sum(37, 5)
assert.NoError(t, err)
assert.Equal(t, result, int32(42))
},
)
}
}
).

@Hywan
Copy link
Contributor Author

Hywan commented Feb 18, 2021

bors r+

@bors bors bot merged commit daa306d into wasmerio:master Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 component-extension About the Go extension 📚 documentation Do you like to read? 🎉 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants