Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/pixi_build_discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ version = "0.1.0"
dunce = { workspace = true }
itertools = { workspace = true }
miette = { workspace = true }
ordermap = { workspace = true }
pathdiff = { workspace = true }
serde = { workspace = true, optional = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
25 changes: 21 additions & 4 deletions crates/pixi_build_discovery/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use std::{

use itertools::Itertools;
use miette::Diagnostic;
use pixi_build_type_conversions::to_project_model_v1;
use pixi_build_types::ProjectModelV1;
use ordermap::OrderMap;
use pixi_build_type_conversions::{to_project_model_v1, to_target_selector_v1};
use pixi_build_types::{ProjectModelV1, TargetSelectorV1};
use pixi_manifest::{
DiscoveryStart, ExplicitManifestError, PackageManifest, PrioritizedChannel, WithProvenance,
WorkspaceDiscoverer, WorkspaceDiscoveryError, WorkspaceManifest,
Expand Down Expand Up @@ -53,6 +54,9 @@ pub struct BackendInitializationParams {

/// Additional configuration that applies to the backend.
pub configuration: Option<serde_json::Value>,

/// Targets that apply to the backend.
pub target_configuration: Option<OrderMap<TargetSelectorV1, serde_json::Value>>,
}

/// Configuration to enable or disable certain protocols discovery.
Expand Down Expand Up @@ -169,12 +173,13 @@ impl DiscoveredBackend {
manifest_path: recipe_relative_path,
project_model: None,
configuration: None,
target_configuration: None,
},
})
}

