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
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[alias]
xtask = "run -p xtask --"

[target.x86_64-pc-windows-msvc]
linker = "rust-lld"

Expand Down
28 changes: 28 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ reqwest-retry = { git = "https://github.com/astral-sh/reqwest-middleware", rev =
rlimit = "0.10.2"
rstest = "0.26.0"
same-file = "1.0.6"
schemars = "1.1.0"
self-replace = "1.5.0"
serde = "1.0.218"
serde-untagged = "0.1.6"
Expand Down
9 changes: 2 additions & 7 deletions crates/pixi_api/src/workspace/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pixi_core::{
workspace::{PypiDeps, UpdateDeps, WorkspaceMut},
};
use pixi_manifest::{FeatureName, KnownPreviewFeature, SpecType};
use pixi_spec::{GitSpec, SourceLocationSpec, SourceSpec};
use pixi_spec::{GitSpec, SourceLocationSpec};
use rattler_conda_types::{MatchSpec, PackageName};

mod options;
Expand Down Expand Up @@ -62,12 +62,7 @@ pub async fn add_conda_dep(
};
(
name.clone(),
(
SourceSpec {
location: SourceLocationSpec::Git(git_spec),
},
*spec_type,
),
(SourceLocationSpec::Git(git_spec).into(), *spec_type),
)
})
.collect();
Expand Down
94 changes: 49 additions & 45 deletions crates/pixi_build_backend_passthrough/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use pixi_build_frontend::{
json_rpc::CommunicationError,
};
use pixi_build_types::{
BackendCapabilities, BinaryPackageSpecV1, NamedSpecV1, PackageSpecV1, ProjectModelV1,
SourcePackageName, TargetSelectorV1, TargetV1, TargetsV1, VariantValue, VersionedProjectModel,
BackendCapabilities, BinaryPackageSpec, NamedSpec, PackageSpec, ProjectModel,
SourcePackageName, Target, TargetSelector, Targets, VariantValue,
procedures::{
conda_build_v1::{CondaBuildV1Params, CondaBuildV1Result},
conda_outputs::{
Expand Down Expand Up @@ -52,7 +52,7 @@ pub enum BackendEvent {
/// backend is useful for testing and debugging purposes, as it does not perform
/// any actual building or processing of the project model.
pub struct PassthroughBackend {
project_model: ProjectModelV1,
project_model: ProjectModel,
config: PassthroughBackendConfig,
source_dir: PathBuf,
index_json: IndexJson,
Expand All @@ -74,7 +74,6 @@ impl InMemoryBackend for PassthroughBackend {
BackendCapabilities {
provides_conda_outputs: Some(true),
provides_conda_build_v1: Some(true),
..BackendCapabilities::default()
}
}

Expand Down Expand Up @@ -250,12 +249,14 @@ fn create_conda_package_on_the_fly(
Ok(())
}

/// Generates all variant outputs for a package based on the variant configuration.
/// Generates all variant outputs for a package based on the variant
/// configuration.
///
/// If any dependency has a "*" version requirement and there's a variant configuration
/// for that package, multiple outputs will be generated - one for each variant combination.
/// If any dependency has a "*" version requirement and there's a variant
/// configuration for that package, multiple outputs will be generated - one for
/// each variant combination.
fn generate_variant_outputs(
project_model: &ProjectModelV1,
project_model: &ProjectModel,
index_json: &IndexJson,
params: &CondaOutputsParams,
run_exports: &BTreeMap<String, RunExportsJson>,
Expand Down Expand Up @@ -307,8 +308,9 @@ fn generate_variant_outputs(
.collect()
}

/// Finds all dependency names that have "*" requirements and have variant configurations.
fn find_variant_keys(project_model: &ProjectModelV1, params: &CondaOutputsParams) -> Vec<String> {
/// Finds all dependency names that have "*" requirements and have variant
/// configurations.
fn find_variant_keys(project_model: &ProjectModel, params: &CondaOutputsParams) -> Vec<String> {
let Some(targets) = &project_model.targets else {
return Vec::new();
};
Expand All @@ -320,7 +322,7 @@ fn find_variant_keys(project_model: &ProjectModelV1, params: &CondaOutputsParams
let mut variant_keys = BTreeSet::new();

// Helper to check dependencies in a target
let mut check_deps = |deps: Option<&OrderMap<SourcePackageName, PackageSpecV1>>| {
let mut check_deps = |deps: Option<&OrderMap<SourcePackageName, PackageSpec>>| {
if let Some(deps) = deps {
for (name, spec) in deps {
// Check if this dependency has a "*" requirement
Expand Down Expand Up @@ -357,13 +359,13 @@ fn find_variant_keys(project_model: &ProjectModelV1, params: &CondaOutputsParams
}

/// Checks if a package spec has a "*" version requirement.
fn is_star_requirement(spec: &PackageSpecV1) -> bool {
let PackageSpecV1::Binary(boxed) = spec else {
fn is_star_requirement(spec: &PackageSpec) -> bool {
let PackageSpec::Binary(boxed) = spec else {
return false;
};

match boxed.as_ref() {
BinaryPackageSpecV1 {
match boxed {
BinaryPackageSpec {
version,
build: None,
build_number: None,
Expand Down Expand Up @@ -462,7 +464,7 @@ fn compute_variant_hash(variant: &BTreeMap<String, VariantValue>) -> String {

/// Creates a single output with the given variant configuration.
fn create_output(
project_model: &ProjectModelV1,
project_model: &ProjectModel,
index_json: &IndexJson,
params: &CondaOutputsParams,
mut variant: BTreeMap<String, VariantValue>,
Expand Down Expand Up @@ -555,8 +557,8 @@ fn create_output(
}
}

fn extract_dependencies<F: Fn(&TargetV1) -> Option<&OrderMap<SourcePackageName, PackageSpecV1>>>(
targets: &Option<TargetsV1>,
fn extract_dependencies<F: Fn(&Target) -> Option<&OrderMap<SourcePackageName, PackageSpec>>>(
targets: &Option<Targets>,
extract: F,
platform: Platform,
variant: &BTreeMap<String, VariantValue>,
Expand All @@ -582,7 +584,7 @@ fn extract_dependencies<F: Fn(&TargetV1) -> Option<&OrderMap<SourcePackageName,
let resolved_spec = if is_star_requirement(spec) {
if let Some(variant_value) = variant.get(name.as_str()) {
// Replace with a version spec using the variant value
PackageSpecV1::Binary(Box::new(BinaryPackageSpecV1 {
PackageSpec::Binary(BinaryPackageSpec {
version: Some(
rattler_conda_types::VersionSpec::from_str(
variant_value.to_string().as_str(),
Expand All @@ -591,15 +593,15 @@ fn extract_dependencies<F: Fn(&TargetV1) -> Option<&OrderMap<SourcePackageName,
.unwrap(),
),
..Default::default()
}))
})
} else {
spec.clone()
}
} else {
spec.clone()
};

NamedSpecV1 {
NamedSpec {
name: name.clone(),
spec: resolved_spec,
}
Expand All @@ -620,7 +622,7 @@ fn extract_dependencies<F: Fn(&TargetV1) -> Option<&OrderMap<SourcePackageName,
fn resolve_run_export_spec(
run_export_str: &str,
variant: &BTreeMap<String, VariantValue>,
) -> Option<NamedSpecV1<PackageSpecV1>> {
) -> Option<NamedSpec<PackageSpec>> {
// Parse the run_export string as a MatchSpec
let match_spec = rattler_conda_types::MatchSpec::from_str(
run_export_str,
Expand Down Expand Up @@ -657,24 +659,24 @@ fn resolve_run_export_spec(
match_spec.version.clone()
};

Some(NamedSpecV1 {
Some(NamedSpec {
name: SourcePackageName::from(name),
spec: PackageSpecV1::Binary(Box::new(BinaryPackageSpecV1 {
spec: PackageSpec::Binary(BinaryPackageSpec {
version: version_spec,
..Default::default()
})),
}),
})
}

/// Returns true if the given [`TargetSelectorV1`] matches the specified
/// Returns true if the given [`TargetSelector`] matches the specified
/// `platform`.
fn matches_target_selector(selector: &TargetSelectorV1, platform: Platform) -> bool {
fn matches_target_selector(selector: &TargetSelector, platform: Platform) -> bool {
match selector {
TargetSelectorV1::Unix => platform.is_unix(),
TargetSelectorV1::Linux => platform.is_linux(),
TargetSelectorV1::Win => platform.is_windows(),
TargetSelectorV1::MacOs => platform.is_osx(),
TargetSelectorV1::Platform(target_platform) => target_platform == platform.as_str(),
TargetSelector::Unix => platform.is_unix(),
TargetSelector::Linux => platform.is_linux(),
TargetSelector::Win => platform.is_windows(),
TargetSelector::MacOs => platform.is_osx(),
TargetSelector::Platform(target_platform) => target_platform == platform.as_str(),
}
}

Expand Down Expand Up @@ -707,10 +709,10 @@ impl InMemoryBackendInstantiator for PassthroughBackendInstantiator {
params: InitializeParams,
) -> Result<Self::Backend, Box<CommunicationError>> {
let project_model = match params.project_model {
Some(VersionedProjectModel::V1(project_model)) => project_model,
_ => {
Some(project_model) => project_model,
None => {
return Err(Box::new(CommunicationError::BackendError(
BackendError::new("Passthrough backend only supports project model v1"),
BackendError::new("Passthrough backend requires a project model"),
)));
}
};
Expand All @@ -721,7 +723,7 @@ impl InMemoryBackendInstantiator for PassthroughBackendInstantiator {
};

// Read the package file if it is specified, or create IndexJson for on_the_fly mode
let source_dir = params.source_dir.expect("Missing source directory");
let source_dir = params.source_directory.expect("Missing source directory");
let index_json = match &config.package {
Some(path) => {
let path = source_dir.join(path);
Expand Down Expand Up @@ -870,8 +872,9 @@ pub struct ObservableBackend<T: InMemoryBackend> {
}

impl<T: InMemoryBackend> ObservableBackend<T> {
/// Creates a new instantiator for an ObservableBackend wrapping the given backend.
/// Returns both the instantiator and a BackendObserver for collecting events.
/// Creates a new instantiator for an ObservableBackend wrapping the given
/// backend. Returns both the instantiator and a BackendObserver for
/// collecting events.
pub fn instantiator<I>(
inner_instantiator: I,
) -> (
Expand Down Expand Up @@ -961,33 +964,34 @@ where

#[cfg(test)]
mod tests {
use super::*;
use pixi_build_types::{BinaryPackageSpecV1, PackageSpecV1};
use pixi_build_types::{BinaryPackageSpec, PackageSpec};
use rattler_conda_types::{ParseStrictness, VersionSpec};

use super::*;

#[test]
fn test_is_star_requirement_with_star() {
let spec = PackageSpecV1::Binary(Box::new(BinaryPackageSpecV1 {
let spec = PackageSpec::Binary(BinaryPackageSpec {
version: Some(VersionSpec::from_str("*", ParseStrictness::Lenient).unwrap()),
..Default::default()
}));
});

assert!(is_star_requirement(&spec));
}

#[test]
fn test_is_star_requirement_with_version() {
let spec = PackageSpecV1::Binary(Box::new(BinaryPackageSpecV1 {
let spec = PackageSpec::Binary(BinaryPackageSpec {
version: Some(VersionSpec::from_str(">=1.0", ParseStrictness::Lenient).unwrap()),
..Default::default()
}));
});

assert!(!is_star_requirement(&spec));
}

#[test]
fn test_is_star_requirement_with_no_version() {
let spec = PackageSpecV1::Binary(Box::default());
let spec = PackageSpec::Binary(BinaryPackageSpec::default());

assert!(is_star_requirement(&spec));
}
Expand Down
24 changes: 4 additions & 20 deletions crates/pixi_build_discovery/src/backend_spec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pixi_spec::{BinarySpec, PixiSpec, SourceAnchor, SourceSpec};
use pixi_spec::{BinarySpec, PixiSpec, SourceAnchor};
use pixi_spec_containers::DependencyMap;
use rattler_conda_types::ChannelUrl;
/// Describes how a backend should be instantiated.
Expand Down Expand Up @@ -41,19 +41,8 @@ impl JsonRpcBackendSpec {
name: self.name,
command: {
match self.command {
CommandSpec::EnvironmentSpec(mut env_spec) => {
let maybe_source_spec = env_spec.requirement.1.try_into_source_spec();
let pixi_spec = match maybe_source_spec {
Ok(source_spec) => {
let resolved_spec = source_anchor.resolve(source_spec.location);
PixiSpec::from(SourceSpec {
location: resolved_spec,
})
}
Err(pixi_spec) => pixi_spec,
};
env_spec.requirement.1 = pixi_spec;
CommandSpec::EnvironmentSpec(env_spec)
CommandSpec::EnvironmentSpec(env_spec) => {
CommandSpec::EnvironmentSpec(Box::new(env_spec.resolve(source_anchor)))
}
CommandSpec::System(system_spec) => CommandSpec::System(system_spec),
}
Expand Down Expand Up @@ -134,12 +123,7 @@ impl EnvironmentSpec {
pub fn resolve(mut self, source_anchor: SourceAnchor) -> Self {
let maybe_source_spec = self.requirement.1.try_into_source_spec();
let pixi_spec = match maybe_source_spec {
Ok(source_spec) => {
let resolved_spec = source_anchor.resolve(source_spec.location);
PixiSpec::from(SourceSpec {
location: resolved_spec,
})
}
Ok(source_spec) => PixiSpec::from(source_spec.resolve(&source_anchor)),
Err(pixi_spec) => pixi_spec,
};
self.requirement.1 = pixi_spec;
Expand Down
Loading
Loading