feat: add initial static component executor #237
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds a composed webassembly component model module that uses the policy engine module.
The idea here is that we can take a policy, perhaps created in the playground, and include it in the static component.
Example usage
To generate a .wasm module we specify a policy file and the policy name. We also have to specify a modules directory where the engine component, and the static-evaluator component are located:
With
dog-composed.wasm
we can then run it in a wasm runtime:Sizes of component modules
Comments
I initially searched for a way to update a .wasm module with a policy which would have meant that we did not have to compile a new core wasm module. I looked at adding the policy as a custom section of the wasm module but that is only available from the "outside" of the module not from within which is what we want. Since we want to be able to run this from the command line, and from a server environment, we don't want to have to have the whole repository checked out to be able to generate this "static" component module.
What I've done in this draft is create a webassembly component module named
static-evaluator
that imports the policy engine, and also imports a component namedstatic-config
. The static-config component is what we then need to generate for each standalone .wasm. The way this is done is by generating a project on the file system, including the source for the static config component. This source has the wit is inlined so it does not have to have access to the wit files in this repository. This will then be compiled to a core wasm module, then programatically create a component of that core wasm module. Then we compose a new component using the component we just created and the policy-engine component. This generate component is what can then be run in a wasm runtime that supports the component model.The drawbacks of the current solution is that it requires the environment this is run on to have a Rust compiler and also support the target
wasm32-unknown-unknown
. And the policy-engine component and the static-evaluator component must also be available on the file system.Outstanding tasks
Currently there is only one source file being generated in one project. But it would better to perhaps have a workspace generated and then have a member crate for each policy being generated. That way they should be able to share the same dependencies and at the same time not overwrite each other. (Hope that makes sense).
--release
build causing a compilation error.Follow up tasks