[Buildroot] [PATCH v1 1/3] package/pkg-cargo: add support to bundle a custom Cargo.lock file
Thomas Devoogdt
thomas at devoogdt.com
Mon Sep 22 07:13:42 UTC 2025
E.g. https://github.com/lu-zero/cargo-c/releases/tag/v0.10.15
Cargo-c releases a separate Cargo.lock file, but doesn't bundle
one in its normal .tar.gz code source target.
We can't use extra downloads/patches/... as cargo is a vendored
package, which is done quite early in the chain.
This patch allows us to define a custom Cargo.lock source.
Both a local bundled file and remote (only wget) file can be linked.
Usage:
<PKG>_CARGO_LOCK_FILE = <PKG>_PKGDIR/Cargo.lock
<PKG>_CARGO_LOCK_FILE = https://.../Cargo.lock
Signed-off-by: Thomas Devoogdt <thomas at devoogdt.com>
---
Superseeds https://patchwork.ozlabs.org/project/buildroot/patch/20250324173246.100112-1-guillaume.chaye@zeetim.com/.
---
package/pkg-cargo.mk | 5 +++++
support/download/cargo-post-process | 14 +++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/package/pkg-cargo.mk b/package/pkg-cargo.mk
index 47a6353f25..626e5ea472 100644
--- a/package/pkg-cargo.mk
+++ b/package/pkg-cargo.mk
@@ -195,6 +195,11 @@ ifneq ($$($(2)_SUBDIR),)
$(2)_DOWNLOAD_POST_PROCESS_OPTS += -m$$($(2)_SUBDIR)/Cargo.toml
endif
+# Allow to download a custom Cargo.lock file.
+ifneq ($$($(3)_CARGO_LOCK_FILE),)
+$(2)_DOWNLOAD_POST_PROCESS_OPTS += -l$$($(3)_CARGO_LOCK_FILE)
+endif
+
# Because we append vendored info, we can't rely on the values being empty
# once we eventually get into the generic-package infra. So, we duplicate
# the heuristics here
diff --git a/support/download/cargo-post-process b/support/download/cargo-post-process
index b0e59ad74d..7913724fe2 100755
--- a/support/download/cargo-post-process
+++ b/support/download/cargo-post-process
@@ -11,11 +11,12 @@ if [ "${BR_CARGO_MANIFEST_PATH}" ]; then
fi
manifest=Cargo.toml
-while getopts "n:o:m:" OPT; do
+while getopts "n:o:m:l:" OPT; do
case "${OPT}" in
o) output="${OPTARG}";;
n) base_name="${OPTARG}";;
m) manifest="${OPTARG}";;
+ l) lockfile="${OPTARG}";;
:) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
\?) error "unknown option '%s'\n" "${OPTARG}";;
esac
@@ -31,6 +32,17 @@ post_process_unpack "${base_name}" "${output}"
# Do the Cargo vendoring
pushd "${base_name}" > /dev/null
+# Copy the custom lockfile path if given
+# TODO: use --lockfile-path once stable
+if [ -n "${lockfile}" ] ; then
+ rm -f "${lockfile}"
+ if [ -f "${lockfile}" ] ; then
+ cp "${lockfile}" Cargo.lock
+ else
+ ${WGET} "${lockfile}" -O Cargo.lock
+ fi
+fi
+
# Create the local .cargo/config.toml with vendor info
mkdir -p .cargo/
mkdir -p "${CARGO_HOME}"
--
2.43.0
More information about the buildroot
mailing list