-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
dd18544
e82f27d
98b3e08
5312ce0
e692659
1a8297b
ef56568
27cee59
fa9609d
37a7a6e
cca2ecb
75d15c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
There was a problem hiding this comment.
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