[vlc-devel] [PATCHv2 3/8] contrib: add rust rules

Thomas Guillem thomas at gllm.fr
Wed Aug 26 14:42:00 CEST 2020


This adds CARGO_INSTALL and CARGOC_INSTALL, using the correct cargo path (from
contribs) and using the correct install arguments.

This also adds rules for managing 'cargo vendor' archives:
 - .cargo-vendor-sum-<project>:
 - .cargo-vendor-<project>:

cf. https://doc.rust-lang.org/cargo/commands/cargo-vendor.html
'cargo vendor' fetch all dependencies required by a Rust project.

Administrators will be able to create an archive (via the upcoming
cargo-vendor-archive.sh script) containing all dependencies of a Rust project
and upload it to the VideoLAN FTP.

The .cargo-vendor-* rules will try to use such archive as the only crates
source. In case of failure (checksum failed, archive not uploaded),
CARGO_INSTALL will fallback to crates.io (by not using the --frozen --offline
arguments).

A warning is displayed when the crates.io source is used. This is like our
download_pkg mechanism (try first VideoLAN FTP, or print a warning and use the
original source).
---
 contrib/src/main-rust.mak | 41 +++++++++++++++++++++++++++++++++++++++
 contrib/src/main.mak      |  2 +-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/contrib/src/main-rust.mak b/contrib/src/main-rust.mak
index ca272e25e21..d9bfef96137 100644
--- a/contrib/src/main-rust.mak
+++ b/contrib/src/main-rust.mak
@@ -18,3 +18,44 @@ RUST_TARGET = x86_64-sun-solaris
 else ifdef HAVE_LINUX
 RUST_TARGET = $(ARCH)-unknown-linux-gnu
 endif
+
+CARGO_HOME = $(BUILDBINDIR)/.cargo
+
+CARGO = CARGO_HOME=$(CARGO_HOME) $(CARGO_HOME)/bin/cargo
+
+CARGO_INSTALL_ARGS = --target=$(RUST_TARGET) --prefix=$(PREFIX) \
+	--library-type staticlib --release
+
+# Use the .cargo-vendor source if present, otherwise use crates.io
+CARGO_INSTALL_ARGS += \
+	$(shell test -d $</.cargo-vendor && echo --frozen --offline || echo --locked)
+
+CARGO_INSTALL = $(CARGO) install $(CARGO_INSTALL_ARGS)
+
+CARGOC_INSTALL = $(CARGO) capi install $(CARGO_INSTALL_ARGS)
+
+# Check the cargo vendor archive checksum. A fail is not critical (if the
+# archive is not present or the videolan server is down), and will make cargo
+# fallback to crates.io
+.cargo-vendor-sum-%: $(SRC)/%/cargo-vendor-SHA512SUMS
+	-$(call checksum,$(SHA512SUM),cargo-vendor-SHA512,.cargo-vendor-sum) \
+		&& echo 1 > $@ || echo 0 > $@
+
+download_vendor = \
+	$(call download,$(1)) || (\
+		echo "" && \
+		echo "WARNING: cargo vendor archive for $(1) invalid, fallback to crates.io" && \
+		echo "");
+
+# Unpack, install and setup the cargo vendor archive into the project folder
+UNPACK_CARGO_VENDOR = \
+	if test "$(shell cat .cargo-vendor-sum-$@)" = "1"; then \
+		tar xvjfo $(patsubst %.tar,%,$(basename $<))-vendor.tar.bz2; \
+		mv $(UNPACK_DIR)-vendor $(UNPACK_DIR)/.cargo-vendor; \
+		mkdir -p $(UNPACK_DIR)/.cargo; \
+		echo "[source.crates-io]" > $(UNPACK_DIR)/.cargo/config.toml; \
+		echo "replace-with = \"vendored-sources\"" >> $(UNPACK_DIR)/.cargo/config.toml; \
+		echo "[source.vendored-sources]" >> $(UNPACK_DIR)/.cargo/config.toml; \
+		echo "directory = \".cargo-vendor\"" >> $(UNPACK_DIR)/.cargo/config.toml; \
+		echo "Using cargo vendor archive for $(UNPACK_DIR)"; \
+	fi;
diff --git a/contrib/src/main.mak b/contrib/src/main.mak
index d0df860a954..47929a60dc6 100644
--- a/contrib/src/main.mak
+++ b/contrib/src/main.mak
@@ -483,7 +483,7 @@ fetch-all: $(PKGS_ALL:%=.sum-%)
 install: $(PKGS:%=.%)
 
 mostlyclean:
-	-$(RM) $(foreach p,$(PKGS_ALL),.$(p) .sum-$(p) .dep-$(p))
+	-$(RM) $(foreach p,$(PKGS_ALL),.$(p) .sum-$(p) .cargo-vendor-sum-$(p) .dep-$(p))
 	-$(RM) toolchain.cmake
 	-$(RM) crossfile.meson
 	-$(RM) -R "$(PREFIX)"
-- 
2.28.0



More information about the vlc-devel mailing list