Skip to content

Commit

Permalink
feat: add variant config to [workspace.build-variants] (#2634)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Dec 3, 2024
1 parent d4f0dd7 commit cba5830
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 25 deletions.
5 changes: 4 additions & 1 deletion crates/pixi_build_types/src/procedures/conda_build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf};

use rattler_conda_types::GenericVirtualPackage;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -34,6 +34,9 @@ pub struct CondaBuildParams {
#[serde(default)]
pub outputs: Option<Vec<CondaOutputIdentifier>>,

/// The variants that we want to build
pub variant_configuration: Option<HashMap<String, Vec<String>>>,

/// A directory that can be used by the backend to store files for
/// subsequent requests. This directory is unique for each separate source
/// dependency.
Expand Down
5 changes: 4 additions & 1 deletion crates/pixi_build_types/src/procedures/conda_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf};
use url::Url;

use crate::{ChannelConfiguration, CondaPackageMetadata, PlatformAndVirtualPackages};
Expand Down Expand Up @@ -27,6 +27,9 @@ pub struct CondaMetadataParams {
/// The channel configuration to use to resolve dependencies.
pub channel_configuration: ChannelConfiguration,

/// The variants that we want to build
pub variant_configuration: Option<HashMap<String, Vec<String>>>,

/// A directory that can be used by the backend to store files for
/// subsequent requests. This directory is unique for each separate source
/// dependency.
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_manifest/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl PyProjectManifest {
homepage: None,
repository: None,
documentation: None,
build_variants: None,
})?;

// Add python as dependency based on the `project.requires_python` property
Expand Down
4 changes: 4 additions & 0 deletions crates/pixi_manifest/src/toml/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct TomlWorkspace {

#[serde(default)]
pub preview: Preview,

pub build_variants: Option<HashMap<String, Vec<String>>>,
}

/// Defines some of the properties that might be defined in other parts of the
Expand All @@ -63,6 +65,7 @@ pub struct ExternalWorkspaceProperties {
pub homepage: Option<Url>,
pub repository: Option<Url>,
pub documentation: Option<Url>,
pub build_variants: Option<HashMap<String, Vec<String>>>,
}

#[derive(Debug, Error)]
Expand Down Expand Up @@ -96,6 +99,7 @@ impl TomlWorkspace {
conda_pypi_map: self.conda_pypi_map,
pypi_options: self.pypi_options,
preview: self.preview,
build_variants: self.build_variants.or(external.build_variants),
})
}
}
3 changes: 3 additions & 0 deletions crates/pixi_manifest/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ pub struct Workspace {

/// Preview features
pub preview: Preview,

/// Build variants
pub build_variants: Option<HashMap<String, Vec<String>>>,
}
3 changes: 3 additions & 0 deletions schema/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class Workspace(StrictBaseModel):
preview: list[KnownPreviewFeature | str] | bool | None = Field(
None, description="Defines the enabling of preview features of the project"
)
build_variants: dict[NonEmptyStr, list[str]] | None = Field(
None, description="The build variants of the project"
)


