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

Experiment: Dynamic Linking of core #8

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Sep 13, 2024

See my EIP for more details on this

How this experiment works

The way this compiler currently works is it builds a shim.wasm and a core.wasm. The shim had both the export and the import shims in it. This works fine when using wasm-merge, but creates a circular dependency when trying to dynamically load the modules. So i moved the imports into their own module. They could maybe be wasm-merged with core.wasm though?

When compiling count-vowels.wasm e.g., we get 3 modules in our build directory (hard coded to my home directory ~/py-out):

$ ls
core.wasm  import_shim.wasm  main.wasm

core.wasm exports the __invoke:

$ wasm-objdump core.wasm --section=Export -x

core.wasm:	file format wasm 0x1

Section Details:

Export[3]:
 - memory[0] -> "memory"
 - func[11050] <__invoke> -> "__invoke"
 - func[11052] <PyInit_extism_ffi> -> "PyInit_extism_ffi"

import_shim.wasm just has the __invokeHostFunc* exports.

main.wasm has the final export:

$ wasm-objdump main.wasm --section=Export -x

main.wasm:	file format wasm 0x1

Section Details:

Export[1]:
 - func[1] <count_vowels> -> "count_vowels"

These all get wasm-merged together in the end. But i left the build directory so i could try dynamically linking them. And it works:

$ extism call main.wasm count_vowels --input="Hello World" --link import_shim=import_shim.wasm --link core=./core.wasm  --wasi
{"count": 3}

Note that the way this is being wizened, i don't this this core is reusable. Discussed this in the EIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant