hakari is the library underlying cargo hakari, a tool to
manage workspace-hack packages.
```rust use guppy::MetadataCommand; use hakari::{HakariBuilder, HakariOutputOptions};
// Use this workspace's PackageGraph for these tests. let packagegraph = MetadataCommand::new() .buildgraph() .expect("obtained cargo-guppy's PackageGraph");
// The second argument to HakariBuilder::new specifies a Hakari (workspace-hack) package. For // the cargo-guppy repository it is called "workspace-hack". let hakaripackage = packagegraph.workspace().memberbyname("workspace-hack").unwrap().id(); let hakaribuilder = HakariBuilder::new(&packagegraph, Some(hakari_package)) .expect("HakariBuilder was constructed");
// HakariBuilder has a number of config options. For this example, use the defaults. let hakari = hakari_builder.compute();
// hakari can be used to build a TOML representation that forms part of a Cargo.toml file. // Existing Cargo.toml files can be managed using Hakari::readtoml. let toml = hakari.totoml_string(&HakariOutputOptions::default()).expect("TOML output was constructed");
// toml contains the Cargo.toml [dependencies] that would go in the Hakari package. It can be
// written out through HakariCargoToml (returned by Hakari::read_toml) or manually.
println!("Cargo.toml contents:\n{}", toml);
```
The cargo-guppy repository uses a workspace-hack crate managed by cargo hakari. See the
generated Cargo.toml.
The cargo-guppy repository also has a number of fixtures that demonstrate Hakari's output.
Here is an example.
hakari worksHakari follows a three-step process.
A HakariBuilder provides options to configure how a Hakari computation is done. Options supported
include:
* the location of the workspace-hack package
* platforms to simulate Cargo builds on
* the version of the Cargo resolver to use
* packages to be excluded during computation
* packages to be excluded from the final output
With the optional cli-support feature, HakariBuilder options can be
read from or written to
a file as TOML or some other format.
Once a HakariBuilder is configured, its compute method can be
called to create a Hakari instance. The algorithm runs in three steps:
workspace-hack package
through step 3 below, it is possible that it causes some extra packages to be built with a
second feature set. Look for such packages, add them to the output map, and iterate until a
fixpoint is reached and no new packages are built more than one way.This computation is done in a parallel fashion, using the Rayon library.
The result of this computation is a Hakari instance.
The last step is to serialize the contents of the output map into the workspace-hack package's
Cargo.toml file.
[Hakari::read_toml] reads an existing Cargo.toml file on disk. This file is
partially generated:
```toml [package] name = "workspace-hack" version = "0.1.0"
...
```
The contents outside the BEGIN HAKARI SECTION and END HAKARI SECTION lines may be
edited by hand. The contents within this section are automatically generated.
On success, a HakariCargoToml is returned.
Hakari::to_toml_string returns the new contents of the
automatically generated section.
HakariCargoToml::write_to_file writes out the contents
to disk.HakariCargoToml also supports serializing contents to memory and producing diffs.
hakari is still missing a few features:
syn but not any others)These features will be added as time permits.
See the CONTRIBUTING file for how to help out.
This project is available under the terms of either the Apache 2.0 license or the MIT license.