Skip to content

Commit 7c1c0fa

Browse files
committed
add target to workspace for [workspace.target.win-64.build-variants] support
1 parent 2a1e115 commit 7c1c0fa

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

crates/pixi_manifest/src/pyproject.rs

-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ impl PyProjectManifest {
267267
homepage: None,
268268
repository: None,
269269
documentation: None,
270-
build_variants: None,
271270
})?;
272271

273272
// Add python as dependency based on the `project.requires_python` property

crates/pixi_manifest/src/toml/workspace.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{collections::HashMap, path::PathBuf};
22

3-
use indexmap::IndexSet;
3+
use indexmap::{IndexMap, IndexSet};
44
use rattler_conda_types::{NamedChannelOrUrl, Platform, Version};
55
use rattler_solve::ChannelPriority;
66
use serde::Deserialize;
@@ -10,9 +10,15 @@ use url::Url;
1010

1111
use crate::{
1212
preview::Preview, pypi::pypi_options::PypiOptions, utils::PixiSpanned, PrioritizedChannel,
13-
Workspace,
13+
TargetSelector, Targets, Workspace,
1414
};
1515

16+
#[derive(Debug, Clone, Deserialize)]
17+
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
18+
pub struct TomlWorkspaceTarget {
19+
build_variants: Option<HashMap<String, Vec<String>>>,
20+
}
21+
1622
/// The TOML representation of the `[[workspace]]` section in a pixi manifest.
1723
#[serde_as]
1824
#[derive(Debug, Clone, Deserialize)]
@@ -46,6 +52,9 @@ pub struct TomlWorkspace {
4652
#[serde(default)]
4753
pub preview: Preview,
4854

55+
#[serde(default)]
56+
pub target: IndexMap<PixiSpanned<TargetSelector>, TomlWorkspaceTarget>,
57+
4958
pub build_variants: Option<HashMap<String, Vec<String>>>,
5059
}
5160

@@ -65,7 +74,6 @@ pub struct ExternalWorkspaceProperties {
6574
pub homepage: Option<Url>,
6675
pub repository: Option<Url>,
6776
pub documentation: Option<Url>,
68-
pub build_variants: Option<HashMap<String, Vec<String>>>,
6977
}
7078

7179
#[derive(Debug, Error)]
@@ -99,7 +107,14 @@ impl TomlWorkspace {
99107
conda_pypi_map: self.conda_pypi_map,
100108
pypi_options: self.pypi_options,
101109
preview: self.preview,
102-
build_variants: self.build_variants.or(external.build_variants),
110+
build_variants: Targets::from_default_and_user_defined(
111+
self.build_variants,
112+
self.target
113+
.clone()
114+
.into_iter()
115+
.map(|(k, v)| (k, v.build_variants))
116+
.collect(),
117+
),
103118
})
104119
}
105120
}

crates/pixi_manifest/src/workspace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rattler_solve::ChannelPriority;
66
use url::Url;
77

88
use super::pypi::pypi_options::PypiOptions;
9-
use crate::{preview::Preview, utils::PixiSpanned, PrioritizedChannel};
9+
use crate::{preview::Preview, utils::PixiSpanned, PrioritizedChannel, Targets};
1010

1111
/// Describes the contents of the `[workspace]` section of the project manifest.
1212
#[derive(Debug, Clone)]
@@ -62,5 +62,5 @@ pub struct Workspace {
6262
pub preview: Preview,
6363

6464
/// Build variants
65-
pub build_variants: Option<HashMap<String, Vec<String>>>,
65+
pub build_variants: Targets<Option<HashMap<String, Vec<String>>>>,
6666
}

src/build/mod.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use pixi_build_types::{
2626
use pixi_config::get_cache_dir;
2727
pub use pixi_glob::{GlobHashCache, GlobHashError};
2828
use pixi_glob::{GlobHashKey, GlobModificationTime, GlobModificationTimeError};
29+
use pixi_manifest::Targets;
2930
use pixi_record::{InputHash, PinnedPathSpec, PinnedSourceSpec, SourceRecord};
3031
use pixi_spec::SourceSpec;
3132
use rattler_conda_types::{
@@ -54,7 +55,7 @@ pub struct BuildContext {
5455
cache_dir: PathBuf,
5556
work_dir: PathBuf,
5657
tool_context: Arc<ToolContext>,
57-
variant_config: Option<HashMap<String, Vec<String>>>,
58+
variant_config: Targets<Option<HashMap<String, Vec<String>>>>,
5859
}
5960

6061
#[derive(Debug, Error, Diagnostic)]
@@ -117,7 +118,7 @@ impl BuildContext {
117118
cache_dir: PathBuf,
118119
dot_pixi_dir: PathBuf,
119120
channel_config: ChannelConfig,
120-
variant_config: Option<HashMap<String, Vec<String>>>,
121+
variant_config: Targets<Option<HashMap<String, Vec<String>>>>,
121122
tool_context: Arc<ToolContext>,
122123
) -> Result<Self, std::io::Error> {
123124
Ok(Self {
@@ -133,16 +134,18 @@ impl BuildContext {
133134
}
134135

135136
pub fn from_project(project: &crate::project::Project) -> miette::Result<Self> {
137+
let variant = project
138+
.manifest()
139+
.workspace
140+
.workspace
141+
.build_variants
142+
.clone();
143+
136144
Self::new(
137145
get_cache_dir()?,
138146
project.pixi_dir(),
139147
project.channel_config(),
140-
project
141-
.manifest()
142-
.workspace
143-
.workspace
144-
.build_variants
145-
.clone(),
148+
variant,
146149
Arc::new(ToolContext::default()),
147150
)
148151
.into_diagnostic()
@@ -163,6 +166,22 @@ impl BuildContext {
163166
}
164167
}
165168

169+
fn resolve_variant(&self, platform: Platform) -> HashMap<String, Vec<String>> {
170+
let mut result = HashMap::new();
171+
for item in self.variant_config.resolve(Some(platform)) {
172+
if let Some(variants) = item {
173+
result.extend(variants.clone());
174+
}
175+
}
176+
tracing::info!(
177+
"resolved variant configuration for {}: {:?}",
178+
platform,
179+
result
180+
);
181+
182+
result
183+
}
184+
166185
/// Extracts the metadata for a package from the given source specification.
167186
#[allow(clippy::too_many_arguments)]
168187
pub async fn extract_source_metadata(
@@ -319,7 +338,7 @@ impl BuildContext {
319338
}
320339
.key(),
321340
),
322-
variant_configuration: self.variant_config.clone(),
341+
variant_configuration: Some(self.resolve_variant(host_platform)),
323342
},
324343
build_reporter.as_conda_build_reporter(),
325344
)
@@ -558,7 +577,7 @@ impl BuildContext {
558577
}
559578
.key(),
560579
),
561-
variant_configuration: self.variant_config.clone(),
580+
variant_configuration: Some(self.resolve_variant(host_platform)),
562581
},
563582
metadata_reporter.as_conda_metadata_reporter().clone(),
564583
)

0 commit comments

Comments
 (0)