Skip to content
Open
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
28 changes: 28 additions & 0 deletions crates/openlogi-desktop/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn main() {
// unrelated change happens to recompile this crate.
println!("cargo:rerun-if-changed=../openlogi-ui/locales");

reserve_debug_main_stack("openlogi-desktop");
embed_windows_resources();

let out = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR"));
Expand Down Expand Up @@ -58,6 +59,33 @@ fn main() {
fs::write(out.join("builtin_themes.rs"), generated).expect("write builtin_themes.rs");
}

/// Give a debug build's main thread a 2 MiB stack on Windows, where the OS
/// reserves 1 MiB and Rust gives every other thread 2 MiB.
///
/// `rust_i18n::i18n!` expands all of `../openlogi-ui/locales` into the
/// initializer of `_RUST_I18N_BACKEND`, one `HashMap` literal per catalog.
/// Unoptimized, that closure keeps every entry on the stack until the map
/// takes it: its prologue asks `__chkstk` for 0x1352C0 bytes (1.21 MiB) and
/// the first `t!` on the main thread dies with `STATUS_STACK_OVERFLOW`
/// before the window opens. Release inlines the closure and keeps nothing
/// on the stack, so it is left alone. Only the named binary gets the flag;
/// test harnesses translate on their own 2 MiB threads and need none.
///
/// Kept in sync with the twin in `crates/openlogi-overlay/build.rs`.
fn reserve_debug_main_stack(binary: &str) {
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows")
|| env::var("PROFILE").as_deref() != Ok("debug")
{
return;
}
let arg = if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
"/STACK:2097152"
} else {
"-Wl,--stack,2097152"
};
println!("cargo:rustc-link-arg-bin={binary}={arg}");
}

/// Embed the Windows exe resources — the app icon and a VERSIONINFO block —
/// so Explorer, the taskbar, and Task Manager stop showing the generic blank
/// binary. The `.rc` is generated here rather than committed so the version
Expand Down
29 changes: 29 additions & 0 deletions crates/openlogi-overlay/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fn main() {
// unrelated change happens to recompile this crate.
println!("cargo:rerun-if-changed=../openlogi-ui/locales");

reserve_debug_main_stack("openlogi-overlay");

if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}
Expand Down Expand Up @@ -82,3 +84,30 @@ END
.manifest_optional()
.expect("compile Windows resources");
}

/// Give a debug build's main thread a 2 MiB stack on Windows, where the OS
/// reserves 1 MiB and Rust gives every other thread 2 MiB.
///
/// `rust_i18n::i18n!` expands all of `../openlogi-ui/locales` into the
/// initializer of `_RUST_I18N_BACKEND`, one `HashMap` literal per catalog.
/// Unoptimized, that closure keeps every entry on the stack until the map
/// takes it: its prologue asks `__chkstk` for 0x1352C0 bytes (1.21 MiB) and
/// the first `t!` on the main thread dies with `STATUS_STACK_OVERFLOW`
/// before the ring opens. Release inlines the closure and keeps nothing on
/// the stack, so it is left alone. Only the named binary gets the flag; test
/// harnesses translate on their own 2 MiB threads and need none.
///
/// Kept in sync with the twin in `crates/openlogi-desktop/build.rs`.
fn reserve_debug_main_stack(binary: &str) {
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows")
|| env::var("PROFILE").as_deref() != Ok("debug")
{
return;
}
let arg = if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
"/STACK:2097152"
} else {
"-Wl,--stack,2097152"
};
println!("cargo:rustc-link-arg-bin={binary}={arg}");
}
Loading