-
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
Refactor build script and expose build functions for crate dependents #19
Refactor build script and expose build functions for crate dependents #19
Conversation
32cf9f1
to
168626c
Compare
168626c
to
07c9fb1
Compare
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.
I expected the whole icons.toml
to be replaced with either a section in Cargo.toml
or direct code when calling build script. A separate file in the root of the project is annoying.
src/lib.rs
Outdated
pub fn initialize_icons() { | ||
gio::resources_register_include!("resources.gresource").unwrap(); | ||
#[macro_export] | ||
macro_rules! initialize_icons { |
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.
Why does this need to be a macro? Looks like a function should work just like before. If you really want to make sure compiler removes it when not necessary add #[inline]
to the function definition.
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.
gio::resources_register_include!("resources.gresource")
tries to load the gresource
but since I am moving the resource bundling to the application's build script from this crate, it won't find the resources.gresource
in the OUT_DIR
of this crate
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.
Then specify an absolute path there instead of relative
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.
gio::resources_register_include!
tries to read OUT_DIR
env variable which is not set in the relm4-icons
crate because it doesn't have build script anymore. Or am I missing sth?
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.
All the macro does is calling a hidden function internally. You do not need either macro or that function strictly speaking, just copy these 3 lines and call them with whatever arguments you may need:
https://github.com/gtk-rs/gtk-rs-core/blob/e1ad60d1c8b38634f638f50ec2b36cdc62462daf/gio/src/resource.rs#L35-L37
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.
converted it back to function, copied those 3 lines. but it's loading the gresource in runtime now. is there other way to to make it compile time and include it in the binary?
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.
Yes, to call include_bytes!
macro just like above code does to store contents of a file in a constant
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.
You provide contents of the file as an argument rather than its path in that case
src/lib.rs
Outdated
pub fn initialize_icons() { | ||
gio::resources_register_include!("resources.gresource").unwrap(); | ||
#[macro_export] | ||
macro_rules! initialize_icons { |
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.
Then specify an absolute path there instead of relative
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.
From my side there are no additional objections that would prevent merging. Once @nazar-pc is satisfied as well, I suggest we merge the PR and publish a new alpha release that can be tested and gradually improved.
Also thanks for the continuous work on this PR!
91adb0e
to
133b001
Compare
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.
Almost there, also please test this if you can, I think if you did you'd see that it didn't actually work properly yet.
src/lib.rs
Outdated
let display = gdk::Display::default().unwrap(); | ||
let theme = gtk::IconTheme::for_display(&display); | ||
theme.add_resource_path("/org/gtkrs/icons/"); | ||
theme.add_resource_path("/org/gtkrs/icons/scalable/actions/"); |
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.
This does not look like an equivalent change. It only previously applied if app_id was not specified, but now it applies unconditionally despite the fact that app ID is required.
Looking at generation code, I think you'll want to store prefix
in a constant and then call initialize_icons
with it. Maybe @AaronErhardt can clarify, but I think it should not be necessary to have both resource paths, just the prefix used in generation code should be sufficient.
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.
Yeah, the code in question is more a hack than an actual documented feature of GTK. It is not strictly harmful to call it unconditionally, but if the user has specified an app ID, the path of the icons can be adjusted such that it doesn't need this hack in the first place (that's why the if
was there). We might as well deprecate or remove this code path entirely instad of relying on it.
build_icons/build.rs
Outdated
|
||
// Create file that contains the icon names as constants | ||
let constants = format!( | ||
" | ||
/// Path to the shipped icons. | ||
pub const SHIPPED_ICONS_PATH: &str = \"{}/icons\";", | ||
icons_path.display() | ||
manifest_path |
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.
This will work, but consider proper path handling, including when it has "
:
std::fs::write(
std::path::Path::new(&out_dir).join(CONSTANTS_FILE),
manifest_path.join("icons').canonicalize().to_str().unwrap(),
)
.unwrap();
Storing OsString
would be even more valid, but it requires platform-specific code to decode back on read, this way it will simply fail on non-utf8 characters at build time.
@dastansam one more push, please 🙏 |
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.
@AaronErhardt this is almost ready, please take another look when you have a chance
build_icons/build.rs
Outdated
pub const SHIPPED_ICONS_PATH: &str = \"{}\";", | ||
std::path::Path::new(&manifest_path) | ||
.join("icons") | ||
.canonicalize() | ||
.unwrap() | ||
.to_str() | ||
.unwrap() |
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.
I'll post the same code snippet again:
std::fs::write(
std::path::Path::new(&out_dir).join(CONSTANTS_FILE),
manifest_path.join("icons').canonicalize().to_str().unwrap(),
)
.unwrap();
Note that it stored the path in the file, not in the string inside of the file. Why? Because your version will result in corrupted file if path contains "
.
2d136c0
to
4120f43
Compare
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.
Looks fine to me assuming it works
Thanks for all the work! Let's test the code and work towards a new stable release :) |
This PR tries to address the issue #12 and also do a little bit of refactoring of build script:
build-utils
feature flag for crate dependents to bundle icons and save icon names in the constant.