-
Notifications
You must be signed in to change notification settings - Fork 81
[UI redesign 1/3] rog-control-center: build .mo from .po at build time #252
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,45 @@ use std::path::PathBuf; | |
|
|
||
| use slint_build::CompilerConfiguration; | ||
|
|
||
| /// Compile .po source files to .mo binaries at build time so dev builds | ||
| /// have translations without committing binary artifacts to Git. | ||
| /// Silently skips if `msgfmt` is not installed (installed packages use | ||
| /// /usr/share/locale/ instead). | ||
| fn compile_locales() { | ||
| let root = env!("CARGO_MANIFEST_DIR"); | ||
| let translations_dir = PathBuf::from(root).join("translations"); | ||
| let Ok(entries) = std::fs::read_dir(&translations_dir) else { | ||
| return; | ||
| }; | ||
| for entry in entries.flatten() { | ||
|
Comment on lines
+9
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Propagate locale compilation failures. The path fix is present, but the previous error-handling issue remains. Return a Also applies to: 26-38, 42-43 🤖 Prompt for AI Agents |
||
| // Sources live at translations/<locale>/rog-control-center.po; the | ||
| // compiled catalog goes to the gettext layout (<locale>/LC_MESSAGES/) | ||
| // that init_translations! resolves at runtime. | ||
| let po = entry.path().join("rog-control-center.po"); | ||
| if !po.exists() { | ||
| continue; | ||
| } | ||
| let mo = entry.path().join("LC_MESSAGES/rog-control-center.mo"); | ||
| // The LC_MESSAGES dir isn't tracked once the .mo are gitignored, so | ||
| // recreate it on a fresh checkout before msgfmt writes into it. | ||
| let _ = std::fs::create_dir_all(mo.parent().unwrap_or(entry.path().as_path())); | ||
| match std::process::Command::new("msgfmt").arg("-o").arg(&mo).arg(&po).status() { | ||
| Ok(status) if !status.success() => { | ||
| println!("cargo:warning=msgfmt failed for {} (status {status})", po.display()); | ||
| } | ||
| // msgfmt not installed (dev without gettext) — packaged builds use | ||
| // /usr/share/locale instead, so silently skip. | ||
| Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} | ||
| Err(e) => { | ||
| println!("cargo:warning=msgfmt could not run for {}: {e}", po.display()); | ||
| } | ||
| Ok(_) => {} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| // write_locales(); | ||
| compile_locales(); | ||
| let root = env!("CARGO_MANIFEST_DIR"); | ||
| let mut main = PathBuf::from(root); | ||
| main.push("ui/main_window.slint"); | ||
|
|
||
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: OpenGamingCollective/asusctl
Length of output: 50385
🏁 Script executed:
Repository: OpenGamingCollective/asusctl
Length of output: 50385
🏁 Script executed:
Repository: OpenGamingCollective/asusctl
Length of output: 6303
🏁 Script executed:
Repository: OpenGamingCollective/asusctl
Length of output: 8046
🌐 Web query:
Cargo build scripts rerun-if-changed directory recursive behavior slint_build compile_with_config source💡 Result:
In Cargo, the
cargo:rerun-if-changed=PATHinstruction directs Cargo to re-run a build script if the specified path changes [1][2]. When this path points to a directory, Cargo performs a recursive scan of the directory to detect modifications [1][3]. Cargo monitors for changes in file timestamps ("mtime"), and if any file or sub-directory within the specified path is modified, added, or deleted, the build script will be re-run [1][3]. This recursive behavior ensures that changes to nested source files or resources are correctly detected [3]. Regardingslint_build::compile_with_configin the Slint crate: This function is used within abuild.rsscript to compile.slintfiles [4]. As part of its operation, it internally tracks input files and dependencies associated with the Slint markup [5][6]. It automatically emitscargo:rerun-if-changedinstructions for these identified dependencies to ensure the build script triggers a re-compilation whenever those specific files change [5][6]. If you experience unexpected or redundant rebuilds, it may be due to how these paths are being tracked or if they point to non-existent or invalid locations, which can cause Cargo to consider the build "dirty" [7]. Top results: [1][3][5][7]Citations:
🏁 Script executed:
Repository: OpenGamingCollective/asusctl
Length of output: 844
🌐 Web query:
site:github.com/slint-ui/slint compile_with_config rerun-if-changed slint_build💡 Result:
When using
slint_build::compile_with_configin a Rustbuild.rsscript, you generally do not need to manually callcargo:rerun-if-changedfor your primary.slintfile or its direct dependencies, as theslint-buildcrate automatically tracks and emits these instructions to Cargo [1]. Key details regarding build script behavior with Slint: 1. Automatic Tracking: Theslint-buildcrate internally scans for dependencies (including imported.slintfiles and embedded resources) and emits the necessarycargo:rerun-if-changedlines to Cargo [1]. This ensures that your build script re-runs automatically when any of these files change [1][2]. 2. Manual Configuration: If you have additional files or resources that are not automatically detected by the Slint compiler—such as custom asset folders or configuration files—you can manually add them to yourbuild.rsusing the standard Cargo build script command [2]: println!("cargo:rerun-if-changed=path/to/your/file"); 3. Environment Variables:slint-buildalso handles common environment variables that affect the build (e.g.,SLINT_STYLE,SLINT_ASSET_SECTION) by emittingcargo:rerun-if-env-changedinstructions [1][3]. If your custom logic relies on other environment variables, you should emit these manually as well: println!("cargo:rerun-if-env-changed=YOUR_ENV_VAR"); 4. Troubleshooting Excessive Rebuilds: If you experience issues where the build script reruns unnecessarily, verify that your paths are absolute and that they do not contain dynamic elements (like incorrectly formatted paths or temporary file paths) that change across builds [3]. Common causes for "dirty" builds include misconfigured font paths or cache-invalidating environment variable changes [3][4]. For most standard projects, simply callingslint_build::compile_with_configis sufficient to keep your build in sync with your UI file changes [5][6][7].Citations:
🏁 Script executed:
Repository: OpenGamingCollective/asusctl
Length of output: 12535
Register the translation sources with Cargo.
compile_localesdoes not emit acargo:rerun-if-changeddirective for the.pofiles.slint_build::compile_with_configemits selective directives for Slint dependencies, so Cargo can skip the build script after a PO-only change. The generated.mofile can remain stale.Register the translation directory:
Proposed minimal change
let root = env!("CARGO_MANIFEST_DIR"); let translations_dir = PathBuf::from(root).join("translations"); + println!("cargo:rerun-if-changed={}", translations_dir.display());📝 Committable suggestion
🤖 Prompt for AI Agents