Fri Aug 14 20:44:16 2020 UTC ()
rust/cargo.mk: add a default do-build target to reduce copypasta


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

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

--- pkgsrc/lang/rust/cargo.mk 2020/08/14 11:05:00 1.19
+++ pkgsrc/lang/rust/cargo.mk 2020/08/14 20:44:16 1.20
@@ -1,30 +1,27 @@ @@ -1,30 +1,27 @@
1# $NetBSD: cargo.mk,v 1.19 2020/08/14 11:05:00 tnn Exp $ 1# $NetBSD: cargo.mk,v 1.20 2020/08/14 20:44:16 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# do-build: 
13# cargo build --offline 
14# 
15# 12#
16# 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
17# --offline to generate a new valid Cargo.lock. 14# --offline in CARGO_ARGS to generate a new valid Cargo.lock.
18# 15#
19# a list of CARGO_CRATE_DEPENDS can be generated via "make show-cargo-depends". 16# a list of CARGO_CRATE_DEPENDS can be generated via "make show-cargo-depends".
20# 17#
21# See also www/geckodriver for a full example. 18# See also www/geckodriver for a full example.
22 19
23MASTER_SITES?= -${MASTER_SITE_CRATESIO}${PKGBASE}/${PKGVERSION_NOREV}/download 20MASTER_SITES?= -${MASTER_SITE_CRATESIO}${PKGBASE}/${PKGVERSION_NOREV}/download
24 21
25.include "../../lang/rust/rust.mk" 22.include "../../lang/rust/rust.mk"
26 23
27USE_TOOLS+= bsdtar digest 24USE_TOOLS+= bsdtar digest
28CARGO_VENDOR_DIR= ${WRKDIR}/vendor 25CARGO_VENDOR_DIR= ${WRKDIR}/vendor
29 26
30DISTFILES?= ${DEFAULT_DISTFILES} 27DISTFILES?= ${DEFAULT_DISTFILES}
@@ -51,13 +48,24 @@ cargo-vendor-crates: @@ -51,13 +48,24 @@ cargo-vendor-crates:
51.for crate in ${CARGO_CRATE_DEPENDS} 48.for crate in ${CARGO_CRATE_DEPENDS}
52 ${RUN}${PRINTF} '{"package":"%s","files":{}}' \ 49 ${RUN}${PRINTF} '{"package":"%s","files":{}}' \
53 $$(${DIGEST} sha256 < ${_DISTDIR}/${crate}.crate) \ 50 $$(${DIGEST} sha256 < ${_DISTDIR}/${crate}.crate) \
54 > ${CARGO_VENDOR_DIR}/${crate}/.cargo-checksum.json 51 > ${CARGO_VENDOR_DIR}/${crate}/.cargo-checksum.json
55.endfor 52.endfor
56 53
57.PHONY: show-cargo-depends 54.PHONY: show-cargo-depends
58show-cargo-depends: 55show-cargo-depends:
59 ${RUN}${AWK} '/^name = / { split($$3, a, "\""); name=a[2]; } \ 56 ${RUN}${AWK} '/^name = / { split($$3, a, "\""); name=a[2]; } \
60 /^version = / { split($$3, a, "\""); vers=a[2]; } \ 57 /^version = / { split($$3, a, "\""); vers=a[2]; } \
61 /^source = / { \ 58 /^source = / { \
62 print "CARGO_CRATE_DEPENDS+=\t" name "-" vers; \ 59 print "CARGO_CRATE_DEPENDS+=\t" name "-" vers; \
63 }' ${WRKSRC}/Cargo.lock 60 }' ${WRKSRC}/Cargo.lock
 61
 62DEFAULT_CARGO_ARGS= build --offline --release -j${_MAKE_JOBS_N}
 63CARGO_ARGS?= ${DEFAULT_CARGO_ARGS}
 64
 65.if !target(do-build)
 66do-build: do-cargo-build
 67.endif
 68
 69.PHONY: do-cargo-build
 70do-cargo-build:
 71 ${RUN} cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${PREFIX}/bin/cargo ${CARGO_ARGS}