allow for explicit version pinning of crates in package specifiers for an image

This works around the issue of a dependendent crate e.g. pulling in a version
of sha2 that is an incompatible API with the one provided by the hardware
accelerator. Cargo needs to know for which sha2 crate to build, and
the current "sha2" specifier is too ambiguous.

This is done by specifying it as "sha2:0.9.8", but, this now breaks
the image creation because the actual artifact built is still a filename
of `sha2`, not `sha2:0.9.8`. This patch both adds the fully specified
version to the sha2 crate and also strips out the trailing version
number without breaking e.g. Windows builds which have a ':' built
into every path (so you can't just do a stupid split(':') to strip
off the version number).
This commit is contained in:
bunnie 2022-03-06 22:24:58 +08:00
parent 5c155587b6
commit 4cfd835c0c

View file

@ -57,7 +57,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"llio",
"susres",
"codec",
"sha2",
"sha2:0.9.8",
"engine-25519",
"spinor",
"root-keys",
@ -588,7 +588,15 @@ fn build_hw_image(
let base_path = build(packages, debug, Some(PROGRAM_TARGET), None, extra_args, None)?;
for pkg in packages {
let mut pkg_path = base_path.clone();
pkg_path.push(pkg);
// some packages may have a colon-delimited version after it to clarify crates.io patches.
// Strip off the version number before passing to the image builder.
let pkg_maybe_version: Vec<&str> = pkg.split(':').collect();
let pkg_root = if pkg_maybe_version.len() > 1 {
pkg_maybe_version[pkg_maybe_version.len() - 2]
} else {
pkg
};
pkg_path.push(pkg_root);
init.push(pkg_path);
}
for pkg in extra_packages {