Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions build/configure/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
},
)
}
Expand Down
18 changes: 16 additions & 2 deletions build/ninja_gen/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,28 @@ pub enum BuildProfile {
Debug,
Release,
ReleaseWithLto,
Ci,
}

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,
_ => Self::Debug,
_ => match std::env::var("CI").unwrap_or_default().as_str() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We set RELEASE=2 in the release workflow so this has no effect there.

"true" => Self::Ci,
_ => Self::Debug,
},
}
}

/// 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,
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions build/ninja_gen/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down Expand Up @@ -131,6 +132,16 @@ 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"),
}
}

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",
}
}

Expand All @@ -147,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");
Expand All @@ -175,10 +190,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"],
Expand Down
3 changes: 1 addition & 2 deletions build/ninja_gen/src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
Expand Down
11 changes: 10 additions & 1 deletion build/ninja_gen/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
10 changes: 8 additions & 2 deletions ninja
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- $*
6 changes: 4 additions & 2 deletions tools/ninja.bat
Original file line number Diff line number Diff line change
@@ -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
Loading