Skip to content

Commit 54e555a

Browse files
committed
Allow multi-version openssl/abseil alongside unicode
Generalize the unicode.org hydrate special-case so parallel-installable ABI lines (openssl 1.1 vs 3, abseil LTS namespaces) can coexist in one graph instead of failing constraint intersection.
1 parent 614dca6 commit 54e555a

9 files changed

Lines changed: 265 additions & 43 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ jobs:
7272
with:
7373
tool: cargo-tarpaulin
7474
- run: cargo tarpaulin -o lcov --output-dir coverage
75+
- run: brew trust coverallsapp/coveralls
76+
if: matrix.os == 'macos-latest'
7577
- uses: coverallsapp/github-action@v2
7678
with:
7779
path-to-lcov: coverage/lcov.info
@@ -234,6 +236,8 @@ jobs:
234236
-Xdemangler=rustfilt \
235237
> lcov.info
236238
239+
- run: brew trust coverallsapp/coveralls
240+
if: matrix.os == 'macos-latest'
237241
- uses: coverallsapp/github-action@v2
238242
with:
239243
path-to-lcov: lcov.info

‎crates/cli/src/resolve.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub async fn resolve(
8787
let mut installations = resolution.installed;
8888
if !resolution.pending.is_empty() {
8989
if env::var("PKGX_NO_INSTALL").is_ok() {
90-
return Err("PKGX_NO_INSTALL is set, refusing to install pending packages")?;
90+
Err("PKGX_NO_INSTALL is set, refusing to install pending packages")?;
9191
}
9292
let installed = install_multi(&resolution.pending, config, spinner.arc()).await?;
9393
installations.extend(installed);

‎crates/lib/src/env.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub fn expand_moustaches(input: &str, pkg: &Installation, deps: &Vec<Installatio
211211
}
212212

213213
output = output.replace("{{prefix}}", &pkg.path.to_string_lossy());
214-
output = output.replace("{{version}}", &format!("{}", &pkg.pkg.version));
214+
output = output.replace("{{version}}", &format!("{}", pkg.pkg.version));
215215
output = output.replace("{{version.major}}", &format!("{}", pkg.pkg.version.major));
216216
output = output.replace("{{version.minor}}", &format!("{}", pkg.pkg.version.minor));
217217
output = output.replace("{{version.patch}}", &format!("{}", pkg.pkg.version.patch));
@@ -228,7 +228,7 @@ pub fn expand_moustaches(input: &str, pkg: &Installation, deps: &Vec<Installatio
228228
);
229229
output = output.replace(
230230
&format!("{{{{{}.version}}}}", prefix),
231-
&format!("{}", &dep.pkg.version),
231+
&format!("{}", dep.pkg.version),
232232
);
233233
output = output.replace(
234234
&format!("{{{{{}.version.major}}}}", prefix),

‎crates/lib/src/hydrate.rs‎

Lines changed: 92 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
use crate::types::PackageReq;
22
use libsemverator::range::Range as VersionReq;
3-
use std::collections::{HashMap, HashSet};
3+
use std::collections::HashMap;
44
use std::error::Error;
55

6+
/// Projects whose distinct version lines are parallel-installable (different
7+
/// sonames / ICU majors / abseil LTS namespaces). When constraints cannot
8+
/// intersect we keep the extra lines as separate `PackageReq` entries instead
9+
/// of failing the graph. Note: these extra lines are surfaced in the resolved
10+
/// set but their own deps are not re-hydrated — fine while alt-line deps match
11+
/// the primary line (openssl/abseil/unicode), revisit if that stops holding.
12+
///
13+
/// - unicode.org: ICU major ABI (see pantry#4104, pkgx#899)
14+
/// - openssl.org: libssl.so.1.1 vs libssl.so.3
15+
/// - abseil.io: LTS inline-namespace + soversion (20250127 vs 20250512, …)
16+
const MULTI_VERSION_PROJECTS: &[&str] = &["unicode.org", "openssl.org", "abseil.io"];
17+
18+
fn is_multi_version(project: &str) -> bool {
19+
MULTI_VERSION_PROJECTS.contains(&project)
20+
}
21+
22+
/// Record an extra constraint for a multi-version project, merging into an
23+
/// existing additional entry when the ranges intersect.
24+
fn push_additional(additional: &mut Vec<PackageReq>, pkg: PackageReq) {
25+
for existing in additional.iter_mut().filter(|p| p.project == pkg.project) {
26+
if let Ok(constraint) = intersect_constraints(&existing.constraint, &pkg.constraint) {
27+
existing.constraint = constraint;
28+
return;
29+
}
30+
}
31+
additional.push(pkg);
32+
}
33+
634
#[derive(Clone)]
735
struct Node {
836
parent: Option<Box<Node>>,
937
pkg: PackageReq,
10-
children: HashSet<String>,
1138
}
1239

1340
impl Node {
1441
fn new(pkg: PackageReq, parent: Option<Box<Node>>) -> Self {
15-
Self {
16-
parent,
17-
pkg,
18-
children: HashSet::new(),
19-
}
42+
Self { parent, pkg }
2043
}
2144

2245
fn count(&self) -> usize {
@@ -38,36 +61,55 @@ pub async fn hydrate<F>(
3861
where
3962
F: Fn(String) -> Result<Vec<PackageReq>, Box<dyn Error>>,
4063
{
41-
let dry = condense(input);
64+
let dry = condense(input)?;
4265
let mut graph: HashMap<String, Box<Node>> = HashMap::new();
4366
let mut stack: Vec<Box<Node>> = vec![];
44-
let mut additional_unicodes: Vec<VersionReq> = vec![];
67+
let mut additional: Vec<PackageReq> = vec![];
4568

4669
for pkg in dry.iter() {
47-
let node = graph
48-
.entry(pkg.project.clone())
49-
.or_insert_with(|| Box::new(Node::new(pkg.clone(), None)));
50-
node.pkg.constraint = intersect_constraints(&node.pkg.constraint, &pkg.constraint)
51-
.map_err(|e| format!("{} for {}", e, pkg.project))?;
52-
stack.push(node.clone());
70+
if let Some(node) = graph.get_mut(&pkg.project) {
71+
match intersect_constraints(&node.pkg.constraint, &pkg.constraint) {
72+
Ok(constraint) => {
73+
node.pkg.constraint = constraint;
74+
stack.push(node.clone());
75+
}
76+
Err(e) => {
77+
if is_multi_version(&pkg.project) {
78+
push_additional(&mut additional, pkg.clone());
79+
} else {
80+
return Err(format!("{} for {}", e, pkg.project).into());
81+
}
82+
}
83+
}
84+
} else {
85+
let node = Box::new(Node::new(pkg.clone(), None));
86+
graph.insert(pkg.project.clone(), node.clone());
87+
stack.push(node);
88+
}
5389
}
5490

55-
while let Some(mut current) = stack.pop() {
91+
while let Some(current) = stack.pop() {
5692
for child_pkg in get_deps(current.pkg.project.clone())? {
93+
let was_new = !graph.contains_key(&child_pkg.project);
5794
let child_node = graph
5895
.entry(child_pkg.project.clone())
5996
.or_insert_with(|| Box::new(Node::new(child_pkg.clone(), Some(current.clone()))));
97+
98+
if was_new {
99+
// Fresh node already carries child_pkg.constraint.
100+
stack.push(child_node.clone());
101+
continue;
102+
}
103+
104+
// Already have a graph node: try the primary constraint, then any
105+
// additional lines for this multi-version project.
60106
let intersection =
61107
intersect_constraints(&child_node.pkg.constraint, &child_pkg.constraint);
62108
if let Ok(constraint) = intersection {
63109
child_node.pkg.constraint = constraint;
64-
current.children.insert(child_node.pkg.project.clone());
65110
stack.push(child_node.clone());
66-
} else if child_pkg.project == "unicode.org" {
67-
// we handle unicode.org for now to allow situations like:
68-
// https://github.com/pkgxdev/pantry/issues/4104
69-
// https://github.com/pkgxdev/pkgx/issues/899
70-
additional_unicodes.push(child_pkg.constraint);
111+
} else if is_multi_version(&child_pkg.project) {
112+
push_additional(&mut additional, child_pkg);
71113
} else {
72114
return Err(
73115
format!("{} for {}", intersection.unwrap_err(), child_pkg.project).into(),
@@ -80,30 +122,45 @@ where
80122
pkgs.sort_by_key(|node| node.count());
81123
let mut pkgs: Vec<PackageReq> = pkgs.into_iter().map(|node| node.pkg.clone()).collect();
82124

83-
// see above explanation
84-
for constraint in additional_unicodes {
85-
let pkg = PackageReq {
86-
project: "unicode.org".to_string(),
87-
constraint,
88-
};
89-
pkgs.push(pkg);
90-
}
125+
pkgs.extend(additional);
91126

92127
Ok(pkgs)
93128
}
94129

95-
/// Condenses a list of `PackageRequirement` by intersecting constraints for duplicates.
96-
fn condense(pkgs: &Vec<PackageReq>) -> Vec<PackageReq> {
130+
/// Condenses a list of `PackageReq` by intersecting constraints for duplicates.
131+
/// Multi-version projects keep non-intersecting constraints as separate entries.
132+
fn condense(pkgs: &Vec<PackageReq>) -> Result<Vec<PackageReq>, Box<dyn Error>> {
97133
let mut out: Vec<PackageReq> = vec![];
98134
for pkg in pkgs {
99135
if let Some(existing) = out.iter_mut().find(|p| p.project == pkg.project) {
100-
existing.constraint = intersect_constraints(&existing.constraint, &pkg.constraint)
101-
.expect("Failed to intersect constraints");
136+
match intersect_constraints(&existing.constraint, &pkg.constraint) {
137+
Ok(constraint) => existing.constraint = constraint,
138+
Err(e) => {
139+
if is_multi_version(&pkg.project) {
140+
// merge into a later non-intersecting sibling if possible
141+
let mut merged = false;
142+
for sibling in out.iter_mut().filter(|p| p.project == pkg.project).skip(1) {
143+
if let Ok(constraint) =
144+
intersect_constraints(&sibling.constraint, &pkg.constraint)
145+
{
146+
sibling.constraint = constraint;
147+
merged = true;
148+
break;
149+
}
150+
}
151+
if !merged {
152+
out.push(pkg.clone());
153+
}
154+
} else {
155+
return Err(format!("{} for {}", e, pkg.project).into());
156+
}
157+
}
158+
}
102159
} else {
103160
out.push(pkg.clone());
104161
}
105162
}
106-
out
163+
Ok(out)
107164
}
108165

109166
/// Intersects two version constraints.

‎crates/lib/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub mod pantry_db;
1111
pub mod platform_case_aware_env_key;
1212
pub mod resolve;
1313
pub mod sync;
14+
#[cfg(test)]
15+
mod tests;
1416
pub mod types;
1517
pub mod utils;
1618

‎crates/lib/src/sync.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ pub async fn update(config: &Config, conn: &mut Connection) -> Result<(), Box<dy
3939
FileExt::unlock(&lockfile)?;
4040
return Ok(());
4141
} else {
42-
return Err(
43-
"PKGX_PANTRY_DIR is set but does not contain a pantry (missing projects/)",
44-
)?;
42+
Err("PKGX_PANTRY_DIR is set but does not contain a pantry (missing projects/)")?;
4543
}
4644
}
4745
replace(config, conn).await

0 commit comments

Comments
 (0)