-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Edoardo Vacchi <[email protected]>
- Loading branch information
Showing
30 changed files
with
914 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.extism.chicory.sdk; | ||
|
||
import com.dylibso.chicory.aot.AotMachine; | ||
import com.dylibso.chicory.runtime.Module; | ||
|
||
import java.nio.file.Path; | ||
|
||
class ChicoryModule { | ||
|
||
static final boolean IS_NATIVE_IMAGE_AOT = Boolean.getBoolean("com.oracle.graalvm.isaot"); | ||
|
||
static Module fromWasm(ManifestWasm m) { | ||
if (m instanceof ManifestWasmBytes) { | ||
ManifestWasmBytes mwb = (ManifestWasmBytes) m; | ||
return Module.builder(mwb.bytes).build(); | ||
} else if (m instanceof ManifestWasmPath) { | ||
ManifestWasmPath mwp = (ManifestWasmPath) m; | ||
return Module.builder(Path.of(mwp.path)).build(); | ||
} else if (m instanceof ManifestWasmFile) { | ||
ManifestWasmFile mwf = (ManifestWasmFile) m; | ||
return Module.builder(mwf.filePath).build(); | ||
} else if (m instanceof ManifestWasmUrl) { | ||
ManifestWasmUrl mwu = (ManifestWasmUrl) m; | ||
return Module.builder(mwu.getUrlAsStream()).build(); | ||
} else { | ||
throw new IllegalArgumentException("Unknown ManifestWasm type " + m.getClass()); | ||
} | ||
} | ||
|
||
static Module.Builder instanceWithOptions(Module.Builder m, Manifest.Options opts) { | ||
if (opts == null) { | ||
return m; | ||
} | ||
// This feature is not compatibly with the native-image builder. | ||
if (opts.aot && !IS_NATIVE_IMAGE_AOT) { | ||
m.withMachineFactory(AotMachine::new); | ||
} | ||
if (!opts.validationFlags.isEmpty()) { | ||
throw new UnsupportedOperationException("Validation flags are not supported yet"); | ||
} | ||
return m; | ||
} | ||
} |
Oops, something went wrong.