diff --git a/providers/go-feature-flag/pom.xml b/providers/go-feature-flag/pom.xml
index 331241416..91da6ac61 100644
--- a/providers/go-feature-flag/pom.xml
+++ b/providers/go-feature-flag/pom.xml
@@ -19,6 +19,8 @@
${groupId}.gofeatureflag
+
+ v1.45.4
@@ -74,16 +76,10 @@
test
-
- com.dylibso.chicory
- runtime
- 1.5.0
-
-
com.dylibso.chicory
wasi
- 1.5.0
+ 1.6.0
@@ -117,20 +113,18 @@
- org.codehaus.mojo
- exec-maven-plugin
+ com.dylibso.chicory
+ chicory-compiler-maven-plugin
+ 1.6.0
- download-latest-github-asset
- generate-resources
+ gofeatureflag
- exec
+ compile
- bash
-
- ${project.basedir}/download-wasm.sh
-
+ dev.openfeature.contrib.providers.gofeatureflag.wasm.Module
+ wasm-releases/evaluation/gofeatureflag-evaluation_${wasm.version}.wasi
diff --git a/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm/EvaluationWasm.java b/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm/EvaluationWasm.java
index d80fa4776..e413913dc 100644
--- a/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm/EvaluationWasm.java
+++ b/providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm/EvaluationWasm.java
@@ -1,14 +1,15 @@
package dev.openfeature.contrib.providers.gofeatureflag.wasm;
+import com.dylibso.chicory.runtime.ByteArrayMemory;
import com.dylibso.chicory.runtime.ExportFunction;
import com.dylibso.chicory.runtime.HostFunction;
+import com.dylibso.chicory.runtime.ImportFunction;
+import com.dylibso.chicory.runtime.ImportValues;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.runtime.Memory;
-import com.dylibso.chicory.runtime.Store;
import com.dylibso.chicory.wasi.WasiExitException;
import com.dylibso.chicory.wasi.WasiOptions;
import com.dylibso.chicory.wasi.WasiPreview1;
-import com.dylibso.chicory.wasm.Parser;
import com.dylibso.chicory.wasm.types.ValueType;
import dev.openfeature.contrib.providers.gofeatureflag.bean.GoFeatureFlagResponse;
import dev.openfeature.contrib.providers.gofeatureflag.exception.WasmFileNotFound;
@@ -16,9 +17,11 @@
import dev.openfeature.contrib.providers.gofeatureflag.wasm.bean.WasmInput;
import dev.openfeature.sdk.ErrorCode;
import dev.openfeature.sdk.Reason;
-import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
import lombok.val;
/**
@@ -42,36 +45,21 @@ public EvaluationWasm() throws WasmFileNotFound {
val wasi = WasiPreview1.builder()
.withOptions(WasiOptions.builder().inheritSystem().build())
.build();
- val hostFunctions = wasi.toHostFunctions();
- val store = new Store().addFunction(hostFunctions);
- store.addFunction(getProcExitFunc());
- this.instance = store.instantiate("evaluation", Parser.parse(getWasmFile()));
+ List hostFunctions =
+ Arrays.stream(wasi.toHostFunctions()).map(this::replaceProcExit).collect(Collectors.toList());
+ this.instance = Instance.builder(Module.load())
+ .withMemoryFactory(ByteArrayMemory::new)
+ .withMachineFactory(Module::create)
+ .withImportValues(
+ ImportValues.builder().withFunctions(hostFunctions).build())
+ .build();
this.evaluate = this.instance.export("evaluate");
this.malloc = this.instance.export("malloc");
this.free = this.instance.export("free");
}
- /**
- * getWasmFile is a function that returns the path to the WASM file.
- * It looks for the file in the classpath under the directory "wasm".
- * This method handles both file system resources and JAR-packaged resources.
- *
- * @return the path to the WASM file
- * @throws WasmFileNotFound - if the file is not found
- */
- private InputStream getWasmFile() throws WasmFileNotFound {
- try {
- final String wasmResourcePath = "wasm/gofeatureflag-evaluation.wasi";
- InputStream inputStream = EvaluationWasm.class.getClassLoader().getResourceAsStream(wasmResourcePath);
- if (inputStream == null) {
- throw new WasmFileNotFound("WASM resource not found in classpath: " + wasmResourcePath);
- }
- return inputStream;
- } catch (WasmFileNotFound e) {
- throw e;
- } catch (Exception e) {
- throw new WasmFileNotFound(e);
- }
+ private ImportFunction replaceProcExit(HostFunction hf) {
+ return hf.name().equals("proc_exit") ? getProcExitFunc() : hf;
}
/**
@@ -81,7 +69,7 @@ private InputStream getWasmFile() throws WasmFileNotFound {
*
* @return a HostFunction that is called when the WASM module calls proc_exit
*/
- private HostFunction getProcExitFunc() {
+ private ImportFunction getProcExitFunc() {
return new HostFunction(
"wasi_snapshot_preview1",
"proc_exit",
diff --git a/providers/go-feature-flag/src/main/resources/wasm/gofeatureflag-evaluation.wasi b/providers/go-feature-flag/src/main/resources/wasm/gofeatureflag-evaluation.wasi
deleted file mode 100644
index 823996413..000000000
Binary files a/providers/go-feature-flag/src/main/resources/wasm/gofeatureflag-evaluation.wasi and /dev/null differ
diff --git a/spotbugs-exclusions.xml b/spotbugs-exclusions.xml
index 5efc2afc9..7f1d7ae12 100644
--- a/spotbugs-exclusions.xml
+++ b/spotbugs-exclusions.xml
@@ -17,6 +17,18 @@
+
+
+
+
+
+
+
+
+
+
+
+