Implement glib_build_tools::compile_schemas#1721
Implement glib_build_tools::compile_schemas#1721shahradelahi wants to merge 2 commits intogtk-rs:mainfrom
glib_build_tools::compile_schemas#1721Conversation
|
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.
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.
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.
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.
Why a hardcoded path on windows?
There was a problem hiding this comment.
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.
Should also be g_get_user_data_dir() on Windows too or not?
There was a problem hiding this comment.
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.
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.
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.
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.
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.
@sdroege Here is a demo: https://github.com/shahradelahi/todo-gtk-rs
There was a problem hiding this comment.
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.
| std::fs::create_dir_all(&target_dir).expect("Failed to create target directory"); | ||
|
|
||
| println!( | ||
| "cargo:rustc-env=GSETTINGS_SCHEMA_DIR={}", |
This PR adds a build‑time utility,
compile_schemas, to theglib_build_toolscrate.It generates the
gschemas.compiledfile by copying all.gschema.xmlfiles from the specified directories into theglib-2.0/schemascache directory and then runningglib-compile-schemas --strictto compile them.