From 4cfd835c0ca2f1f0e3f0a22f790539f437f91045 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 6 Mar 2022 22:24:58 +0800 Subject: [PATCH] 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). --- xtask/src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 6ef60bf39..87257e560 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -57,7 +57,7 @@ fn main() -> Result<(), Box> { "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 {