|
2 | 2 |
|
3 | 3 | #![doc = include_str!("../README.md")] |
4 | 4 |
|
5 | | -use gio::glib; |
6 | | -use std::{ |
7 | | - env, |
8 | | - path::{Path, PathBuf}, |
9 | | - process::Command, |
10 | | -}; |
| 5 | +use std::{env, path::Path, process::Command}; |
11 | 6 |
|
12 | 7 | // rustdoc-stripper-ignore-next |
13 | 8 | /// Call to run `glib-compile-resources` to generate compiled gresources to embed |
@@ -65,36 +60,27 @@ pub fn compile_resources<P: AsRef<Path>>(source_dirs: &[P], gresource: &str, tar |
65 | 60 |
|
66 | 61 | // rustdoc-stripper-ignore-next |
67 | 62 | /// Call to run `glib-compile-schemas` to generate compiled gschemas from `.gschema.xml` schemas |
68 | | -/// files from specified directories and store `gschemas.compiled` into `glib-2.0` schema cache |
69 | | -/// directory. |
70 | | -/// |
71 | | -/// If `target_dir` is `None`, the default schema cache directory is used: |
72 | | -/// - Unix: `$HOME/.local/share/glib-2.0/schemas/` |
73 | | -/// - Windows: `C:/ProgramData/glib-2.0/schemas/` |
| 63 | +/// files. |
74 | 64 | /// |
75 | 65 | /// ```no_run |
76 | 66 | /// glib_build_tools::compile_schemas( |
77 | | -/// &["schemas"], |
78 | | -/// None |
| 67 | +/// &["schemas"] |
79 | 68 | /// ); |
80 | 69 | /// ``` |
81 | | -pub fn compile_schemas(schemas_dir: &[&str], target_dir: Option<&str>) { |
82 | | - let target_dir = match target_dir { |
83 | | - Some(base) => PathBuf::from(base), |
84 | | - None => { |
85 | | - let prefix = if cfg!(windows) { |
86 | | - PathBuf::from("C:/ProgramData") |
87 | | - } else { |
88 | | - glib::user_data_dir() |
89 | | - }; |
90 | | - |
91 | | - Path::new(&prefix).join("glib-2.0").join("schemas") |
92 | | - } |
93 | | - }; |
| 70 | +pub fn compile_schemas(schemas_dir: &[&str]) { |
| 71 | + let out_dir = env::var("OUT_DIR").unwrap(); |
| 72 | + let out_dir = Path::new(&out_dir); |
| 73 | + |
| 74 | + let target_dir = out_dir.join("gschemas"); |
94 | 75 |
|
95 | 76 | // Ensure target_dir exists |
96 | 77 | std::fs::create_dir_all(&target_dir).expect("Failed to create target directory"); |
97 | 78 |
|
| 79 | + println!( |
| 80 | + "cargo:rustc-env=GSETTINGS_SCHEMA_DIR={}", |
| 81 | + target_dir.to_str().unwrap() |
| 82 | + ); |
| 83 | + |
98 | 84 | // Recursively copy all files with .gschema.xml extension from schema_dir to target_dir |
99 | 85 | for schema_dir in schemas_dir { |
100 | 86 | let entries = Path::new(schema_dir) |
|
0 commit comments