Skip to content

Commit cf0aa74

Browse files
authored
fix: add noarch config (#29)
1 parent eaddfd0 commit cf0aa74

File tree

16 files changed

+199
-24
lines changed

16 files changed

+199
-24
lines changed

Cargo.lock

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ parking_lot = "0.12.3"
2020
reqwest = "0.12.5"
2121
reqwest-middleware = "0.4.0"
2222
serde = "1.0"
23-
serde_yaml = "0.9.33"
23+
serde_yaml = "0.9"
24+
serde_json = "1.0"
2425
tempfile = "3.10.1"
2526
tokio = "1.37.0"
2627
tracing-subscriber = "0.3.19"

crates/pixi-build/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ reqwest = { workspace = true }
2323
reqwest-middleware = { workspace = true }
2424
serde = { workspace = true, features = ["derive"] }
2525
serde_yaml = { workspace = true }
26+
serde_json = { workspace = true }
2627
tempfile = { workspace = true }
2728
tokio = { workspace = true, features = ["macros"] }
2829
tracing-subscriber = { workspace = true }

crates/pixi-build/src/bin/pixi-build-cmake/build_script.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ninja --version
22
cmake --version
33

4-
# Windows
4+
{# Windows #}
55
{% if build_platform == "windows" -%}
66
if not exist %SRC_DIR%\..\build\CMakeCache.txt (
77
cmake %CMAKE_ARGS% ^
@@ -16,7 +16,7 @@ if not exist %SRC_DIR%\..\build\CMakeCache.txt (
1616
cmake --build %SRC_DIR%\..\build --target install
1717
@if errorlevel 1 exit 1
1818

19-
# Non-Windows
19+
{# Non Windows #}
2020
{% else -%}
2121
if [ ! -f "$SRC_DIR/../build/CMakeCache.txt" ]; then
2222
cmake $CMAKE_ARGS \

crates/pixi-build/src/bin/pixi-build-cmake/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ impl BuildScriptContext {
2121
.template_from_str(include_str!("build_script.j2"))
2222
.unwrap();
2323
let rendered = template.render(self).unwrap().to_string();
24-
rendered.split("\n").map(|s| s.to_string()).collect()
24+
rendered.lines().map(|s| s.to_string()).collect()
2525
}
2626
}

crates/pixi-build/src/bin/pixi-build-cmake/cmake.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{
88

99
use chrono::Utc;
1010
use itertools::Itertools;
11+
use jsonrpc_core::serde_json;
1112
use miette::{Context, IntoDiagnostic};
1213
use pixi_build_backend::{
1314
dependencies::extract_dependencies,
@@ -48,12 +49,14 @@ use reqwest::Url;
4849

4950
use crate::{
5051
build_script::{BuildPlatform, BuildScriptContext},
52+
config::CMakeBackendConfig,
5153
stub::default_compiler,
5254
};
5355

5456
pub struct CMakeBuildBackend {
5557
logging_output_handler: LoggingOutputHandler,
5658
manifest: Manifest,
59+
_config: CMakeBackendConfig,
5760
cache_dir: Option<PathBuf>,
5861
}
5962

@@ -72,6 +75,7 @@ impl CMakeBuildBackend {
7275
/// at the given path.
7376
pub fn new(
7477
manifest_path: &Path,
78+
config: CMakeBackendConfig,
7579
logging_output_handler: LoggingOutputHandler,
7680
cache_dir: Option<PathBuf>,
7781
) -> miette::Result<Self> {
@@ -82,6 +86,7 @@ impl CMakeBuildBackend {
8286

8387
Ok(Self {
8488
manifest,
89+
_config: config,
8590
logging_output_handler,
8691
cache_dir,
8792
})
@@ -556,8 +561,17 @@ impl ProtocolFactory for CMakeBuildBackendFactory {
556561
&self,
557562
params: InitializeParams,
558563
) -> miette::Result<(Self::Protocol, InitializeResult)> {
564+
let config = if params.configuration.is_null() {
565+
CMakeBackendConfig::default()
566+
} else {
567+
serde_json::from_value(params.configuration)
568+
.into_diagnostic()
569+
.context("failed to parse backend configuration")?
570+
};
571+
559572
let instance = CMakeBuildBackend::new(
560573
params.manifest_path.as_path(),
574+
config,
561575
self.logging_output_handler.clone(),
562576
params.cache_directory,
563577
)?;
@@ -569,14 +583,14 @@ impl ProtocolFactory for CMakeBuildBackendFactory {
569583

570584
#[cfg(test)]
571585
mod tests {
586+
use std::path::PathBuf;
572587

573588
use pixi_manifest::Manifest;
574589
use rattler_build::console_utils::LoggingOutputHandler;
575590
use rattler_conda_types::{ChannelConfig, Platform};
576-
use std::path::PathBuf;
577591
use tempfile::tempdir;
578592

579-
use crate::cmake::CMakeBuildBackend;
593+
use crate::{cmake::CMakeBuildBackend, config::CMakeBackendConfig};
580594

581595
#[tokio::test]
582596
async fn test_setting_host_and_build_requirements() {
@@ -614,8 +628,13 @@ mod tests {
614628

615629
let manifest = Manifest::from_str(&tmp_manifest, package_with_host_and_build_deps).unwrap();
616630

617-
let cmake_backend =
618-
CMakeBuildBackend::new(&manifest.path, LoggingOutputHandler::default(), None).unwrap();
631+
let cmake_backend = CMakeBuildBackend::new(
632+
&manifest.path,
633+
CMakeBackendConfig::default(),
634+
LoggingOutputHandler::default(),
635+
None,
636+
)
637+
.unwrap();
619638

620639
let channel_config = ChannelConfig::default_with_root_dir(PathBuf::new());
621640

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use serde::Deserialize;
2+
3+
#[derive(Debug, Default, Deserialize)]
4+
#[serde(rename_all = "kebab-case")]
5+
pub struct CMakeBackendConfig {}

crates/pixi-build/src/bin/pixi-build-cmake/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod build_script;
22
mod cmake;
3+
mod config;
34
mod stub;
45

56
use cmake::CMakeBuildBackend;

crates/pixi-build/src/bin/pixi-build-python/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ impl BuildScriptContext {
3838
.template_from_str(include_str!("build_script.j2"))
3939
.unwrap();
4040
let rendered = template.render(self).unwrap().to_string();
41-
rendered.split("\n").map(|s| s.to_string()).collect()
41+
rendered.lines().map(|s| s.to_string()).collect()
4242
}
4343
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::convert::identity;
2+
3+
use serde::Deserialize;
4+
5+
#[derive(Debug, Default, Deserialize)]
6+
#[serde(rename_all = "kebab-case")]
7+
pub struct PythonBackendConfig {
8+
/// True if the package should be build as a python noarch package. Defaults
9+
/// to `true`.
10+
#[serde(default)]
11+
pub noarch: Option<bool>,
12+
}
13+
14+
impl PythonBackendConfig {
15+
/// Whether to build a noarch package or a platform-specific package.
16+
pub fn noarch(&self) -> bool {
17+
self.noarch.map_or(true, identity)
18+
}
19+
}

crates/pixi-build/src/bin/pixi-build-python/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod build_script;
2+
mod config;
23
mod python;
34

45
use python::PythonBuildBackend;

0 commit comments

Comments
 (0)