Skip to content
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

fix: add noarch config #29

Merged
merged 4 commits into from
Dec 3, 2024
Merged
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
13 changes: 8 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ parking_lot = "0.12.3"
reqwest = "0.12.5"
reqwest-middleware = "0.4.0"
serde = "1.0"
serde_yaml = "0.9.33"
serde_yaml = "0.9"
serde_json = "1.0"
tempfile = "3.10.1"
tokio = "1.37.0"
tracing-subscriber = "0.3.19"
Expand Down
1 change: 1 addition & 0 deletions crates/pixi-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_yaml = { workspace = true }
serde_json = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
tracing-subscriber = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi-build/src/bin/pixi-build-cmake/build_script.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ninja --version
cmake --version

# Windows
{# Windows #}
{% if build_platform == "windows" -%}
if not exist %SRC_DIR%\..\build\CMakeCache.txt (
cmake %CMAKE_ARGS% ^
Expand All @@ -16,7 +16,7 @@ if not exist %SRC_DIR%\..\build\CMakeCache.txt (
cmake --build %SRC_DIR%\..\build --target install
@if errorlevel 1 exit 1

# Non-Windows
{# Non Windows #}
{% else -%}
if [ ! -f "$SRC_DIR/../build/CMakeCache.txt" ]; then
cmake $CMAKE_ARGS \
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi-build/src/bin/pixi-build-cmake/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ impl BuildScriptContext {
.template_from_str(include_str!("build_script.j2"))
.unwrap();
let rendered = template.render(self).unwrap().to_string();
rendered.split("\n").map(|s| s.to_string()).collect()
rendered.lines().map(|s| s.to_string()).collect()
}
}
27 changes: 23 additions & 4 deletions crates/pixi-build/src/bin/pixi-build-cmake/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{

use chrono::Utc;
use itertools::Itertools;
use jsonrpc_core::serde_json;
use miette::{Context, IntoDiagnostic};
use pixi_build_backend::{
dependencies::extract_dependencies,
Expand Down Expand Up @@ -48,12 +49,14 @@ use reqwest::Url;

use crate::{
build_script::{BuildPlatform, BuildScriptContext},
config::CMakeBackendConfig,
stub::default_compiler,
};

pub struct CMakeBuildBackend {
logging_output_handler: LoggingOutputHandler,
manifest: Manifest,
_config: CMakeBackendConfig,
cache_dir: Option<PathBuf>,
}

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

Ok(Self {
manifest,
_config: config,
logging_output_handler,
cache_dir,
})
Expand Down Expand Up @@ -556,8 +561,17 @@ impl ProtocolFactory for CMakeBuildBackendFactory {
&self,
params: InitializeParams,
) -> miette::Result<(Self::Protocol, InitializeResult)> {
let config = if params.configuration.is_null() {
CMakeBackendConfig::default()
} else {
serde_json::from_value(params.configuration)
.into_diagnostic()
.context("failed to parse backend configuration")?
};

let instance = CMakeBuildBackend::new(
params.manifest_path.as_path(),
config,
self.logging_output_handler.clone(),
params.cache_directory,
)?;
Expand All @@ -569,14 +583,14 @@ impl ProtocolFactory for CMakeBuildBackendFactory {

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use pixi_manifest::Manifest;
use rattler_build::console_utils::LoggingOutputHandler;
use rattler_conda_types::{ChannelConfig, Platform};
use std::path::PathBuf;
use tempfile::tempdir;

use crate::cmake::CMakeBuildBackend;
use crate::{cmake::CMakeBuildBackend, config::CMakeBackendConfig};

#[tokio::test]
async fn test_setting_host_and_build_requirements() {
Expand Down Expand Up @@ -614,8 +628,13 @@ mod tests {

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

let cmake_backend =
CMakeBuildBackend::new(&manifest.path, LoggingOutputHandler::default(), None).unwrap();
let cmake_backend = CMakeBuildBackend::new(
&manifest.path,
CMakeBackendConfig::default(),
LoggingOutputHandler::default(),
None,
)
.unwrap();

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

Expand Down
5 changes: 5 additions & 0 deletions crates/pixi-build/src/bin/pixi-build-cmake/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use serde::Deserialize;

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CMakeBackendConfig {}
1 change: 1 addition & 0 deletions crates/pixi-build/src/bin/pixi-build-cmake/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod build_script;
mod cmake;
mod config;
mod stub;

use cmake::CMakeBuildBackend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ impl BuildScriptContext {
.template_from_str(include_str!("build_script.j2"))
.unwrap();
let rendered = template.render(self).unwrap().to_string();
rendered.split("\n").map(|s| s.to_string()).collect()
rendered.lines().map(|s| s.to_string()).collect()
}
}
19 changes: 19 additions & 0 deletions crates/pixi-build/src/bin/pixi-build-python/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::convert::identity;

use serde::Deserialize;

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct PythonBackendConfig {
/// True if the package should be build as a python noarch package. Defaults
/// to `true`.
#[serde(default)]
pub noarch: Option<bool>,
}

impl PythonBackendConfig {
/// Whether to build a noarch package or a platform-specific package.
pub fn noarch(&self) -> bool {
self.noarch.map_or(true, identity)
}
}
1 change: 1 addition & 0 deletions crates/pixi-build/src/bin/pixi-build-python/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod build_script;
mod config;
mod python;

use python::PythonBuildBackend;
Expand Down
Loading
Loading