Check for Rust and wasm32-wasi on spin new and spin build #1432
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 adds a Rhai scripting facility to Spin templates and to the
spin build
command. The scripting facility is used to implement a check that the user has Rust and thewasm32-wasi
target installed when they install thehttp-rust
template, and when they build an application based on that template and the build fails.Some questions for reviewers:
The current draft ships scripts to the user as part of template install and instantiation. I can already envisage problems with this: as Rust 1.71 will change the
wasm32-wasi
target towasm32-wasi-preview1
, users on Rust 1.71 whose templates predate Rust 1.71 will get the wrong advice. I would kind of like to be able to point at, say,magic:rust
instead of a local path, and have that fetch the latest script(s) - but I don't want to slow down template instantiation or build, and definitely not require the user to be online! We can snapshot the magic scripts at template install time (which is an inherently online activity), but how do we painlessly update them? [ETA: Incidentally, this would largely obviate question 5.]There is duplication across the
templates
andbuild
crates. Would it be reasonable to create ascripting
crate to encapsulate this? (That in turn raises whether we should have aninteraction
orui
crate, sincescripting
alone would have duplication withtemplates::interaction
.)Currently templates cite scripts via the manifest (e.g.
[scripts] after_instantiate = "after_instantiate.rhai"
. This feels like there's redundancy there. How do people feel about just using a naming convention instead? (E.g. if the template includes a script file calledafter_instantiation.rhai
then we run it after instantiation, no need for a manifest entry.)I put the component checker in a directory under the component called
.spinbuild
. I hate this. I considered.spin/build
(and excluding that from .gitignore) but at the moment the.spin
directory is kind of transient, and I suspect people are already learning to blow it away when you want to reset an app to its clean state. Any ideas?If a component build fails, should a script be allowed to signal to retry it? This would fix a bit of ugliness/potential confusion where we go "okay we have installed
wasm32-wasi
for you but your build failed." But I am wondering if it would cause coordination issues in multi-component applications, e.g. if different scripts signal different things.Is it worth being able to mark a template script as "advisory" - that is, success or failure does not affect the overall outcome of template instantiation? The current Rust script probably should be advisory, because you still have an app if it fails. So maybe "advisory" should be the default, and we can add "critical" later if we need to?
Some to-dos:
I haven't yet done the
redis-rust
templateI haven't done any languages other than Rust
Uh probably a bunch of other things I have lost track of, yay