From a14557a421b2283c7632036e82ef4b0d7c3e5434 Mon Sep 17 00:00:00 2001 From: Abdo Date: Thu, 9 Jul 2026 10:47:58 +0300 Subject: [PATCH 1/7] Set opt-level to 0 on CI --- Cargo.toml | 8 ++++++++ build/ninja_gen/src/build.rs | 6 +++++- build/ninja_gen/src/cargo.rs | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ca595d2f853..6e35b5ba402 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,3 +175,11 @@ debug = 0 [profile.release-lto] inherits = "release" lto = true + +[profile.ci] +inherits = "dev" +opt-level = 0 +incremental = false + +[profile.ci.package."*"] +opt-level = 0 diff --git a/build/ninja_gen/src/build.rs b/build/ninja_gen/src/build.rs index eebcbee1799..3489d965e7d 100644 --- a/build/ninja_gen/src/build.rs +++ b/build/ninja_gen/src/build.rs @@ -356,6 +356,7 @@ pub enum BuildProfile { Debug, Release, ReleaseWithLto, + Ci, } impl BuildProfile { @@ -363,7 +364,10 @@ impl BuildProfile { match std::env::var("RELEASE").unwrap_or_default().as_str() { "1" => Self::Release, "2" => Self::ReleaseWithLto, - _ => Self::Debug, + _ => match std::env::var("CI").unwrap_or_default().as_str() { + "true" => Self::Ci, + _ => Self::Debug, + }, } } } diff --git a/build/ninja_gen/src/cargo.rs b/build/ninja_gen/src/cargo.rs index 2a339770497..b1f96439454 100644 --- a/build/ninja_gen/src/cargo.rs +++ b/build/ninja_gen/src/cargo.rs @@ -72,6 +72,7 @@ fn profile_output_dir(profile: BuildProfile) -> &'static str { BuildProfile::Debug => "debug", BuildProfile::Release => "release", BuildProfile::ReleaseWithLto => "release-lto", + BuildProfile::Ci => "ci", } } @@ -131,6 +132,7 @@ fn profile_arg_for_cargo(profile: BuildProfile) -> Option<&'static str> { BuildProfile::Debug => None, BuildProfile::Release => Some("--release"), BuildProfile::ReleaseWithLto => Some("--profile release-lto"), + BuildProfile::Ci => Some("--profile ci"), } } From 6762807850ea5528275819c33ce87b3a70e7cb3e Mon Sep 17 00:00:00 2001 From: Abdo Date: Thu, 9 Jul 2026 11:44:24 +0300 Subject: [PATCH 2/7] Pass configured profile to clippy --- build/ninja_gen/src/cargo.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/ninja_gen/src/cargo.rs b/build/ninja_gen/src/cargo.rs index b1f96439454..9394fc809d7 100644 --- a/build/ninja_gen/src/cargo.rs +++ b/build/ninja_gen/src/cargo.rs @@ -177,10 +177,12 @@ pub struct CargoClippy { impl BuildAction for CargoClippy { fn command(&self) -> &str { - "cargo clippy $cargo_flags --tests -- -Dclippy::dbg_macro -Dwarnings" + "cargo clippy $release_arg $cargo_flags --tests -- -Dclippy::dbg_macro -Dwarnings" } fn files(&mut self, build: &mut impl FilesHandle) { + let release_arg = profile_arg_for_cargo(build.build_profile()).unwrap_or_default(); + build.add_variable("release_arg", release_arg); build.add_inputs( "", inputs![&self.inputs, "Cargo.lock", "rust-toolchain.toml"], From 488b4a15b580f8190d2aec136c2e0dc0f9406512 Mon Sep 17 00:00:00 2001 From: Abdo Date: Thu, 9 Jul 2026 12:14:00 +0300 Subject: [PATCH 3/7] Use CI profile for minilints/configure_bin --- build/configure/src/rust.rs | 3 +-- build/ninja_gen/src/build.rs | 10 ++++++++++ build/ninja_gen/src/configure.rs | 3 +-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build/configure/src/rust.rs b/build/configure/src/rust.rs index 8f20d4e5ade..821057fb4a8 100644 --- a/build/configure/src/rust.rs +++ b/build/configure/src/rust.rs @@ -5,7 +5,6 @@ use std::env; use anyhow::Result; use ninja_gen::action::BuildAction; -use ninja_gen::build::BuildProfile; use ninja_gen::build::FilesHandle; use ninja_gen::cargo::CargoBuild; use ninja_gen::cargo::CargoClippy; @@ -238,7 +237,7 @@ pub fn check_minilints(build: &mut Build) -> Result<()> { outputs: &[RustOutput::Binary("minilints")], target: None, extra_args: "-p minilints", - release_override: Some(BuildProfile::Debug), + release_override: Some(build.build_profile.for_build_tools()), }, ) } diff --git a/build/ninja_gen/src/build.rs b/build/ninja_gen/src/build.rs index 3489d965e7d..37c2a2c752f 100644 --- a/build/ninja_gen/src/build.rs +++ b/build/ninja_gen/src/build.rs @@ -370,6 +370,16 @@ impl BuildProfile { }, } } + + /// The profile to build helper tools like configure/minilints with: + /// never optimized, but otherwise matching the main profile so that + /// dependency builds are shared. + pub fn for_build_tools(self) -> Self { + match self { + Self::Release | Self::ReleaseWithLto => Self::Debug, + other => other, + } + } } pub trait FilesHandle { diff --git a/build/ninja_gen/src/configure.rs b/build/ninja_gen/src/configure.rs index c0fbec33a26..e93f379f711 100644 --- a/build/ninja_gen/src/configure.rs +++ b/build/ninja_gen/src/configure.rs @@ -4,7 +4,6 @@ use anyhow::Result; use crate::action::BuildAction; -use crate::build::BuildProfile; use crate::build::FilesHandle; use crate::cargo::CargoBuild; use crate::cargo::RustOutput; @@ -34,7 +33,7 @@ impl BuildAction for ConfigureBuild { outputs: &[RustOutput::Binary("configure")], target: None, extra_args: "-p configure", - release_override: Some(BuildProfile::Debug), + release_override: Some(build.build_profile.for_build_tools()), }, )?; Ok(()) From c5b622b2f1f85299358c93c3ed00430a124fc2d4 Mon Sep 17 00:00:00 2001 From: Abdo Date: Thu, 9 Jul 2026 12:14:27 +0300 Subject: [PATCH 4/7] Use CI profile for runner --- build/ninja_gen/src/build.rs | 2 +- build/ninja_gen/src/render.rs | 11 ++++++++++- ninja | 10 ++++++++-- tools/ninja.bat | 6 ++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/build/ninja_gen/src/build.rs b/build/ninja_gen/src/build.rs index 37c2a2c752f..bef6e587c4c 100644 --- a/build/ninja_gen/src/build.rs +++ b/build/ninja_gen/src/build.rs @@ -360,7 +360,7 @@ pub enum BuildProfile { } impl BuildProfile { - fn from_env() -> Self { + pub fn from_env() -> Self { match std::env::var("RELEASE").unwrap_or_default().as_str() { "1" => Self::Release, "2" => Self::ReleaseWithLto, diff --git a/build/ninja_gen/src/render.rs b/build/ninja_gen/src/render.rs index dde307e73a8..46f9dcf8d57 100644 --- a/build/ninja_gen/src/render.rs +++ b/build/ninja_gen/src/render.rs @@ -9,9 +9,17 @@ use anyhow::Result; use itertools::Itertools; use crate::archives::with_exe; +use crate::build::BuildProfile; use crate::input::space_separated; use crate::Build; +fn profile_output_dir() -> &'static str { + match BuildProfile::from_env() { + BuildProfile::Ci => "ci", + _ => "release", + } +} + impl Build { pub fn render(&self) -> String { let mut buf = String::new(); @@ -25,7 +33,8 @@ impl Build { writeln!(&mut buf, "builddir = {}", self.buildroot.as_str()).unwrap(); writeln!( &mut buf, - "runner = $builddir/rust/release/{}", + "runner = $builddir/rust/{}/{}", + profile_output_dir(), with_exe("runner") ) .unwrap(); diff --git a/ninja b/ninja index c44f8c33074..722c95e2d9d 100755 --- a/ninja +++ b/ninja @@ -10,9 +10,15 @@ fi export CARGO_TARGET_DIR=$out/rust export RECONFIGURE_KEY="${MAC_X86};${LIN_ARM64};${SOURCEMAP};${HMR}" +if [ "$CI" = "true" ] && [ -z "$RELEASE" ]; then + runner_profile=ci +else + runner_profile=release +fi + if [ "$SKIP_RUNNER_BUILD" = "1" ]; then echo "Runner not rebuilt." else - cargo build -p runner --release + cargo build -p runner --profile $runner_profile fi -exec $out/rust/release/runner build -- $* +exec $out/rust/$runner_profile/runner build -- $* diff --git a/tools/ninja.bat b/tools/ninja.bat index 6310103c3be..8a6350f4cca 100755 --- a/tools/ninja.bat +++ b/tools/ninja.bat @@ -1,5 +1,7 @@ @echo off set CARGO_TARGET_DIR=%~dp0..\out\rust +set RUNNER_PROFILE=release +if "%CI%"=="true" if "%RELEASE%"=="" set RUNNER_PROFILE=ci REM separate build+run steps so build env doesn't leak into subprocesses -cargo build -p runner --release || exit /b 1 -out\rust\release\runner build %* || exit /b 1 +cargo build -p runner --profile %RUNNER_PROFILE% || exit /b 1 +out\rust\%RUNNER_PROFILE%\runner build %* || exit /b 1 From 0a678ca3f8752aaaa07ade041ba6317b345db872 Mon Sep 17 00:00:00 2001 From: Abdo Date: Thu, 9 Jul 2026 12:14:57 +0300 Subject: [PATCH 5/7] Pass Cargo profile to cargo-nextest --- build/ninja_gen/src/cargo.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/build/ninja_gen/src/cargo.rs b/build/ninja_gen/src/cargo.rs index 9394fc809d7..98a095d89cb 100644 --- a/build/ninja_gen/src/cargo.rs +++ b/build/ninja_gen/src/cargo.rs @@ -136,6 +136,15 @@ fn profile_arg_for_cargo(profile: BuildProfile) -> Option<&'static str> { } } +fn profile_arg_for_nextest(profile: BuildProfile) -> &'static str { + match profile { + BuildProfile::Debug => "", + BuildProfile::Release => "--cargo-profile release", + BuildProfile::ReleaseWithLto => "--cargo-profile release-lto", + BuildProfile::Ci => "--cargo-profile ci", + } +} + fn setup_flags(build: &mut Build) -> Result<()> { build.once_only("cargo_flags_and_pool", |build| { build.variable("cargo_flags", "--locked"); @@ -149,10 +158,14 @@ pub struct CargoTest { impl BuildAction for CargoTest { fn command(&self) -> &str { - "cargo nextest run --color=always --failure-output=final --status-level=none $cargo_flags" + "cargo nextest run --color=always --failure-output=final --status-level=none $profile_arg $cargo_flags" } fn files(&mut self, build: &mut impl FilesHandle) { + build.add_variable( + "profile_arg", + profile_arg_for_nextest(build.build_profile()), + ); build.add_inputs("", &self.inputs); build.add_inputs("", inputs![":cargo-nextest"]); build.add_env_var("ANKI_TEST_MODE", "1"); From 168b113e3d497610baaf709c850ec1e274324795 Mon Sep 17 00:00:00 2001 From: Abdo Date: Wed, 15 Jul 2026 17:47:35 +0300 Subject: [PATCH 6/7] Update RECONFIGURE_KEY --- ninja | 2 +- tools/ninja.bat | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ninja b/ninja index 722c95e2d9d..f717905081b 100755 --- a/ninja +++ b/ninja @@ -8,7 +8,7 @@ else out="$BUILD_ROOT" fi export CARGO_TARGET_DIR=$out/rust -export RECONFIGURE_KEY="${MAC_X86};${LIN_ARM64};${SOURCEMAP};${HMR}" +export RECONFIGURE_KEY="${MAC_X86};${LIN_ARM64};${SOURCEMAP};${HMR};${CI}" if [ "$CI" = "true" ] && [ -z "$RELEASE" ]; then runner_profile=ci diff --git a/tools/ninja.bat b/tools/ninja.bat index 8a6350f4cca..db00700569b 100755 --- a/tools/ninja.bat +++ b/tools/ninja.bat @@ -1,5 +1,6 @@ @echo off set CARGO_TARGET_DIR=%~dp0..\out\rust +set "RECONFIGURE_KEY=%SOURCEMAP%;%HMR%;%CI%" set RUNNER_PROFILE=release if "%CI%"=="true" if "%RELEASE%"=="" set RUNNER_PROFILE=ci REM separate build+run steps so build env doesn't leak into subprocesses From 79cd50de8ca6d3797c0d0519744b4e60b613b1c0 Mon Sep 17 00:00:00 2001 From: Abdo Date: Wed, 15 Jul 2026 18:41:35 +0300 Subject: [PATCH 7/7] Pass profile to bootstrap_build() --- build/runner/src/build.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/build/runner/src/build.rs b/build/runner/src/build.rs index 107be9783a8..21a2efaf85e 100644 --- a/build/runner/src/build.rs +++ b/build/runner/src/build.rs @@ -153,11 +153,19 @@ fn setup_build_root() -> Utf8PathBuf { fn bootstrap_build() { let status = Command::new("cargo") - .args(["run", "-p", "configure"]) + .args(["run", "-p", "configure", "--profile", bootstrap_profile()]) .status(); assert!(status.expect("ninja").success()); } +fn bootstrap_profile() -> &'static str { + if env::var("RELEASE").is_err() && env::var("CI").as_deref() == Ok("true") { + "ci" + } else { + "dev" + } +} + fn maybe_update_buildhash(build_root: &Utf8Path) { // only updated on release builds let path = build_root.join("buildhash");