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

Sketch Linker implementation. #9

Closed
wants to merge 12 commits into from
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>999-SNAPSHOT</chicory.version>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose we might want to wait for a release before merging

</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
46 changes: 46 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,46 @@
package org.extism.chicory.sdk;

import com.dylibso.chicory.aot.AotMachine;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.wasm.Module;
import com.dylibso.chicory.wasm.Parser;

import java.nio.file.Path;

class ChicoryModule {

static final boolean IS_NATIVE_IMAGE_AOT = Boolean.getBoolean("com.oracle.graalvm.isaot");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not strictly related to this PR, but it's necessary to compile this under graalvm native image. This flag is true when the native image builder it's running. We want to make sure that the code path below is pruned at build-time, because the AoT in its current state is not compatible with the way native image works.


static Module fromWasm(ManifestWasm m) {
if (m instanceof ManifestWasmBytes) {
ManifestWasmBytes mwb = (ManifestWasmBytes) m;
return Parser.parse(mwb.bytes);
} else if (m instanceof ManifestWasmPath) {
ManifestWasmPath mwp = (ManifestWasmPath) m;
return Parser.parse(Path.of(mwp.path));
} else if (m instanceof ManifestWasmFile) {
ManifestWasmFile mwf = (ManifestWasmFile) m;
return Parser.parse(mwf.filePath);
} else if (m instanceof ManifestWasmUrl) {
ManifestWasmUrl mwu = (ManifestWasmUrl) m;
return Parser.parse(mwu.getUrlAsStream());
} else {
throw new IllegalArgumentException("Unknown ManifestWasm type " + m.getClass());
}
}

static Instance.Builder instanceWithOptions(Module m, Manifest.Options opts) {
Instance.Builder builder = Instance.builder(m);
if (opts == null) {
return builder;
}
// This feature is not compatibly with the native-image builder.
if (opts.aot && !IS_NATIVE_IMAGE_AOT) {
builder.withMachineFactory(AotMachine::new);
}
if (!opts.validationFlags.isEmpty()) {
throw new UnsupportedOperationException("Validation flags are not supported yet");
}
return builder;
}
}
Loading