Skip to content

feat: add magic sccache integration for cmake #111

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions crates/pixi-build-cmake/src/build_script.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
ninja --version
cmake --version
{% if has_sccache -%}
sccache --version

{% if build_platform == "windows" -%}
set EXTRA_CMAKE_ARGS=-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
{% else -%}
export EXTRA_CMAKE_ARGS="-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
{% endif -%}
{% endif -%}

{# Windows #}
{% if build_platform == "windows" -%}
Expand All @@ -10,6 +19,7 @@ if not exist %SRC_DIR%\..\build\CMakeCache.txt (
-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON ^
-DBUILD_SHARED_LIBS=ON ^
%EXTRA_CMAKE_ARGS% ^
{{ extra_args | join(" ") }} ^
-B %SRC_DIR%\..\build ^
-S "{{ source_dir }}"
Expand All @@ -27,6 +37,7 @@ if [ ! -f "$SRC_DIR/../build/CMakeCache.txt" ]; then
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DBUILD_SHARED_LIBS=ON \
$EXTRA_CMAKE_ARGS \
{{ extra_args | join(" ") }} \
-B $SRC_DIR/../build \
-S "{{ source_dir }}"
Expand All @@ -37,3 +48,7 @@ cmake --build $SRC_DIR/../build --target install
{% if build_platform == "windows" -%}
@if errorlevel 1 exit 1
{% endif %}

{% if has_sccache -%}
sccache --show-stats
{% endif %}
1 change: 1 addition & 0 deletions crates/pixi-build-cmake/src/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct BuildScriptContext {
pub build_platform: BuildPlatform,
pub source_dir: String,
pub extra_args: Vec<String>,
pub has_sccache: bool,
}

#[derive(Serialize)]
Expand Down
10 changes: 9 additions & 1 deletion crates/pixi-build-cmake/src/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ impl<P: ProjectModel> CMakeBuildBackend<P> {

let noarch_type = NoArchType::none();

let requirements = self.requirements(host_platform, channel_config, variant)?;
let mut requirements = self.requirements(host_platform, channel_config, variant)?;

let has_sccache = std::env::vars().any(|(key, _)| key.starts_with("SCCACHE"));
if has_sccache {
requirements
.build
.push(Dependency::Spec("sccache".parse().unwrap()));
}

let build_platform = Platform::current();
let build_number = 0;
Expand All @@ -124,6 +131,7 @@ impl<P: ProjectModel> CMakeBuildBackend<P> {
},
source_dir: self.manifest_root.display().to_string(),
extra_args: self.config.extra_args.clone(),
has_sccache,
}
.render();

Expand Down