Skip to content

Commit

Permalink
initial commit for optional dependencies support in resolvo
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Jan 29, 2025
1 parent 7e1bd18 commit 8c60946
Show file tree
Hide file tree
Showing 6 changed files with 548 additions and 81 deletions.
40 changes: 40 additions & 0 deletions cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,41 @@ impl From<SolvableId> for resolvo::SolvableId {
}
}

/// A wrapper around an optional string id.
/// cbindgen:derive-eq
/// cbindgen:derive-neq
#[repr(C)]
#[derive(Copy, Clone)]
pub struct FfiOptionStringId {
pub is_some: bool,
pub value: StringId,
}

impl From<Option<resolvo::StringId>> for FfiOptionStringId {
fn from(opt: Option<resolvo::StringId>) -> Self {
match opt {
Some(v) => Self {
is_some: true,
value: v.into(),
},
None => Self {
is_some: false,
value: StringId { id: 0 },
},
}
}
}

impl From<FfiOptionStringId> for Option<resolvo::StringId> {
fn from(ffi: FfiOptionStringId) -> Self {
if ffi.is_some {
Some(ffi.value.into())
} else {
None
}
}
}

/// A wrapper around an optional version set id.
/// cbindgen:derive-eq
/// cbindgen:derive-neq
Expand Down Expand Up @@ -100,13 +135,15 @@ impl From<FfiOptionVersionSetId> for Option<VersionSetId> {
pub struct ConditionalRequirement {
pub condition: FfiOptionVersionSetId,
pub requirement: Requirement,
pub extra: FfiOptionStringId,
}

impl From<resolvo::ConditionalRequirement> for ConditionalRequirement {
fn from(value: resolvo::ConditionalRequirement) -> Self {
Self {
condition: value.condition.into(),
requirement: value.requirement.into(),
extra: value.extra.into(),
}
}
}
Expand All @@ -116,6 +153,7 @@ impl From<ConditionalRequirement> for resolvo::ConditionalRequirement {
Self {
condition: value.condition.into(),
requirement: value.requirement.into(),
extra: value.extra.into(),
}
}
}
Expand Down Expand Up @@ -622,6 +660,7 @@ pub extern "C" fn resolvo_conditional_requirement_single(
ConditionalRequirement {
condition: Option::<VersionSetId>::None.into(),
requirement: Requirement::Single(version_set_id),
extra: None.into(),
}
}

Expand All @@ -633,6 +672,7 @@ pub extern "C" fn resolvo_conditional_requirement_union(
ConditionalRequirement {
condition: Option::<VersionSetId>::None.into(),
requirement: Requirement::Union(version_set_union_id),
extra: None.into(),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ impl Conflict {
}
}
}
&Clause::RequiresWithExtra(..) => todo!(),
&Clause::ConditionalWithExtra(..) => todo!(),
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/requirement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Interner, VersionSetId, VersionSetUnionId};
use crate::{Interner, StringId, VersionSetId, VersionSetUnionId};
use itertools::Itertools;
use std::fmt::Display;

Expand All @@ -10,14 +10,21 @@ pub struct ConditionalRequirement {
pub condition: Option<VersionSetId>,
/// The requirement that is only active when the condition is met.
pub requirement: Requirement,
/// The extra that must be enabled for the requirement to be active.
pub extra: Option<StringId>,
}

impl ConditionalRequirement {
/// Creates a new conditional requirement.
pub fn new(condition: Option<VersionSetId>, requirement: Requirement) -> Self {
pub fn new(
condition: Option<VersionSetId>,
requirement: Requirement,
extra: Option<StringId>,
) -> Self {
Self {
condition,
requirement,
extra,
}
}
/// Returns the version sets that satisfy the requirement.
Expand Down Expand Up @@ -49,6 +56,7 @@ impl From<Requirement> for ConditionalRequirement {
Self {
condition: None,
requirement: value,
extra: None,
}
}
}
Expand All @@ -58,6 +66,7 @@ impl From<VersionSetId> for ConditionalRequirement {
Self {
condition: None,
requirement: value.into(),
extra: None,
}
}
}
Expand All @@ -67,6 +76,7 @@ impl From<VersionSetUnionId> for ConditionalRequirement {
Self {
condition: None,
requirement: value.into(),
extra: None,
}
}
}
Expand All @@ -76,6 +86,7 @@ impl From<(VersionSetId, Option<VersionSetId>)> for ConditionalRequirement {
Self {
condition,
requirement: requirement.into(),
extra: None,
}
}
}
Expand Down
Loading

0 comments on commit 8c60946

Please sign in to comment.