-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement dynamic linking feature #867
Conversation
Awesome! |
Probably not? Bevy says it's better to be used for development, but I don't think there should be much runtime overhead. The only thing it might effect is the program's start-up time while it tries to search for one extra shared library (on top of all the other shared libraries it already has to find). Either way, if the dynamic feature is used for release builds, the shared binary would have to be packaged with the executable so it's probably not desirable. |
I copied the tour of iced example to a separate folder and pointed the iced dependency to my fork to do some testing.
I kinda expected lld to improve times a bit more, but there could be other reasons that the times are similar. |
How are you timing the compile times, (and what OS)? |
I'm using NixOS (with this flake.nix). To run each test, I modify the main.rs file a bit to trigger an iterative recompile and then note down the output time of |
Ok cool! |
Oh wow. The effects of dynamic linking seems to have a greater effect on bigger projects.
👍 👍 Great job! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting!
Could we leave the iced
crate as-is and build iced_dynamic
on top? I think the dynamic linking could be setup by users directly, instead of offering a feature out of the box which forces us to further nest the dependencies.
If I understand correctly, a user could simply introduce iced_dynamic
as an optional dependency to their Cargo.toml
and then add to their main.rs
:
#[cfg(feature = "iced_dynamic")]
use iced_dynamic;
Then, they should be able to dynamically link with cargo
by using the flag --features iced_dynamic
. Is that correct?
To do that wouldn't you need to duplicate Also, having people configure the dynamic linking themselves might put off people who are new to rust. The first time I used iced, I was annoyed by how long it took to recompile small changes. (>10 seconds sometimes!). If you are worried about dependency messiness, iced could do something like what Bevy does and move all the modules into a [workspace]
members = ["crates/*", "examples/*"] |
I agree with zyan, if possible manually configuring dynamic linking should be avoided, for both newbies and lazy people 😀 👈 |
Why can we keep If a user wants dynamic linking, they could use a different entrypoint instead of |
I'm not sure if that question was directed at me. Either way, I don't understand Rust nor Iced's under belly enough to be helpful to this conversation. |
That might work, but it will be annoying to the user if they have to constantly change their dependency from
It's necessary because the bevy does the same thing with the main Cargo.toml (and src/lib.rs) simply exporting internal crates (including bevy_internal and bevy_dynamic) based on feature flags. |
Is there a rust issue for this? This seems like something Cargo should support. |
When I investigated how Bevy's dynamic linking worked, it seems like it was a neat trick based on how Cargo handles dependency linkage.
By these rules, there needs to be wrapper over an internal crate to force Iced to compile as a dylib when the feature is toggled. |
Dynamic linking will probably be a lot easier once the Rust ABI gets stabilized, but who knows when that will happen... |
I am getting a lot of linking errors when trying to compile a project of mine using this new feature:
|
Also, I think I've been able to implement the dynamic linking feature completely on top of the current Unfortunately, it produces the same linking errors I mentioned in #867 (comment). |
I am also getting these linker errors... I tried using Rust's linker, gold, lld and all of them give linker errors. |
I got your pull request working with one of the examples by changing iced = { path = "../.." features = ["canvas", "tokio", "debug"] } to iced = { path = "../../dynamic", package="iced_dynamic", features = ["canvas", "tokio", "debug"] } which seems to be a fine way to do it (you could put one in dependencies and one in dev-dependencies and it should work fine)
I'm using rust nightly on NixOS with a custom wrapped lld linker so maybe my linker is configured differently? What OS/setup do you have? |
|
@zyansheep I tried compiling Bevy with the I believe the issue here may be related to using async. CI is also failing with weird errors... I'm closing this for now, but feel free to reopen it if you make any progress towards figuring out the cause of these issues. |
The Bevy game engine has a nice dynamic linking features which, coupled with the lld linker, significantly improves compile times.
I have added this to iced for faster compiling iterations (down to about 2.3 from 3.8 for a personal project) . What do you think?
Relevant issue: #849