Skip to content

live-reload of .slint file for rust compiled app #8837

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ogoffart
Copy link
Member

@ogoffart ogoffart commented Jul 2, 2025

This will generate API that calls the interpreter behind the scene.
And it will set a file system watcher so reload automatically

Can be tested by running an app like so:

SLINT_LIVE_RELOAD=1 cargo run -p gallery --features=slint/live-reload

SLINT_LIVE_RELOAD=1 is needed at build time so the rust compiler generate the right thing, the slint/live-reload feature will be used to enable the runtime for the live-reloading

  • Since only the public API needs to be compiled by the rust compiler, the rust compilation is faster.
  • The automatic reloading feature works Ok, but can lead to unexpected states. But the application can still be restarted without compiling.
  • If the interface changes in an incompatible way (deleted properties or callback or to incompatible types) then the app will panic.

Rust part of #4128

@tronical
Copy link
Member

tronical commented Jul 3, 2025

Looks good at first glance (just glanced because it's still a draft). Quite elegant and minimal.

One missing item is perhaps to run the test driver with this also in the CI, so that we catch any accidentally regressions in the new code generator.

ogoffart added 2 commits July 3, 2025 14:10
Because i want to be able to hold componetns that do not directly
implement ItemTreeVTable, but only forward to it
This fixes the test on tests/cases/model/models when using the rust
interpreter, as the second test has a "broken" model, the data is left
uninitialized, and this causes a data of the wrong type which causes
panic when it is being used.
@ogoffart ogoffart force-pushed the olivier/wip-rust-build-interpreter branch 2 times, most recently from 9f8fb86 to 10a4564 Compare July 3, 2025 12:44
@ogoffart ogoffart marked this pull request as ready for review July 3, 2025 12:51
ogoffart added 4 commits July 3, 2025 14:53
When the SLINT_LIVE_RELOAD env variable is set, generate a component
that will forward everything to the interpreter instead of generating
everything.

Fix running the test driver rust with the SLINT_LIVE_RELOAD

```
SLINT_LIVE_RELOAD=1 cargo test -p test-driver-rust --all-features --features=slint/live-reload
```
@ogoffart ogoffart force-pushed the olivier/wip-rust-build-interpreter branch from 10a4564 to 9b5c1cb Compare July 3, 2025 12:53
@ogoffart ogoffart changed the title WIP: live-reload of .slint file for rust compiled app live-reload of .slint file for rust compiled app Jul 3, 2025
Comment on lines +34 to +35
} else if live_reload && module_name.contains("write_to_model") {
"#[ignore = \"Interpreted model don't forward to underlying models for anonymous structs\"]"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is something like that:

    property<[{name: string, account: string, score: float}]> model: [
//   ...
    ];


    for person[i] in model: TouchArea {
        // ...
        clicked => {
            person.score += 1;
        //...

The test does set a ModelRc<(slint::SharedString, slint::SharedString, f32)> to the property, then click, then expect the model to be changed.

But the ModelRc needs to be mapped. Since Value doesn't implement From<> for tuples (it can't, really, how would they know the names of the fields), Then the code generated there do the conversion:
https://github.com/slint-ui/slint/pull/8837/files#diff-70fcd8b8c35cc6705d940dbda1e7664aa8d23a78c32de31466c66d2ece515011R370-R372

                let sp::live_reload::Value::Model(model) = v else { return sp::Err(()) };
                sp::Ok(sp::ModelRc::new(model.map(|x| #conf_fn(x).unwrap_or_default())))

But model.map returns a MappedModel that doesn't implement set_row_data. Cf #5290

@ogoffart ogoffart requested a review from tronical July 3, 2025 13:19
Copy link
Member

@tronical tronical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to also add the run-if-changed for the env variable to trigger rebuilds correctly.

Comment on lines +88 to +90
## This feature allow to reload the .slint files at runtime, and reload it whenever the files are modified on disk.
## In order to use this, you will also need to define the `SLINT_LIVE_RELOAD` environment variable while
## doing the slint compilation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## This feature allow to reload the .slint files at runtime, and reload it whenever the files are modified on disk.
## In order to use this, you will also need to define the `SLINT_LIVE_RELOAD` environment variable while
## doing the slint compilation.
## Enable this feature to reload the .slint files at runtime and reload it whenever the files are modified on disk.
## For this feature to work, it's also required to set the `SLINT_LIVE_RELOAD` environment variable during
## application compilation.

Comment on lines +92 to +96
## Since this is a debug-only feature, it is not recommanded to add this feature to your Cargo.toml.
## Instead, you can use the `--features` command line argument like so when building your app:
## ```bash
## SLINT_LIVE_RELOAD=1 cargo build --features slint/live-reload
## ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Since this is a debug-only feature, it is not recommanded to add this feature to your Cargo.toml.
## Instead, you can use the `--features` command line argument like so when building your app:
## ```bash
## SLINT_LIVE_RELOAD=1 cargo build --features slint/live-reload
## ```
## This is a feature for debugging and development. It's not recommended to add this feature to your Cargo.toml.
## Instead, use the `--features` command line argument like so when building your app:
## ```bash
## SLINT_LIVE_RELOAD=1 cargo build --features slint/live-reload
## ```

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.

2 participants