spin icon indicating copy to clipboard operation
spin copied to clipboard

Spin watch builds all components when a single component is changed

Open adamreese opened this issue 1 year ago • 7 comments

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"]

adamreese avatar Apr 21 '23 18:04 adamreese

@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 avatar Apr 25 '23 22:04 itowlson

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

well maybe next time

itowlson avatar Apr 25 '23 22:04 itowlson

@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,
}

calebschoepp avatar Apr 25 '23 23:04 calebschoepp

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

itowlson avatar Jul 20 '23 03:07 itowlson

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

calebschoepp avatar Jun 14 '24 20:06 calebschoepp

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.

itowlson avatar Jun 16 '24 20:06 itowlson

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.

dimitrilw avatar Jun 18 '24 15:06 dimitrilw