Fri Aug 14 21:12:04 2020 UTC ()
cargo.mk: some improvements

- rename show-cargo-depends to print-cargo-depends (but keep a compat alias)
- make it print an RCS id preamble with a comment

This allows one to do "make print-cargo-depends > cargo-depends.mk"
and reference cargo-depends.mk from the packages main Makefile.
Makes updating packages easier.


(tnn)
diff -r1.20 -r1.21 pkgsrc/lang/rust/cargo.mk

cvs diff -r1.20 -r1.21 pkgsrc/lang/rust/cargo.mk (expand / switch to unified diff)

--- pkgsrc/lang/rust/cargo.mk 2020/08/14 20:44:16 1.20
+++ pkgsrc/lang/rust/cargo.mk 2020/08/14 21:12:03 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: cargo.mk,v 1.20 2020/08/14 20:44:16 tnn Exp $ 1# $NetBSD: cargo.mk,v 1.21 2020/08/14 21:12:03 tnn Exp $
2# 2#
3# Common logic that can be used by packages that depend on cargo crates 3# Common logic that can be used by packages that depend on cargo crates
4# from crates.io. This lets existing pkgsrc infrastructure fetch and verify 4# from crates.io. This lets existing pkgsrc infrastructure fetch and verify
5# cargo crates instead of using the rust package manager in the build phase. 5# cargo crates instead of using the rust package manager in the build phase.
6# Inspired by cargo.mk from FreeBSD ports. 6# Inspired by cargo.mk from FreeBSD ports.
7# 7#
8# Usage example: 8# Usage example:
9# 9#
10# CARGO_CRATE_DEPENDS+= sha1-0.20 10# CARGO_CRATE_DEPENDS+= sha1-0.20
11# .include "../../lang/rust/cargo.mk" 11# .include "../../lang/rust/cargo.mk"
12# 12#
13# If modifying the list of dependencies, re-run the build once without 13# If modifying the list of dependencies, re-run the build once without
14# --offline in CARGO_ARGS to generate a new valid Cargo.lock. 14# --offline in CARGO_ARGS to generate a new valid Cargo.lock.
@@ -41,31 +41,36 @@ MAKE_JOBS_SAFE= no @@ -41,31 +41,36 @@ MAKE_JOBS_SAFE= no
41post-extract: cargo-vendor-crates 41post-extract: cargo-vendor-crates
42.PHONY: cargo-vendor-crates 42.PHONY: cargo-vendor-crates
43cargo-vendor-crates: 43cargo-vendor-crates:
44 @${STEP_MSG} "Extracting local cargo crates" 44 @${STEP_MSG} "Extracting local cargo crates"
45 ${RUN}${MKDIR} ${WRKSRC}/.cargo 45 ${RUN}${MKDIR} ${WRKSRC}/.cargo
46 ${RUN}${PRINTF} "[source.crates-io]\nreplace-with = \"vendored-sources\"\n[source.vendored-sources]\ndirectory = \"${CARGO_VENDOR_DIR}\"\n" > ${WRKSRC}/.cargo/config 46 ${RUN}${PRINTF} "[source.crates-io]\nreplace-with = \"vendored-sources\"\n[source.vendored-sources]\ndirectory = \"${CARGO_VENDOR_DIR}\"\n" > ${WRKSRC}/.cargo/config
47 ${RUN}${MKDIR} ${CARGO_VENDOR_DIR} 47 ${RUN}${MKDIR} ${CARGO_VENDOR_DIR}
48.for crate in ${CARGO_CRATE_DEPENDS} 48.for crate in ${CARGO_CRATE_DEPENDS}
49 ${RUN}${PRINTF} '{"package":"%s","files":{}}' \ 49 ${RUN}${PRINTF} '{"package":"%s","files":{}}' \
50 $$(${DIGEST} sha256 < ${_DISTDIR}/${crate}.crate) \ 50 $$(${DIGEST} sha256 < ${_DISTDIR}/${crate}.crate) \
51 > ${CARGO_VENDOR_DIR}/${crate}/.cargo-checksum.json 51 > ${CARGO_VENDOR_DIR}/${crate}/.cargo-checksum.json
52.endfor 52.endfor
53 53
 54# Legacy name
54.PHONY: show-cargo-depends 55.PHONY: show-cargo-depends
55show-cargo-depends: 56show-cargo-depends: print-cargo-depends
56 ${RUN}${AWK} '/^name = / { split($$3, a, "\""); name=a[2]; } \ 57
57 /^version = / { split($$3, a, "\""); vers=a[2]; } \ 58.PHONY: print-cargo-depends
58 /^source = / { \ 59print-cargo-depends:
59 print "CARGO_CRATE_DEPENDS+=\t" name "-" vers; \ 60 ${RUN}${AWK} 'BEGIN {print "# $$Net" "BSD$$"; print;} \
 61 /^name = / { split($$3, a, "\""); name=a[2]; } \
 62 /^version = / { split($$3, a, "\""); vers=a[2]; } \
 63 /^source = / { \
 64 print "CARGO_CRATE_DEPENDS+=\t" name "-" vers; \
60 }' ${WRKSRC}/Cargo.lock 65 }' ${WRKSRC}/Cargo.lock
61 66
62DEFAULT_CARGO_ARGS= build --offline --release -j${_MAKE_JOBS_N} 67DEFAULT_CARGO_ARGS= build --offline --release -j${_MAKE_JOBS_N}
63CARGO_ARGS?= ${DEFAULT_CARGO_ARGS} 68CARGO_ARGS?= ${DEFAULT_CARGO_ARGS}
64 69
65.if !target(do-build) 70.if !target(do-build)
66do-build: do-cargo-build 71do-build: do-cargo-build
67.endif 72.endif
68 73
69.PHONY: do-cargo-build 74.PHONY: do-cargo-build
70do-cargo-build: 75do-cargo-build:
71 ${RUN} cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${PREFIX}/bin/cargo ${CARGO_ARGS} 76 ${RUN} cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${PREFIX}/bin/cargo ${CARGO_ARGS}