Skip to content

Commit

Permalink
Backport Linker API (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: Edoardo Vacchi <[email protected]>
  • Loading branch information
evacchi authored Oct 16, 2024
1 parent 8700bc6 commit 967a52a
Show file tree
Hide file tree
Showing 30 changed files with 914 additions and 204 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>

<chicory.version>0.0.12</chicory.version>
</properties>

<dependencies>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>runtime</artifactId>
<version>0.0.12</version>
<version>${chicory.version}</version>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasi</artifactId>
<version>0.0.12</version>
<version>${chicory.version}</version>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>aot</artifactId>
<version>0.0.12</version>
<version>${chicory.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/org/extism/chicory/sdk/ChicoryModule.java
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;
}
}
Loading

0 comments on commit 967a52a

Please sign in to comment.