|
| 1 | +# PubGrub version solving algorithm. |
| 2 | + |
| 3 | +[package documentation](https://mpizenberg.github.io/pubgrub-rs/pubgrub/) |
| 4 | + |
| 5 | +It consists in efficiently finding a set of packages and versions |
| 6 | +that satisfy all the constraints of a given project dependencies. |
| 7 | +In addition, when that is not possible, |
| 8 | +PubGrub tries to provide a very human-readable and clear |
| 9 | +explanation as to why that failed. |
| 10 | +Below is an example of explanation present in |
| 11 | +the introductory blog post about PubGrub |
| 12 | + |
| 13 | +```txt |
| 14 | +Because dropdown >=2.0.0 depends on icons >=2.0.0 and |
| 15 | + root depends on icons <2.0.0, dropdown >=2.0.0 is forbidden. |
| 16 | +
|
| 17 | +And because menu >=1.1.0 depends on dropdown >=2.0.0, |
| 18 | + menu >=1.1.0 is forbidden. |
| 19 | +
|
| 20 | +And because menu <1.1.0 depends on dropdown >=1.0.0 <2.0.0 |
| 21 | + which depends on intl <4.0.0, every version of menu |
| 22 | + requires intl <4.0.0. |
| 23 | +
|
| 24 | +So, because root depends on both menu >=1.0.0 and intl >=5.0.0, |
| 25 | + version solving failed. |
| 26 | +``` |
| 27 | + |
| 28 | +The algorithm is generic and works for any type of dependency system |
| 29 | +as long as packages (P) and versions (V) implement |
| 30 | +the `Package` and `Version` traits. |
| 31 | +`Package` is strictly equivalent and automatically generated |
| 32 | +for any type that implement `Clone + Eq + Hash + Debug + Display`. |
| 33 | +`Version` simply states that versions are ordered, |
| 34 | +that there should be |
| 35 | +a minimal `lowest` version (like 0.0.0 in semantic versions), |
| 36 | +and that for any version, it is possible to compute |
| 37 | +what the next version closest to this one is (`bump`). |
| 38 | +For semantic versions, `bump` corresponds to an increment of the patch number. |
| 39 | + |
| 40 | + |
| 41 | +## API |
| 42 | + |
| 43 | +```rust |
| 44 | +solution = solver.run(package, version)?; |
| 45 | +``` |
| 46 | + |
| 47 | +Where `solver` provides the list of available packages and versions, |
| 48 | +as well as the dependencies of every available package |
| 49 | +by implementing the `Solver` trait. |
| 50 | +The call to `run` for a given package at a given version |
| 51 | +will compute the set of packages and versions needed |
| 52 | +to satisfy the dependencies of that package and version pair. |
| 53 | +If there is no solution, the reason will be provided as clear as possible. |
| 54 | + |
| 55 | + |
| 56 | +## PubGrub |
| 57 | + |
| 58 | +PubGrub is a version solving algorithm, |
| 59 | +written in 2018 by Natalie Weizenbaum |
| 60 | +for the Dart package manager. |
| 61 | +It is supposed to be very fast and to explain errors |
| 62 | +more clearly than the alternatives. |
| 63 | +An introductory blog post was |
| 64 | +[published on Medium][medium-pubgrub] by its author. |
| 65 | + |
| 66 | +The detailed explanation of the algorithm is |
| 67 | +[provided on GitHub][github-pubgrub]. |
| 68 | +The foundation of the algorithm is based on ASP (Answer Set Programming) |
| 69 | +and a book called |
| 70 | +"[Answer Set Solving in Practice][potassco-book]" |
| 71 | +by Martin Gebser, Roland Kaminski, Benjamin Kaufmann and Torsten Schaub. |
| 72 | + |
| 73 | +[medium-pubgrub]: https://medium.com/@nex3/pubgrub-2fb6470504f |
| 74 | +[github-pubgrub]: https://github.com/dart-lang/pub/blob/master/doc/solver.md |
| 75 | +[potassco-book]: https://potassco.org/book/ |
0 commit comments