Skip to content

Commit

Permalink
up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Jan 17, 2025
1 parent 340171f commit 17a57e1
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 147 deletions.
35 changes: 12 additions & 23 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ rattler_conda_types = { version = "0.29.9", default-features = false }
rattler_package_streaming = { version = "0.22.22", default-features = false }
rattler_virtual_packages = { version = "1.1.17", default-features = false }

pixi_build_types = { git = "https://github.com/tdejager/pixi", branch = "feat/split-source-binary-build-types" }
pixi_consts = { git = "https://github.com/tdejager/pixi", branch = "feat/split-source-binary-build-types" }
pixi_manifest = { git = "https://github.com/tdejager/pixi", branch = "feat/split-source-binary-build-types" }
pixi_spec = { git = "https://github.com/tdejager/pixi", branch = "feat/split-source-binary-build-types" }
pixi_build_type_conversions = { git = "https://github.com/tdejager/pixi", branch = "feat/split-source-binary-build-types" }
pixi_build_types = { git = "https://github.com/prefix-dev/pixi", branch = "main" }
pixi_consts = { git = "https://github.com/prefix-dev/pixi", branch = "main" }
pixi_manifest = { git = "https://github.com/prefix-dev/pixi", branch = "main" }
pixi_spec = { git = "https://github.com/prefix-dev/pixi", branch = "main" }
pixi_build_type_conversions = { git = "https://github.com/prefix-dev/pixi", branch = "main" }
58 changes: 33 additions & 25 deletions crates/pixi-build/src/bin/pixi-build-cmake/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl CMakeBuildBackend {
/// at the given path.
pub fn new(
manifest_path: &Path,
project_model: pbt::VersionedProjectModel,
config: Option<CMakeBackendConfig>,
project_model: pbt::ProjectModelV1,
config: CMakeBackendConfig,
logging_output_handler: LoggingOutputHandler,
cache_dir: Option<PathBuf>,
) -> miette::Result<Self> {
Expand All @@ -92,21 +92,10 @@ impl CMakeBuildBackend {
.ok_or_else(|| miette::miette!("the project manifest must reside in a directory"))?
.to_path_buf();

// Read config from the manifest itself if its not provided
// TODO: I guess this should also be passed over the protocol.
let config = match config {
Some(config) => config,
None => CMakeBackendConfig::from_path(manifest_path)?,
};

let v1 = project_model
.into_v1()
.ok_or_else(|| miette::miette!("project model v1 is required"))?;

Ok(Self {
manifest_path: manifest_path.to_path_buf(),
manifest_root,
project_model: v1,
project_model,
_config: config,
logging_output_handler,
cache_dir,
Expand Down Expand Up @@ -138,24 +127,27 @@ impl CMakeBuildBackend {
let targets = self
.project_model
.targets
.resolve(Some(host_platform))
.iter()
.flat_map(|targets| targets.resolve(Some(host_platform)))
.collect_vec();

let run_dependencies = targets
.iter()
.flat_map(|t| t.run_dependencies.iter())
.flatten()
.collect::<IndexMap<&pbt::SourcePackageName, &pbt::PackageSpecV1>>();

let host_dependencies = targets
.iter()
.flat_map(|t| t.host_dependencies.iter())
.flatten()
.collect::<IndexMap<&pbt::SourcePackageName, &pbt::PackageSpecV1>>();

let mut build_dependencies = targets
.iter()
.flat_map(|t| t.build_dependencies.iter())
.collect::<IndexMap<&pbt::SourcePackageName, &pbt::PackageSpecV1>>(
);
.flatten()
.collect::<IndexMap<&pbt::SourcePackageName, &pbt::PackageSpecV1>>();

// Ensure build tools are available in the build dependencies section.
let build_tools = ["cmake".to_string(), "ninja".to_string()];
Expand Down Expand Up @@ -372,12 +364,14 @@ impl CMakeBuildBackend {
let used_variants = self
.project_model
.targets
.resolve(Some(host_platform))
.iter()
.flat_map(|target| target.resolve(Some(host_platform)))
.flat_map(|dep| {
dep.build_dependencies
.iter()
.chain(dep.run_dependencies.iter())
.chain(dep.host_dependencies.iter())
.flatten()
.chain(dep.run_dependencies.iter().flatten())
.chain(dep.host_dependencies.iter().flatten())
})
.filter(|(_, spec)| can_be_used_as_variant(spec))
.map(|(name, _)| name.clone().into())
Expand Down Expand Up @@ -688,12 +682,26 @@ impl ProtocolFactory for CMakeBuildBackendFactory {
&self,
params: InitializeParams,
) -> miette::Result<(Self::Protocol, InitializeResult)> {
let project_model = params
.project_model
.ok_or_else(|| miette::miette!("project model is required"))?;

let project_model = project_model
.into_v1()
.ok_or_else(|| miette::miette!("project model v1 is required"))?;

let config = if let Some(config) = params.configuration {
serde_json::from_value(config)
.into_diagnostic()
.context("failed to parse configuration")?
} else {
CMakeBackendConfig::default()
};

let instance = CMakeBuildBackend::new(
params.manifest_path.as_path(),
params
.project_model
.ok_or_else(|| miette::miette!("project model is required"))?,
None,
project_model,
config,
self.logging_output_handler.clone(),
params.cache_directory,
)?;
Expand Down Expand Up @@ -762,7 +770,7 @@ mod tests {
let cmake_backend = CMakeBuildBackend::new(
&manifest.path,
project_model,
Some(CMakeBackendConfig::default()),
CMakeBackendConfig::default(),
LoggingOutputHandler::default(),
None,
)
Expand Down
25 changes: 0 additions & 25 deletions crates/pixi-build/src/bin/pixi-build-cmake/config.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
use miette::IntoDiagnostic;
use serde::Deserialize;
use std::path::Path;

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CMakeBackendConfig {}

impl CMakeBackendConfig {
/// Parse the configuration from a manifest file.
pub fn from_path(path: &Path) -> miette::Result<Self> {
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Manifest {
#[serde(default)]
tool: Tool,
}

#[derive(Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Tool {
#[serde(default)]
pixi_build_python: CMakeBackendConfig,
}

let manifest = fs_err::read_to_string(path).into_diagnostic()?;
let document: Manifest = toml_edit::de::from_str(&manifest).into_diagnostic()?;
Ok(document.tool.pixi_build_python)
}
}
23 changes: 0 additions & 23 deletions crates/pixi-build/src/bin/pixi-build-python/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use miette::IntoDiagnostic;
use serde::Deserialize;
use std::convert::identity;
use std::path::Path;

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
Expand All @@ -17,25 +15,4 @@ impl PythonBackendConfig {
pub fn noarch(&self) -> bool {
self.noarch.map_or(true, identity)
}

/// Parse the configuration from a manifest file.
pub fn from_path(path: &Path) -> miette::Result<Self> {
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Manifest {
#[serde(default)]
tool: Tool,
}

#[derive(Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Tool {
#[serde(default)]
pixi_build_python: PythonBackendConfig,
}

let manifest = fs_err::read_to_string(path).into_diagnostic()?;
let document: Manifest = toml_edit::de::from_str(&manifest).into_diagnostic()?;
Ok(document.tool.pixi_build_python)
}
}
Loading

0 comments on commit 17a57e1

Please sign in to comment.