Skip to content

Commit

Permalink
Merge pull request #19 from nichmor/fix/pass-host-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra authored Nov 28, 2024
2 parents 7787729 + 8783ecf commit 7cb28e6
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 27 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ jsonrpc-core = "18.0.0"

url = "2.5.3"



rattler-build = { git = "https://github.com/prefix-dev/rattler-build", branch = "main", default-features = false }


rattler_conda_types = { version = "0.29.1", default-features = false }
rattler_package_streaming = { version = "0.22.14", default-features = false }
rattler_virtual_packages = { version = "1.1.10", default-features = false }
Expand Down
112 changes: 102 additions & 10 deletions crates/pixi-build/src/bin/pixi-build-cmake/cmake.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
borrow::Cow,
collections::BTreeMap,
path::{Path, PathBuf},
str::FromStr,
Expand Down Expand Up @@ -106,23 +107,31 @@ impl CMakeBuildBackend {
channel_config: &ChannelConfig,
) -> miette::Result<Requirements> {
let mut requirements = Requirements::default();
let default_features = [self.manifest.default_feature()];
let package = self.manifest.package.clone().ok_or_else(|| {
miette::miette!(
"manifest {} does not contains [package] section",
self.manifest.path.display()
)
})?;

let targets = package.targets.resolve(Some(host_platform)).collect_vec();

// Get all different feature types
let run_dependencies = Dependencies::from(
default_features
targets
.iter()
.filter_map(|f| f.dependencies(SpecType::Run, Some(host_platform))),
.filter_map(|f| f.dependencies(SpecType::Run).cloned().map(Cow::Owned)),
);
let mut host_dependencies = Dependencies::from(
default_features

let build_dependencies = Dependencies::from(
targets
.iter()
.filter_map(|f| f.dependencies(SpecType::Host, Some(host_platform))),
.filter_map(|f| f.dependencies(SpecType::Build).cloned().map(Cow::Owned)),
);
let build_dependencies = Dependencies::from(
default_features

let mut host_dependencies = Dependencies::from(
targets
.iter()
.filter_map(|f| f.dependencies(SpecType::Build, Some(host_platform))),
.filter_map(|f| f.dependencies(SpecType::Host).cloned().map(Cow::Owned)),
);

// Ensure build tools are available in the host dependencies section.
Expand Down Expand Up @@ -575,3 +584,86 @@ impl ProtocolFactory for CMakeBuildBackendFactory {
Ok((instance, InitializeResult { capabilities }))
}
}

#[cfg(test)]
mod tests {

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

use crate::cmake::CMakeBuildBackend;

#[tokio::test]
async fn test_setting_host_and_build_requirements() {
// get cargo manifest dir

let package_with_host_and_build_deps = r#"
[workspace]
name = "test-reqs"
channels = ["conda-forge"]
platforms = ["osx-arm64"]
preview = ["pixi-build"]
[package]
name = "test-reqs"
version = "1.0"
[host-dependencies]
hatchling = "*"
[build-dependencies]
boltons = "*"
[build-system]
build-backend = "pixi-build-cmake"
dependencies = []
channels = []
"#;

let tmp_dir = tempdir().unwrap();
let tmp_manifest = tmp_dir.path().join("pixi.toml");

// write the raw string into the file
std::fs::write(&tmp_manifest, package_with_host_and_build_deps).unwrap();

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 channel_config = ChannelConfig::default_with_root_dir(PathBuf::new());

let host_platform = Platform::current();

let reqs = cmake_backend
.requirements(host_platform, &channel_config)
.unwrap();

let host_reqs = reqs
.host
.iter()
.map(|d| match d {
Dependency::Spec(spec) => spec.to_string(),
_ => "".to_string(),
})
.collect::<Vec<String>>();

let build_reqs = reqs
.build
.iter()
.map(|d| match d {
Dependency::Spec(spec) => spec.to_string(),
_ => "".to_string(),
})
.collect::<Vec<String>>();

assert!(host_reqs.contains(&"hatchling *".to_string()));
assert!(!host_reqs.contains(&"boltons *".to_string()));

assert!(build_reqs.contains(&"boltons *".to_string()));
assert!(!host_reqs.contains(&"hatcling *".to_string()));
}
}
114 changes: 104 additions & 10 deletions crates/pixi-build/src/bin/pixi-build-python/python.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::{
borrow::Cow,
collections::BTreeMap,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
};

use chrono::Utc;
use itertools::Itertools;
use miette::{Context, IntoDiagnostic};
use pixi_build_backend::{
dependencies::MatchspecExtractor,
Expand Down Expand Up @@ -102,23 +104,31 @@ impl PythonBuildBackend {
channel_config: &ChannelConfig,
) -> miette::Result<(Requirements, Installer)> {
let mut requirements = Requirements::default();
let default_features = [self.manifest.default_feature()];
let package = self.manifest.package.clone().ok_or_else(|| {
miette::miette!(
"manifest {} does not contains [package] section",
self.manifest.path.display()
)
})?;

let targets = package.targets.resolve(Some(host_platform)).collect_vec();

// Get all different feature types
let run_dependencies = Dependencies::from(
default_features
targets
.iter()
.filter_map(|f| f.dependencies(SpecType::Run, Some(host_platform))),
.filter_map(|f| f.dependencies(SpecType::Run).cloned().map(Cow::Owned)),
);
let mut host_dependencies = Dependencies::from(
default_features

let build_dependencies = Dependencies::from(
targets
.iter()
.filter_map(|f| f.dependencies(SpecType::Host, Some(host_platform))),
.filter_map(|f| f.dependencies(SpecType::Build).cloned().map(Cow::Owned)),
);
let build_dependencies = Dependencies::from(
default_features

let mut host_dependencies = Dependencies::from(
targets
.iter()
.filter_map(|f| f.dependencies(SpecType::Build, Some(host_platform))),
.filter_map(|f| f.dependencies(SpecType::Host).cloned().map(Cow::Owned)),
);

// Determine the installer to use
Expand Down Expand Up @@ -569,3 +579,87 @@ impl ProtocolFactory for PythonBuildBackendFactory {
Ok((instance, InitializeResult { capabilities }))
}
}

#[cfg(test)]
mod tests {

use pixi_manifest::Manifest;
use rattler_build::{console_utils::LoggingOutputHandler, recipe::parser::Dependency};
use rattler_conda_types::{ChannelConfig, Platform};
use std::path::PathBuf;

use tempfile::tempdir;

use crate::python::PythonBuildBackend;

#[tokio::test]
async fn test_setting_host_and_build_requirements() {
// get cargo manifest dir

let package_with_host_and_build_deps = r#"
[workspace]
name = "test-reqs"
channels = ["conda-forge"]
platforms = ["osx-arm64"]
preview = ["pixi-build"]
[package]
name = "test-reqs"
version = "1.0"
[host-dependencies]
hatchling = "*"
[build-dependencies]
boltons = "*"
[build-system]
build-backend = "pixi-build-python"
dependencies = []
channels = []
"#;

let tmp_dir = tempdir().unwrap();
let tmp_manifest = tmp_dir.path().join("pixi.toml");

// write the raw string into the file
std::fs::write(&tmp_manifest, package_with_host_and_build_deps).unwrap();

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

let python_backend =
PythonBuildBackend::new(&manifest.path, LoggingOutputHandler::default(), None).unwrap();

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

let host_platform = Platform::current();

let (reqs, _) = python_backend
.requirements(host_platform, &channel_config)
.unwrap();

let host_reqs = reqs
.host
.iter()
.map(|d| match d {
Dependency::Spec(spec) => spec.to_string(),
_ => "".to_string(),
})
.collect::<Vec<String>>();

let build_reqs = reqs
.build
.iter()
.map(|d| match d {
Dependency::Spec(spec) => spec.to_string(),
_ => "".to_string(),
})
.collect::<Vec<String>>();

assert!(host_reqs.contains(&"hatchling *".to_string()));
assert!(!host_reqs.contains(&"boltons *".to_string()));

assert!(build_reqs.contains(&"boltons *".to_string()));
assert!(!host_reqs.contains(&"hatcling *".to_string()));
}
}

0 comments on commit 7cb28e6

Please sign in to comment.