Reducing rust-analyzer check time by splitting bridge from implementation #1043
Replies: 2 comments 1 reply
-
There is one downside I noticed: visibility. In order to have implementations and tests in a separate file, it is often necessary to declare the Rust struct's fields as "pub", otherwise the implementation file cannot see them. To me this is an acceptable drawback. |
Beta Was this translation helpful? Give feedback.
-
This is a super cool way to optimize build times, thank you for sharing! Overall we should try to find a way to optimize the build times with CxxQtBuild anyhow, but this is a good workaround for now. I should note that with the recent improvements to our build system, it should at least be possible to split projects into crates more easily. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This could be considered a micro-show-and-tell.
I noticed that, at least in VSCode, the time for rust-analyzer to check code on saving (
cargo check
) is very long when making any kind of change to a Rust file that has accx_qt::bridge
module in it. It really slows down development, especially since it takes a lock on the cargo directory preventing e.g. running tests.I don't have a direct solution, but did find that usually, during development we tend to change a lot in method implementations and test cases, but less frequently to the bridge module itself (the object signature).
Therefore, for me it works well to provide the
impl MyObject { ... }
, along with any helper functions and tests related to the object, in a separate Rust file from the bridge whereMyObject
is declared. That way, changes to the non-bridge file will recompile very fast since no C++ needs to be generated in the background.A small example:
qobj_release_focus_notifier_bridge.rs
:and the accompanying
qobj_release_focus_notifier.rs
:This example is tiny and only implements one method. But when the number of methods starts to increase this makes a large difference. Especially when working on unit tests: those can be defined in the non-bridge file, so tests can be very quickly added and debugged without re-running code generation.
This might be an obvious thing to Rust veterans, but I was surprised that this division over files is even allowed under Rust's orphaning rules. Maybe it is a bit of advice that could be included in the documentation?
Beta Was this translation helpful? Give feedback.
All reactions