-
-
Notifications
You must be signed in to change notification settings - Fork 126
Implement glib_build_tools::compile_schemas
#1721
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
base: main
Are you sure you want to change the base?
Conversation
Please squash the commits and provide a meaningful commit message (and PR description) for what this is actually doing. |
glib-build-tools/src/lib.rs
Outdated
let prefix = if cfg!(windows) { | ||
PathBuf::from("C:/ProgramData") | ||
} else { | ||
glib::user_data_dir() | ||
}; |
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 hardcoding the prefix to use is meh. Either the prefix will have to be passed as a param or this function won't land as is.
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’re right; the prefix can also be /usr/share/
.
c2386b2
to
d7acbd3
Compare
glib-build-tools/src/lib.rs
Outdated
/// glib_build_tools::compile_schemas( | ||
/// &["schemas"], | ||
/// None |
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.
Please document the default target_dir.
glib-build-tools/src/lib.rs
Outdated
Some(base) => PathBuf::from(base), | ||
None => { | ||
let prefix = if cfg!(windows) { | ||
PathBuf::from("C:/ProgramData") |
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 a hardcoded path on windows?
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 looked everywhere, but I couldn’t find any information on where the target directory is on Windows. The paths are based on the gtk-rs.org documentation.
https://gtk-rs.org/gtk4-rs/stable/latest/book/settings.html
https://man.archlinux.org/man/core/glib2/glib-compile-schemas.1.en
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.
Should also be g_get_user_data_dir()
on Windows too or not?
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.
Also there's the extra complication that on Windows IIRC these things are relative to the executable (or library?) path. This needs some further investigation in any case.
d7acbd3
to
525f2c2
Compare
…gs schemas It generates the `gschemas.compiled` file by copying all `.gschema.xml` files from the specified directories into the `glib-2.0/schemas` cache directory and then running `glib-compile-schemas --strict` to compile them.
525f2c2
to
2f29eac
Compare
@sdroege a review please |
}; | ||
|
||
// Ensure target_dir exists | ||
std::fs::create_dir_all(&target_dir).expect("Failed to create target directory"); |
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.
Installing things as part of build.rs
is an anti-pattern and unexpected. You should not place (or modify) anything outside of OUT_DIR
, see https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
println!( | ||
"cargo:rustc-env=GSETTINGS_SCHEMA_DIR={}", | ||
target_dir.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.
https://docs.gtk.org/gio/overview.html#running-gio-applications
GSETTINGS_SCHEMA_DIR. This variable can be set to the names of directories to consider when looking for compiled schemas for GSettings, in addition to the glib-2.0/schemas subdirectories of the XDG system data directories. To specify multiple directories, use G_SEARCHPATH_SEPARATOR_S as a separator.
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.
But this is passing the environment variable to rustc, it doesn't make your application run with it
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 can run the application this way, but of course, the compiled schema binary must be installed in the glib-2.0/schemas
directory within one of the directories listed in XDG_DATA_DIRS
.
I'm trying to implement a similar approach to compile_resources
. After reading through the GLib source code, I couldn't find anything—unless I'm missing something.
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.
@sdroege Here is a demo: https://github.com/shahradelahi/todo-gtk-rs
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 don't think this makes sense really. The correct way for all this is to install the schemas in the right location and the environment variable is meant for uninstalled usage or special setups.
cargo has no mechanism for installing anything but an executable, so the usual solution for this is to put another, proper build system around cargo. E.g. having a Makefile (which hopefully does things correctly enough), or using meson or cmake.
I don't think what you're trying to achieve here (installing schemas) is possible with cargo in its current form but would need more features in cargo first.
|
||
// Ensure target_dir exists | ||
std::fs::create_dir_all(&target_dir).expect("Failed to create target directory"); | ||
|
||
println!( | ||
"cargo:rustc-env=GSETTINGS_SCHEMA_DIR={}", |
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.
How would this be used?
This PR adds a build‑time utility,
compile_schemas
, to theglib_build_tools
crate.It generates the
gschemas.compiled
file by copying all.gschema.xml
files from the specified directories into theglib-2.0/schemas
cache directory and then runningglib-compile-schemas --strict
to compile them.