/// Convert a package manifest and corresponding workspace manifest into a
/// discovered backend.
/// discovered backend, with optional platform-specific configuration.
pub fn from_package_and_workspace(
source_path: PathBuf,
package_manifest: &WithProvenance<PackageManifest>,
Expand Down Expand Up @@ -247,7 +252,19 @@ impl DiscoveredBackend {
configuration: build_system.configuration.map(|config| {
config
.deserialize_into()
.expect("Configuration dictionary should be serializable to JSON")
.expect("Configuration dictionary needs to be serializable to JSON")
}),
target_configuration: build_system.target_configuration.map(|c| {
c.into_iter()
.map(|(selector, config)| {
(
to_target_selector_v1(&selector),
config.deserialize_into().expect(
"Configuration dictionary needs to be serializable to JSON",
),
)
})
.collect()
}),
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ init-params:
manifest-path: recipe.yaml
project-model: ~
configuration: ~
target-configuration: ~
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ init-params:
runDependencies: {}
targets: {}
configuration: ~
target-configuration: ~
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ init-params:
runDependencies: {}
targets: {}
configuration: ~
target-configuration: ~
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ init-params:
manifest-path: recipe/recipe.yml
project-model: ~
configuration: ~
target-configuration: ~
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ init-params:
manifest-path: recipe.yaml
project-model: ~
configuration: ~
target-configuration: ~
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ init-params:
manifest-path: recipe.yml
project-model: ~
configuration: ~
target-configuration: ~
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ init-params:
runDependencies: {}
targets: {}
configuration: ~
target-configuration: ~
9 changes: 8 additions & 1 deletion crates/pixi_build_frontend/src/backend/json_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ use jsonrpsee::{
types::ErrorCode,
};
use miette::Diagnostic;
use ordermap::OrderMap;
use pixi_build_types::{
BackendCapabilities, FrontendCapabilities, ProjectModelV1, VersionedProjectModel, procedures,
BackendCapabilities, FrontendCapabilities, ProjectModelV1, TargetSelectorV1,
VersionedProjectModel,
procedures::{
self,
conda_build_v0::{CondaBuildParams, CondaBuildResult},
conda_build_v1::{CondaBuildV1Params, CondaBuildV1Result},
conda_metadata::{CondaMetadataParams, CondaMetadataResult},
Expand Down Expand Up @@ -143,6 +146,7 @@ impl JsonRpcBackend {
manifest_path: PathBuf,
package_manifest: Option<ProjectModelV1>,
configuration: Option<serde_json::Value>,
target_configuration: Option<OrderMap<TargetSelectorV1, serde_json::Value>>,
cache_dir: Option<PathBuf>,
tool: Tool,
) -> Result<Self, InitializeError> {
Expand Down Expand Up @@ -187,6 +191,7 @@ impl JsonRpcBackend {
manifest_path,
package_manifest,
configuration,
target_configuration,
cache_dir,
tx,
rx,
Expand All @@ -203,6 +208,7 @@ impl JsonRpcBackend {
manifest_path: PathBuf,
project_model: Option<ProjectModelV1>,
configuration: Option<serde_json::Value>,
target_configuration: Option<OrderMap<TargetSelectorV1, serde_json::Value>>,
cache_dir: Option<PathBuf>,
sender: impl TransportSenderT + Send,
receiver: impl TransportReceiverT + Send,
Expand Down Expand Up @@ -239,6 +245,7 @@ impl JsonRpcBackend {
RpcParams::from(InitializeParams {
project_model: project_model.map(VersionedProjectModel::V1),
configuration,
target_configuration,
manifest_path: manifest_path.clone(),
source_dir: Some(source_dir),
cache_directory: cache_dir,
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_build_type_conversions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod project_model;

pub use project_model::{compute_project_model_hash, to_project_model_v1};
pub use project_model::{compute_project_model_hash, to_project_model_v1, to_target_selector_v1};
2 changes: 1 addition & 1 deletion crates/pixi_build_type_conversions/src/project_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn to_target_v1(
})
}

fn to_target_selector_v1(selector: &TargetSelector) -> pbt::TargetSelectorV1 {
pub fn to_target_selector_v1(selector: &TargetSelector) -> pbt::TargetSelectorV1 {
match selector {
TargetSelector::Platform(platform) => pbt::TargetSelectorV1::Platform(platform.to_string()),
TargetSelector::Unix => pbt::TargetSelectorV1::Unix,
Expand Down
6 changes: 5 additions & 1 deletion crates/pixi_build_types/src/procedures/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

use std::path::PathBuf;

use ordermap::OrderMap;
use serde::{Deserialize, Serialize};

use crate::VersionedProjectModel;
use crate::{TargetSelectorV1, VersionedProjectModel};

pub const METHOD_NAME: &str = "initialize";

Expand Down Expand Up @@ -46,6 +47,9 @@ pub struct InitializeParams {

/// Backend specific configuration passed from the frontend to the backend.
pub configuration: Option<serde_json::Value>,

/// Targets that apply to the backend.
pub target_configuration: Option<OrderMap<TargetSelectorV1, serde_json::Value>>,
}

/// The result of the initialize request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl CommandDispatcher {
cache_directory: Some(self.cache_dirs().root().clone()),
project_model: spec.init_params.project_model.map(Into::into),
configuration: spec.init_params.configuration,
target_configuration: spec.init_params.target_configuration,
})
.map_err(InstantiateBackendError::InMemoryError)
.map_err(CommandDispatcherError::Failed)?;
Expand Down Expand Up @@ -141,6 +142,7 @@ impl CommandDispatcher {
manifest_path,
spec.init_params.project_model,
spec.init_params.configuration,
spec.init_params.target_configuration,
Some(self.cache_dirs().root().clone()),
tool,
)
Expand Down
5 changes: 5 additions & 0 deletions crates/pixi_manifest/src/build_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use indexmap::IndexMap;
use pixi_spec::BinarySpec;
use rattler_conda_types::NamedChannelOrUrl;

use crate::TargetSelector;
use crate::toml::FromTomlStr;
use crate::{TomlError, toml::TomlPackageBuild};

Expand All @@ -23,6 +24,9 @@ pub struct PackageBuild {

/// Additional configuration for the build backend.
pub configuration: Option<serde_value::Value>,

/// Target-specific configuration for different platforms
pub target_configuration: Option<IndexMap<TargetSelector, serde_value::Value>>,
}

impl PackageBuild {
Expand All @@ -33,6 +37,7 @@ impl PackageBuild {
channels: Some(channels),
additional_dependencies: IndexMap::default(),
configuration: None,
target_configuration: None,
}
}
}
Expand Down
31 changes: 28 additions & 3 deletions crates/pixi_manifest/src/toml/build_system.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::collections::BTreeMap;

use indexmap::IndexMap;
use itertools::Either;
use pixi_spec::TomlSpec;
use pixi_toml::{TomlFromStr, TomlWith};
use pixi_toml::{Same, TomlFromStr, TomlIndexMap, TomlWith};
use rattler_conda_types::NamedChannelOrUrl;
use toml_span::{DeserError, Spanned, Value, de_helpers::TableHelper, value::ValueInner};

use crate::{
PackageBuild, TomlError,
PackageBuild, TargetSelector, TomlError,
build_system::BuildBackend,
error::GenericError,
toml::build_target::TomlPackageBuildTarget,
utils::{PixiSpanned, package_map::UniquePackageMap},
};

Expand All @@ -19,6 +21,7 @@ pub struct TomlPackageBuild {
pub channels: Option<PixiSpanned<Vec<NamedChannelOrUrl>>>,
pub additional_dependencies: UniquePackageMap,
pub configuration: Option<serde_value::Value>,
pub target: IndexMap<PixiSpanned<TargetSelector>, TomlPackageBuildTarget>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -70,6 +73,17 @@ impl TomlPackageBuild {
}
}

// Convert target-specific build configurations
let target_configuration = self
.target
.into_iter()
.flat_map(|(selector, target)| {
target
.configuration
.map(|config| (selector.into_inner(), config))
})
.collect::<IndexMap<_, _>>();

Ok(PackageBuild {
backend: BuildBackend {
name: self.backend.value.name.value,
Expand All @@ -78,11 +92,16 @@ impl TomlPackageBuild {
additional_dependencies,
channels: self.channels.map(|channels| channels.value),
configuration: self.configuration,
target_configuration: if target_configuration.is_empty() {
None
} else {
Some(target_configuration)
},
})
}
}

fn convert_toml_to_serde(value: &mut Value) -> Result<serde_value::Value, DeserError> {
pub fn convert_toml_to_serde(value: &mut Value) -> Result<serde_value::Value, DeserError> {
Ok(match value.take() {
ValueInner::String(s) => serde_value::Value::String(s.to_string()),
ValueInner::Integer(i) => serde_value::Value::I64(i),
Expand Down Expand Up @@ -143,12 +162,18 @@ impl<'de> toml_span::Deserialize<'de> for TomlPackageBuild {
.map(|(_, mut value)| convert_toml_to_serde(&mut value))
.transpose()?;

let target = th
.optional::<TomlWith<_, TomlIndexMap<_, Same>>>("target")
.map(TomlWith::into_inner)
.unwrap_or_default();

th.finalize(None)?;
Ok(Self {
backend: build_backend,
channels,
additional_dependencies,
configuration,
target,
})
}
}
Expand Down
21 changes: 21 additions & 0 deletions crates/pixi_manifest/src/toml/build_target.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use toml_span::{DeserError, Value, de_helpers::TableHelper};

use crate::toml::build_system::convert_toml_to_serde;

#[derive(Debug)]
pub struct TomlPackageBuildTarget {
pub configuration: Option<serde_value::Value>,
}

impl<'de> toml_span::Deserialize<'de> for TomlPackageBuildTarget {
fn deserialize(value: &mut Value<'de>) -> Result<Self, DeserError> {
let mut th = TableHelper::new(value)?;
let configuration = th
.take("configuration")
.map(|(_, mut value)| convert_toml_to_serde(&mut value))
.transpose()?;

th.finalize(None)?;
Ok(TomlPackageBuildTarget { configuration })
}
}
1 change: 1 addition & 0 deletions crates/pixi_manifest/src/toml/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod build_system;
mod build_target;
mod channel;
mod document;
mod environment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/pixi_manifest/src/toml/build_system.rs
expression: "expect_parse_failure(r#\"\n backend = { name = \"foobar\", version = \"*\" }\n additional = \"key\"\n \"#)"
---
× Unexpected keys, expected only 'backend', 'channels', 'additional-dependencies', 'configuration'
× Unexpected keys, expected only 'backend', 'channels', 'additional-dependencies', 'configuration', 'target'
╭─[pixi.toml:3:13]
2 │ backend = { name = "foobar", version = "*" }
3 │ additional = "key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ TomlPackageBuild {
},
),
),
target: {},
}
13 changes: 13 additions & 0 deletions schema/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,14 @@ class Package(StrictBaseModel):
)


class BuildTarget(StrictBaseModel):
"""Target-specific build configuration for different platforms"""

configuration: dict[str, Any] = Field(
None, description="Target-specific configuration for the build backend"
)


class Build(StrictBaseModel):
backend: BuildBackend = Field(..., description="The build backend to instantiate")
channels: list[Channel] = Field(
Expand All @@ -694,6 +702,11 @@ class Build(StrictBaseModel):
configuration: dict[str, Any] = Field(
None, description="The configuration of the build backend"
)
target: dict[TargetName, BuildTarget] | None = Field(
None,
description="Target-specific build configuration for different platforms",
examples=[{"linux-64": {"configuration": {"key": "value"}}}],
)


class BuildBackend(MatchspecTable):
Expand Down
Loading
Loading