class Package(StrictBaseModel):
Expand Down
11 changes: 11 additions & 0 deletions schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,17 @@
"John Doe <[email protected]>"
]
},
"build-variants": {
"title": "Build-Variants",
"description": "The build variants of the project",
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
},
"channel-priority": {
"$ref": "#/$defs/ChannelPriority",
"description": "The type of channel priority that is used in the solve.- 'strict': only take the package from the channel it exist in first.- 'disabled': group all dependencies together as if there is no channel difference.",
Expand Down
32 changes: 31 additions & 1 deletion src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod cache;
mod reporters;

use std::{
collections::HashMap,
ffi::OsStr,
hash::{Hash, Hasher},
ops::Not,
Expand All @@ -13,7 +14,7 @@ use std::{
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use chrono::Utc;
use itertools::Itertools;
use miette::Diagnostic;
use miette::{Diagnostic, IntoDiagnostic};
use pixi_build_frontend::{BackendOverride, SetupRequest, ToolContext};
use pixi_build_types::{
procedures::{
Expand All @@ -22,6 +23,7 @@ use pixi_build_types::{
},
ChannelConfiguration, CondaPackageMetadata, PlatformAndVirtualPackages,
};
use pixi_config::get_cache_dir;
pub use pixi_glob::{GlobHashCache, GlobHashError};
use pixi_glob::{GlobHashKey, GlobModificationTime, GlobModificationTimeError};
use pixi_record::{InputHash, PinnedPathSpec, PinnedSourceSpec, SourceRecord};
Expand Down Expand Up @@ -52,6 +54,7 @@ pub struct BuildContext {
cache_dir: PathBuf,
work_dir: PathBuf,
tool_context: Arc<ToolContext>,
variant_config: Option<HashMap<String, Vec<String>>>,
}

#[derive(Debug, Error, Diagnostic)]
Expand Down Expand Up @@ -114,6 +117,7 @@ impl BuildContext {
cache_dir: PathBuf,
dot_pixi_dir: PathBuf,
channel_config: ChannelConfig,
variant_config: Option<HashMap<String, Vec<String>>>,
tool_context: Arc<ToolContext>,
) -> Result<Self, std::io::Error> {
Ok(Self {
Expand All @@ -124,9 +128,33 @@ impl BuildContext {
cache_dir,
work_dir: dot_pixi_dir.join("build-v0"),
tool_context,
variant_config,
})
}

pub fn from_project(project: &crate::project::Project) -> miette::Result<Self> {
Self::new(
get_cache_dir()?,
project.pixi_dir(),
project.channel_config(),
project
.manifest()
.workspace
.workspace
.build_variants
.clone(),
Arc::new(ToolContext::default()),
)
.into_diagnostic()
}

pub fn with_tool_context(self, tool_context: Arc<ToolContext>) -> Self {
Self {
tool_context,
..self
}
}

/// Sets the input hash cache to use for caching input hashes.
pub fn with_glob_hash_cache(self, glob_hash_cache: GlobHashCache) -> Self {
Self {
Expand Down Expand Up @@ -291,6 +319,7 @@ impl BuildContext {
}
.key(),
),
variant_configuration: self.variant_config.clone(),
},
build_reporter.as_conda_build_reporter(),
)
Expand Down Expand Up @@ -529,6 +558,7 @@ impl BuildContext {
}
.key(),
),
variant_configuration: self.variant_config.clone(),
},
metadata_reporter.as_conda_metadata_reporter().clone(),
)
Expand Down
2 changes: 2 additions & 0 deletions src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
pixi_dir.display()
)
})?;

let work_dir = tempfile::Builder::new()
.prefix("pixi-build-")
.tempdir_in(project.pixi_dir())
Expand Down Expand Up @@ -165,6 +166,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
},
outputs: None,
work_directory: work_dir.path().to_path_buf(),
variant_configuration: Some(Default::default()),
},
progress.clone(),
)
Expand Down
26 changes: 4 additions & 22 deletions src/lock_file/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use indicatif::ProgressBar;
use itertools::{Either, Itertools};
use miette::{Diagnostic, IntoDiagnostic, LabeledSpan, MietteDiagnostic, Report, WrapErr};
use pixi_build_frontend::ToolContext;
use pixi_config::get_cache_dir;
use pixi_consts::consts;
use pixi_manifest::{EnvironmentName, FeaturesExt, HasFeaturesIter};
use pixi_progress::global_multi_progress;
Expand Down Expand Up @@ -680,13 +679,7 @@ pub async fn update_lock_file(
updated_pypi_prefixes: Default::default(),
uv_context: None,
io_concurrency_limit: IoConcurrencyLimit::default(),
build_context: BuildContext::new(
get_cache_dir()?,
project.pixi_dir(),
project.channel_config(),
Arc::new(ToolContext::default()),
)
.into_diagnostic()?,
build_context: BuildContext::from_project(project)?,
glob_hash_cache,
});
}
Expand All @@ -710,13 +703,7 @@ pub async fn update_lock_file(
updated_pypi_prefixes: Default::default(),
uv_context: None,
io_concurrency_limit: IoConcurrencyLimit::default(),
build_context: BuildContext::new(
get_cache_dir()?,
project.pixi_dir(),
project.channel_config(),
Arc::new(ToolContext::default()),
)
.into_diagnostic()?,
build_context: BuildContext::from_project(project)?,
glob_hash_cache,
});
}
Expand Down Expand Up @@ -1011,13 +998,8 @@ impl<'p> UpdateContextBuilder<'p> {
.with_client(client)
.build();

let build_context = BuildContext::new(
pixi_config::get_cache_dir()?,
project.pixi_dir(),
project.channel_config(),
tool_context.into(),
)
.into_diagnostic()?;
let build_context =
BuildContext::from_project(project)?.with_tool_context(Arc::new(tool_context));

Ok(UpdateContext {
project,
Expand Down

0 comments on commit cba5830

Please sign in to comment.