Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into refactor/binary_enc…
Browse files Browse the repository at this point in the history
…oding
  • Loading branch information
baszalmstra committed Aug 14, 2024
2 parents 1ba5ecf + 2700ea0 commit 1d1a903
Show file tree
Hide file tree
Showing 26 changed files with 2,291 additions and 1,395 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cpp-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v4
- name: Build conda package
uses: prefix-dev/rattler-build-action@v0.2.11
uses: prefix-dev/rattler-build-action@v0.2.13
with:
recipe-path: recipe/recipe.yaml
# needs to be unique for each matrix entry
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.0](https://github.com/mamba-org/resolvo/compare/resolvo-v0.6.2...resolvo-v0.7.0) - 2024-08-06

### Added
- *(solver)* [**breaking**] Solve for optional solvables in addition to the root solvable ([#54](https://github.com/mamba-org/resolvo/pull/54))
- [**breaking**] Version set unions as solvable requirements ([#56](https://github.com/mamba-org/resolvo/pull/56))

### Fixed
- Fix off-by-one error in `Mapping::serialize` ([#58](https://github.com/mamba-org/resolvo/pull/58))

### Other
- *(ci)* bump prefix-dev/rattler-build-action from 0.2.12 to 0.2.13 ([#59](https://github.com/mamba-org/resolvo/pull/59))
- *(ci)* bump prefix-dev/rattler-build-action from 0.2.11 to 0.2.12 ([#57](https://github.com/mamba-org/resolvo/pull/57))
- Add more tracing ([#55](https://github.com/mamba-org/resolvo/pull/55))
- *(ci)* bump prefix-dev/rattler-build-action from 0.2.10 to 0.2.11 ([#53](https://github.com/mamba-org/resolvo/pull/53))
- *(ci)* bump prefix-dev/rattler-build-action from 0.2.9 to 0.2.10 ([#51](https://github.com/mamba-org/resolvo/pull/51))

## [0.6.2](https://github.com/mamba-org/resolvo/compare/resolvo-v0.6.1...resolvo-v0.6.2) - 2024-06-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["cpp", "tools/*"]
resolver = "2"

[workspace.package]
version = "0.6.2"
version = "0.7.0"
authors = ["Adolfo Ochagavía <github@adolfo.ochagavia.nl>", "Bas Zalmstra <zalmstra.bas@gmail.com>", "Tim de Jager <tdejager89@gmail.com>"]
homepage = "https://github.com/mamba-org/resolvo"
repository = "https://github.com/mamba-org/resolvo"
Expand Down
2 changes: 1 addition & 1 deletion cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish = false
crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
resolvo = { version = "0.6.2", path = "../" }
resolvo = { version = "0.7.0", path = "../" }

[build-dependencies]
anyhow = "1"
Expand Down
26 changes: 23 additions & 3 deletions cpp/include/resolvo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
#include "resolvo_internal.h"

namespace resolvo {
using cbindgen_private::Problem;
using cbindgen_private::Requirement;

/**
* Specifies a requirement (dependency) of a single version set.
*/
inline Requirement requirement_single(VersionSetId id) {
return cbindgen_private::resolvo_requirement_single(id);
}

/**
* Specifies a requirement (dependency) of the union (logical OR) of multiple version sets.
* A solvable belonging to any of the version sets contained in the union satisfies the
* requirement. This variant is typically used for requirements that can be satisfied by two
* or more version sets belonging to different packages.
*/
inline Requirement requirement_union(VersionSetUnionId id) {
return cbindgen_private::resolvo_requirement_union(id);
}

/**
* Called to solve a package problem.
Expand All @@ -12,8 +31,8 @@ namespace resolvo {
* stored in `result`. If the solve was unsuccesfull an error describing the reason is returned and
* the result vector will be empty.
*/
inline String solve(DependencyProvider &provider, Slice<VersionSetId> requirements,
Slice<VersionSetId> constraints, Vector<SolvableId> &result) {
inline String solve(DependencyProvider &provider, const Problem &problem,
Vector<SolvableId> &result) {
cbindgen_private::DependencyProvider bridge{
static_cast<void *>(&provider),
private_api::bridge_display_solvable,
Expand All @@ -24,14 +43,15 @@ inline String solve(DependencyProvider &provider, Slice<VersionSetId> requiremen
private_api::bridge_display_string,
private_api::bridge_version_set_name,
private_api::bridge_solvable_name,
private_api::bridge_version_sets_in_union,
private_api::bridge_get_candidates,
private_api::bridge_sort_candidates,
private_api::bridge_filter_candidates,
private_api::bridge_get_dependencies,
};

String error;
cbindgen_private::resolvo_solve(&bridge, requirements, constraints, &error, &result);
cbindgen_private::resolvo_solve(&bridge, &problem, &error, &result);
return error;
}
} // namespace resolvo
15 changes: 15 additions & 0 deletions cpp/include/resolvo_dependency_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using cbindgen_private::NameId;
using cbindgen_private::SolvableId;
using cbindgen_private::StringId;
using cbindgen_private::VersionSetId;
using cbindgen_private::VersionSetUnionId;

/**
* An interface that implements ecosystem specific logic.
Expand Down Expand Up @@ -75,6 +76,11 @@ struct DependencyProvider {
*/
virtual NameId solvable_name(SolvableId solvable_id) = 0;

/**
* Returns the version sets comprising the given union.
*/
virtual Slice<VersionSetId> version_sets_in_union(VersionSetUnionId version_set_union_id) = 0;

/**
* Obtains a list of solvables that should be considered when a package
* with the given name is requested.
Expand Down Expand Up @@ -133,6 +139,15 @@ extern "C" inline NameId bridge_solvable_name(void *data, SolvableId solvable_id
return reinterpret_cast<DependencyProvider *>(data)->solvable_name(solvable_id);
}

// HACK(clang): For some reason, clang needs this to know that the return type is complete
static_assert(sizeof(Slice<VersionSetId>));

extern "C" inline Slice<VersionSetId> bridge_version_sets_in_union(
void *data, VersionSetUnionId version_set_union_id) {
return reinterpret_cast<DependencyProvider *>(data)->version_sets_in_union(
version_set_union_id);
}

extern "C" inline void bridge_get_candidates(void *data, NameId package, Candidates *result) {
*result = reinterpret_cast<DependencyProvider *>(data)->get_candidates(package);
}
Expand Down
142 changes: 127 additions & 15 deletions cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,66 @@ impl From<SolvableId> for resolvo::SolvableId {
}
}

/// Specifies the dependency of a solvable on a set of version sets.
/// cbindgen:derive-eq
/// cbindgen:derive-neq
#[repr(C)]
#[derive(Copy, Clone)]
pub enum Requirement {
/// Specifies a dependency on a single version set.
/// cbindgen:derive-eq
/// cbindgen:derive-neq
Single(VersionSetId),
/// Specifies a dependency on the union (logical OR) of multiple version sets. A solvable
/// belonging to ANY of the version sets contained in the union satisfies the requirement.
/// This variant is typically used for requirements that can be satisfied by two or more
/// version sets belonging to different packages.
/// cbindgen:derive-eq
/// cbindgen:derive-neq
Union(VersionSetUnionId),
}

impl From<resolvo::Requirement> for crate::Requirement {
fn from(value: resolvo::Requirement) -> Self {
match value {
resolvo::Requirement::Single(id) => Requirement::Single(id.into()),
resolvo::Requirement::Union(id) => Requirement::Union(id.into()),
}
}
}

impl From<crate::Requirement> for resolvo::Requirement {
fn from(value: crate::Requirement) -> Self {
match value {
Requirement::Single(id) => resolvo::Requirement::Single(id.into()),
Requirement::Union(id) => resolvo::Requirement::Union(id.into()),
}
}
}

/// A unique identifier for a version set union. A version set union describes
/// the union (logical OR) of a non-empty set of version sets belonging to
/// more than one package.
/// cbindgen:derive-eq
/// cbindgen:derive-neq
#[repr(C)]
#[derive(Copy, Clone)]
pub struct VersionSetUnionId {
id: u32,
}

impl From<resolvo::VersionSetUnionId> for crate::VersionSetUnionId {
fn from(id: resolvo::VersionSetUnionId) -> Self {
Self { id: id.0 }
}
}

impl From<crate::VersionSetUnionId> for resolvo::VersionSetUnionId {
fn from(id: crate::VersionSetUnionId) -> Self {
Self(id.id)
}
}

/// A unique identifier for a single version set. A version set describes a
/// set of versions.
/// cbindgen:derive-eq
Expand Down Expand Up @@ -102,7 +162,7 @@ pub struct Dependencies {
/// A pointer to the first element of a list of requirements. Requirements
/// defines which packages should be installed alongside the depending
/// package and the constraints applied to the package.
pub requirements: Vector<VersionSetId>,
pub requirements: Vector<Requirement>,

/// Defines additional constraints on packages that may or may not be part
/// of the solution. Different from `requirements`, packages in this set
Expand Down Expand Up @@ -230,6 +290,12 @@ pub struct DependencyProvider {
/// Returns the name of the package for the given solvable.
pub solvable_name: unsafe extern "C" fn(data: *mut c_void, solvable_id: SolvableId) -> NameId,

/// Returns the version sets comprising the given union.
pub version_sets_in_union: unsafe extern "C" fn(
data: *mut c_void,
version_set_union_id: VersionSetUnionId,
) -> Slice<'static, VersionSetId>,

/// Obtains a list of solvables that should be considered when a package
/// with the given name is requested.
pub get_candidates:
Expand Down Expand Up @@ -314,6 +380,17 @@ impl<'d> resolvo::Interner for &'d DependencyProvider {
fn solvable_name(&self, solvable: resolvo::SolvableId) -> resolvo::NameId {
unsafe { (self.solvable_name)(self.data, solvable.into()) }.into()
}

fn version_sets_in_union(
&self,
version_set_union: resolvo::VersionSetUnionId,
) -> impl Iterator<Item = resolvo::VersionSetId> {
unsafe { (self.version_sets_in_union)(self.data, version_set_union.into()) }
.as_slice()
.into_iter()
.copied()
.map(Into::into)
}
}

impl<'d> resolvo::DependencyProvider for &'d DependencyProvider {
Expand Down Expand Up @@ -396,28 +473,49 @@ impl<'d> resolvo::DependencyProvider for &'d DependencyProvider {
}
}

#[repr(C)]
pub struct Problem<'a> {
pub requirements: Slice<'a, Requirement>,
pub constraints: Slice<'a, VersionSetId>,
pub soft_requirements: Slice<'a, SolvableId>,
}

#[no_mangle]
#[allow(unused)]
pub extern "C" fn resolvo_solve(
provider: &DependencyProvider,
requirements: Slice<VersionSetId>,
constraints: Slice<VersionSetId>,
problem: &Problem,
error: &mut String,
result: &mut Vector<SolvableId>,
) -> bool {
let requirements = requirements
.into_iter()
.copied()
.map(Into::into)
.collect::<Vec<_>>();
let constraints = constraints
.into_iter()
.copied()
.map(Into::into)
.collect::<Vec<_>>();

let mut solver = resolvo::Solver::new(provider);
match solver.solve(requirements, constraints) {

let problem = resolvo::Problem::new()
.requirements(
problem
.requirements
.into_iter()
.copied()
.map(Into::into)
.collect(),
)
.constraints(
problem
.constraints
.into_iter()
.copied()
.map(Into::into)
.collect(),
)
.soft_requirements(
problem
.soft_requirements
.into_iter()
.copied()
.map(Into::into),
);

match solver.solve(problem) {
Ok(solution) => {
*result = solution.into_iter().map(Into::into).collect();
true
Expand All @@ -433,6 +531,20 @@ pub extern "C" fn resolvo_solve(
}
}

#[no_mangle]
#[allow(unused)]
pub extern "C" fn resolvo_requirement_single(version_set_id: VersionSetId) -> Requirement {
Requirement::Single(version_set_id)
}

#[no_mangle]
#[allow(unused)]
pub extern "C" fn resolvo_requirement_union(
version_set_union_id: VersionSetUnionId,
) -> Requirement {
Requirement::Union(version_set_union_id)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit 1d1a903

Please sign in to comment.