fermyon / spin

Spin is the open source developer tool for building and running serverless applications powered by WebAssembly.
https://developer.fermyon.com/spin
Apache License 2.0
5.05k stars 242 forks source link

Spin watch builds all components when a single component is changed #1417

Open adamreese opened 1 year ago

adamreese commented 1 year ago

if files in foo are changed foo and bar both get rebuilt.

[[component]]
id = "foo"
...
[component.build]
workdir = "foo"
command = "cargo build --target wasm32-wasi --release"
watch = ["src/**/*.rs", "Cargo.toml"]

[[component]]
id = "bar"
[component.build]
workdir = "bar"
command = "cargo build --target wasm32-wasi --release"
watch = ["src/**/*.rs", "Cargo.toml"]
itowlson commented 1 year ago

@calebschoepp This feels like something that could slot nicely in if/when you are separating "artifact" paths from "source code" paths - you could split the source code watches down further to associate component name(s) with them. Though presumably it would also need an entry point into build to build only specific components - I am not sure how you are driving that at the moment.

itowlson commented 1 year ago

reads 3 emails further on and discovers that @calebschoepp has already done that refactor

well maybe next time

calebschoepp commented 1 year ago

@itowlson this isn't handled in my current refactor (#1418) and is out of scope for it. Buuuuuut, my refactor has laid the foundation to do this much more easily. Something like:

pub enum Effect {
    /// Exit spin watch
    Exit,
    /// Either `spin build` or `spin up` failed to run
    ProcessFailed,
    /// `spin build` has completed running, `spin up` never completes
    ProcessCompleted,
    /// Changes have been made to the application manifest
    ManifestChange,
    /// Changes have been made to the application source code
    SourceChange(component String),
    /// Changes have been made to an application artifact
    ArtifactChange(component String),
    /// A default option that maps to doing nothing
    DoNothing,
}
itowlson commented 12 months ago

Just noting that the single-component entry point into build now exists courtesy of the Spin Doctor.

calebschoepp commented 1 month ago

@itowlson is this kind of feature still achievable with your redesign of spin watch or do we just want to close this issue?

itowlson commented 1 month ago

We still want to do it but my refactor definitely introduced exciting new challenges to doing so - see the discussion on https://github.com/fermyon/spin/pull/2478. I would leave it open because it is still a nice-to-have feature.

dimitrilw commented 4 weeks ago

Ok, so a silly and naive question: Can't the underlying "compile my stuff to WASM binary" routine just do a quick sanity-check:

Have any files in the component been mod'd since last compilation?

There could be a flag in the config that is False by default, then opt-in via config.

[component name]
only_compile_if_modified = True

Then, the components that are slowest to compile could be toggled to only be recompiled when one of the component's files were mod'd.

[my tinygo component]
# since tinygo is very slow to compile, 
# only compile if a file inside the /my-tinygo-component dir was mod'd since last compile
only_compile_if_modified = True

To track, an artifact could be left in the .spin dir that lists last compile time for flagged components. Whenever the compile routine is called (via build or watch or whatever), then that routine would do a sanity-check for each component prior to rebuilding it.