-
Notifications
You must be signed in to change notification settings - Fork 5
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
Icons are not initialized if CARGO_TARGET_DIR is used #12
Comments
I wasn't aware that global target dirs are a thing. The question is whether a build script is able to figure out the manifest directory of the root crate (the one which depends on relm4-icons) in this case. As I explained, I think there's no standardized solution for communicating such information to build scripts (or more precisely the only solution got cancelled by crates.io). The only available information are the env variables... |
I don't think there is and it is architecturally wrong in general. Out of curiosity, what is the issue with including all icons? They are downloaded anyway and compiler should be able to eliminate unused constants (though this might require LTO, didn't check). |
That's actually the same thing the crates.io team suggested when I asked them to remove the feature flag limitation. No, that doesn't work because GTK loads icons as bundled resources and the Rust compiler does not know what's in the resource bundle. |
Well, then the alternative could be to expose a function that user of the library has to call from their |
I already thought about this earlier. We could definitely use macros for archiving the same result, albeit a bit less beautiful (AFAIK you can't tell Rust to rebuild code if files changed through a macro). I can try to get this to work. |
Instructions to Rust (or Cargo?) are just printed to stdout, so should work. And any changes to |
I think I've hit another dead end. If I build the bundle from this crate, it can't see the primary Cargo.toml without some hacks. If I build from the primary crate (e. g. by calling a fn in build.rs or by using a macro), I don't have access to the files of this crate which includes the shipped icons. Overall, I think the best approach would be to keep this crate as it is for now and rather work on a proper solution that uses a different approach. E. g. relm4-template could be converted into an easily configurable template generator that automatically updates the generated files and supports multiple build systems (e. g. cargo, meson and flatpak). While doing this, we could also add a mechanism to download icons from here to the directory of the primary crate, making it possible to include them there with ease. |
Well, I can't upgrade anymore because my development workflow is basically broken with new version.
Why not, what is the difficulty? |
That's how I felt when the crates.io team told me I can't publish a new stable version with the old mechanism that used feature flags. They broke it and didn't want to make an exception so I had to come up with a workaround. It's really unfortunate.
AFAIK, you can only see the files in your current crate. You can't see the source code of your dependencies. So the build script or the macro wouldn't be able to access the icons shipped with this crate because they are executed by the primary crate. I just had the idea that we could include every single icon file in the generated binary of the build library or the macro tough. That would be extremely ugly, but would be a robust solution. |
Build script will still depend on |
Yeah, it should work like that. The thing is though, because the release yesterday already took me more time than a whole work day with all the various steps included and I'm already short on free time, I'm not eager to work on this in the upcoming days. I hope you understand. |
Sure, totally understand. I might take a stab at this myself depending on the mood. |
I get a similar error:
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] The error is triggered at this line, not this line like the OP's build did. Is it related to the same issue or is it best if I open a separate thread for this? |
@nazar-pc @AaronErhardt: I'm not positive if I understood what was wrong, but it looks like you all are saying If so, it looks like the There's a corner case where it wouldn't work when running Let me know if I overlooked something you guys already looked into, but there's a PR open at #17 if you want to test things. |
You shouldn't rely on Basically the whole current approach is broadly speaking flawed to begin with. I think simply letting user pick icons with a call in their own It was not the highest priority for me for now, but if no one else does that, I will get to it at some point. |
You're right about that, it does look like you can build outside of the project directory through the use of I guess writing a new tool from scratch is going to be the best option. Cargo really does make this clunky to deal with :P |
Or that too, I think that'd be best honestly. Aaron probably has more insight than me on the best approach between the two though. |
I actually had an idea how to solve the issue entirely (not sure whether it works though). We could include each icon into its own resource bundle and only load it, if the constant of the icon name was used. This would actually allow dead-code elimination to remove the unused icons. We could store each icon as |
I started working on this, mostly based on @nazar-pc suggestions:
basically, I created a sub-crate
could you tell more about this approach @AaronErhardt? |
The "approach" you've cited is actually a statement, so I don't know what I should answer. The general problem is always that you can't access files across crates, but only the resulting library. So if we compile all icons into a library, we could circumvent the problem. Yet, unless we have a mechanism for dead-code elimination, we add bloat to the final binary. Therefore, I suggested storing the icons individually bundled in static variables, that only get accessed (and initialized) if their icon name is derefed ( |
What is the issue exactly? |
basically this one:
I need the path to the icons shipped with this crate in the build script of the application |
The reason I mentioned build crate is because build crate can have It will then be available either directly or through a specific function in |
The way config file is searched doesn't account for
CARGO_TARGET_DIR
and results in errors like this:/home/nazar-pc/.cache/cargo/target
is mytarget
shared across multiple projects, I don't havetarget
local to each crate.The text was updated successfully, but these errors were encountered: