Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ AGENTS.md

*.log

# Compiled gettext binaries — .po sources are tracked, .mo are build artifacts
# compiled from source at build time (see rog-control-center/build.rs).
*.mo

# Git should not follow this IN ANY CASE
Cargo.lock
39 changes: 38 additions & 1 deletion rog-control-center/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Comment on lines +11 to +12

Copy link
Copy Markdown

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:

#!/bin/bash
set -eu
printf '%s\n' '--- build.rs ---'
cat -n rog-control-center/build.rs
printf '%s\n' '--- build-script related configuration ---'
rg -n -C 4 'slint_build|compile_with_config|rerun-if-changed|compile_locales|translations|gettext|po|mo' rog-control-center Cargo.toml Cargo.lock 2>/dev/null || true
printf '%s\n' '--- relevant tracked files ---'
git ls-files 'rog-control-center/*' | rg '(^|/)(build\.rs|.*\.(po|mo)|Cargo\.toml)$' || true

Repository: OpenGamingCollective/asusctl

Length of output: 50385


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- build.rs ---'
cat -n rog-control-center/build.rs
printf '%s\n' '--- build-script references ---'
rg -n -C 5 'slint_build|compile_with_config|rerun-if-changed|compile_locales|translations|gettext|po|mo' rog-control-center Cargo.toml Cargo.lock 2>/dev/null || true
printf '%s\n' '--- relevant tracked files ---'
git ls-files 'rog-control-center/*' | rg '(^|/)(build\.rs|.*\.(po|mo)|Cargo\.toml)$' || true

Repository: OpenGamingCollective/asusctl

Length of output: 50385


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- rog-control-center/build.rs ---'
sed -n '1,140p' rog-control-center/build.rs
printf '%s\n' '--- rog-control-center/Cargo.toml build configuration ---'
rg -n -C 8 'build\s*=|slint-build|gettext|compile' rog-control-center/Cargo.toml
printf '%s\n' '--- build-script APIs and rerun directives ---'
rg -n -C 6 'slint_build|compile_with_config|rerun-if-changed|compile_locales' --glob '!rog-control-center/translations/**' --glob '!Cargo.lock' .
printf '%s\n' '--- translation files ---'
git ls-files 'rog-control-center/translations/**' | sed -n '1,120p'
printf '%s\n' '--- generated MO files ---'
git ls-files | rg '(^|/)[^/]+\.mo$' || true

Repository: OpenGamingCollective/asusctl

Length of output: 6303


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- pinned Slint revision ---'
rg -n -A12 -B3 '^name = "slint-build"$|^name = "slint"$' Cargo.lock
printf '%s\n' '--- local Cargo source cache candidates ---'
find "${HOME}/.cargo" -maxdepth 5 -type f \( -path '*slint-build*/src/*.rs' -o -name 'build.rs' \) 2>/dev/null | sed -n '1,80p' || true

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=PATH instruction 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]. Regarding slint_build::compile_with_config in the Slint crate: This function is used within a build.rs script to compile .slint files [4]. As part of its operation, it internally tracks input files and dependencies associated with the Slint markup [5][6]. It automatically emits cargo:rerun-if-changed instructions 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:

#!/bin/bash
set -eu
printf '%s\n' '--- exact Slint lockfile entries ---'
awk '
  /^name = "(slint|slint-build)"$/ {show=1; n=0}
  show {print; n++}
  show && n >= 14 {show=0}
' Cargo.lock

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_config in a Rust build.rs script, you generally do not need to manually call cargo:rerun-if-changed for your primary .slint file or its direct dependencies, as the slint-build crate automatically tracks and emits these instructions to Cargo [1]. Key details regarding build script behavior with Slint: 1. Automatic Tracking: The slint-build crate internally scans for dependencies (including imported .slint files and embedded resources) and emits the necessary cargo:rerun-if-changed lines 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 your build.rs using the standard Cargo build script command [2]: println!("cargo:rerun-if-changed=path/to/your/file"); 3. Environment Variables: slint-build also handles common environment variables that affect the build (e.g., SLINT_STYLE, SLINT_ASSET_SECTION) by emitting cargo:rerun-if-env-changed instructions [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 calling slint_build::compile_with_config is sufficient to keep your build in sync with your UI file changes [5][6][7].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu
url='https://raw.githubusercontent.com/slint-ui/slint/2c94caa2b439c8b4476a63866b00b3001307aad1/api/rs/build/lib.rs'
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
curl --fail --silent --show-error "$url" > "$tmp"
printf '%s\n' '--- rerun directives in pinned slint-build source ---'
rg -n -C 8 'rerun-if-changed|compile_with_config|print_rustc_flags' "$tmp"
printf '%s\n' '--- Cargo documentation wording ---'
curl --fail --silent --show-error 'https://doc.rust-lang.org/cargo/reference/build-scripts.html' |
  sed -n '/rerun-if-changed/,/rerun-if-env-changed/p' |
  sed -n '1,100p'

Repository: OpenGamingCollective/asusctl

Length of output: 12535


Register the translation sources with Cargo.

compile_locales does not emit a cargo:rerun-if-changed directive for the .po files. slint_build::compile_with_config emits selective directives for Slint dependencies, so Cargo can skip the build script after a PO-only change. The generated .mo file 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let translations_dir = PathBuf::from(root).join("translations");
let Ok(entries) = std::fs::read_dir(&translations_dir) else {
let root = env!("CARGO_MANIFEST_DIR");
let translations_dir = PathBuf::from(root).join("translations");
println!("cargo:rerun-if-changed={}", translations_dir.display());
let Ok(entries) = std::fs::read_dir(&translations_dir) else {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rog-control-center/build.rs` around lines 11 - 12, Update compile_locales to
emit a cargo:rerun-if-changed directive for translations_dir before reading the
directory, ensuring Cargo reruns the build script when any PO translation source
changes. Leave the existing directory-reading and locale compilation flow
unchanged.

return;
};
for entry in entries.flatten() {
Comment on lines +9 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Propagate locale compilation failures.

The path fix is present, but the previous error-handling issue remains. read_dir and individual directory-entry errors are discarded. create_dir_all errors are ignored. A non-zero msgfmt status only emits a warning. An old ignored .mo can remain after a failed or removed translation source.

Return a Result, propagate filesystem errors, fail on non-zero msgfmt status, and remove or atomically replace generated catalogs.

Also applies to: 26-38, 42-43

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rog-control-center/build.rs` around lines 9 - 15, Update compile_locales to
return a Result and propagate read_dir, directory-entry, create_dir_all, and
file-operation errors instead of discarding them; make non-zero msgfmt status
return an error rather than only warn. Ensure generated .mo catalogs are removed
or atomically replaced when compilation fails or a translation source is
removed, and update the caller to handle the propagated result.

// 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");
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.