Sun May 6 01:59:36 2018 UTC ()
Add a show-cargo-depends target, sparing the effort of listing cargo
dependencies manually.

Document a bit and give some helpful tips.


(maya)
diff -r1.1 -r1.2 pkgsrc/lang/rust/cargo.mk

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

--- pkgsrc/lang/rust/cargo.mk 2017/11/08 13:40:10 1.1
+++ pkgsrc/lang/rust/cargo.mk 2018/05/06 01:59:36 1.2
@@ -1,38 +1,48 @@ @@ -1,38 +1,48 @@
1# $NetBSD: cargo.mk,v 1.1 2017/11/08 13:40:10 tnn Exp $ 1# $NetBSD: cargo.mk,v 1.2 2018/05/06 01:59:36 maya 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# do-build: 12# do-build:
13# cargo build --locked --frozen 13# cargo build --locked --frozen
14# 14#
 15#
 16# If modifying the list of dependencies, re-run the build once without
 17# --locked --frozen to generate a new valid Cargo.lock.
 18#
 19# a list of CARGO_CRATE_DEPENDS can be generated via "make show-cargo-depends".
 20#
15# See also www/geckodriver for a full example. 21# See also www/geckodriver for a full example.
16 22
17USE_TOOLS+= bsdtar digest 23USE_TOOLS+= bsdtar digest
18CARGO_VENDOR_DIR= ${WRKDIR}/vendor 24CARGO_VENDOR_DIR= ${WRKDIR}/vendor
19 25
20DISTFILES?= ${DEFAULT_DISTFILES} 26DISTFILES?= ${DEFAULT_DISTFILES}
21.for _crate in ${CARGO_CRATE_DEPENDS} 27.for _crate in ${CARGO_CRATE_DEPENDS}
22DISTFILES+= ${_crate}.crate 28DISTFILES+= ${_crate}.crate
23SITES.${_crate}.crate+= -${MASTER_SITE_CRATESIO}${_crate:C/-[0-9.]+$//}/${_crate:C/^.*-([0-9.]+)$/\1/}/download 29SITES.${_crate}.crate+= -${MASTER_SITE_CRATESIO}${_crate:C/-[0-9.]+$//}/${_crate:C/^.*-([0-9.]+)$/\1/}/download
24.endfor 30.endfor
25 31
26post-extract: cargo-vendor-crates 32post-extract: cargo-vendor-crates
27.PHONY: cargo-vendor-crates 33.PHONY: cargo-vendor-crates
28cargo-vendor-crates: 34cargo-vendor-crates:
29 @${STEP_MSG} "Extracting local cargo crates" 35 @${STEP_MSG} "Extracting local cargo crates"
30 ${RUN}${MKDIR} ${WRKSRC}/.cargo 36 ${RUN}${MKDIR} ${WRKSRC}/.cargo
31 ${RUN}${PRINTF} "[source.crates-io]\nreplace-with = \"vendored-sources\"\n[source.vendored-sources]\ndirectory = \"${CARGO_VENDOR_DIR}\"\n" >> ${WRKSRC}/.cargo/config 37 ${RUN}${PRINTF} "[source.crates-io]\nreplace-with = \"vendored-sources\"\n[source.vendored-sources]\ndirectory = \"${CARGO_VENDOR_DIR}\"\n" >> ${WRKSRC}/.cargo/config
32 ${RUN}${MKDIR} ${CARGO_VENDOR_DIR} 38 ${RUN}${MKDIR} ${CARGO_VENDOR_DIR}
33.for _crate in ${CARGO_CRATE_DEPENDS} 39.for _crate in ${CARGO_CRATE_DEPENDS}
34 ${RUN}${TOOLS_PATH.bsdtar} -C ${CARGO_VENDOR_DIR} -xzf ${WRKDIR}/${_crate}.crate 40 ${RUN}${TOOLS_PATH.bsdtar} -C ${CARGO_VENDOR_DIR} -xzf ${WRKDIR}/${_crate}.crate
35 ${RUN}${PRINTF} '{"package":"%s","files":{}}' \ 41 ${RUN}${PRINTF} '{"package":"%s","files":{}}' \
36 $$(${DIGEST} sha256 < ${WRKDIR}/${_crate}.crate) \ 42 $$(${DIGEST} sha256 < ${WRKDIR}/${_crate}.crate) \
37 > ${CARGO_VENDOR_DIR}/${_crate}/.cargo-checksum.json 43 > ${CARGO_VENDOR_DIR}/${_crate}/.cargo-checksum.json
38.endfor 44.endfor
 45
 46.PHONY: show-cargo-depends
 47show-cargo-depends:
 48 ${RUN}${AWK} '/^\"checksum/ { print "CARGO_CRATE_DEPENDS+=\t" $$2 "-" $$3""; next } ' ${WRKSRC}/Cargo.lock