Annotation of pkgsrc/lang/rust/cargo.mk, Revision 1.7
1.7 ! fox 1: # $NetBSD: cargo.mk,v 1.6 2018/11/27 15:45:23 adam Exp $
1.1 tnn 2: #
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
5: # cargo crates instead of using the rust package manager in the build phase.
6: # Inspired by cargo.mk from FreeBSD ports.
7: #
8: # Usage example:
9: #
10: # CARGO_CRATE_DEPENDS+= sha1-0.20
11: # .include "../../lang/rust/cargo.mk"
12: # do-build:
13: # cargo build --locked --frozen
14: #
1.2 maya 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: #
1.1 tnn 21: # See also www/geckodriver for a full example.
22:
1.3 minskim 23: BUILD_DEPENDS+= rust-[0-9]*:../../lang/rust
24:
1.1 tnn 25: USE_TOOLS+= bsdtar digest
26: CARGO_VENDOR_DIR= ${WRKDIR}/vendor
27:
28: DISTFILES?= ${DEFAULT_DISTFILES}
29: .for _crate in ${CARGO_CRATE_DEPENDS}
30: DISTFILES+= ${_crate}.crate
1.7 ! fox 31: SITES.${_crate}.crate+= -${MASTER_SITE_CRATESIO}${_crate:C/-[0-9]+\.[0-9.]+.*$//}/${_crate:C/^.*-([0-9]+\.[0-9.]+.*)$/\1/}/download
1.4 minskim 32: EXTRACT_DIR.${_crate}.crate?= ${CARGO_VENDOR_DIR}
1.1 tnn 33: .endfor
34:
35: post-extract: cargo-vendor-crates
36: .PHONY: cargo-vendor-crates
37: cargo-vendor-crates:
38: @${STEP_MSG} "Extracting local cargo crates"
39: ${RUN}${MKDIR} ${WRKSRC}/.cargo
1.5 maya 40: ${RUN}${PRINTF} "[source.crates-io]\nreplace-with = \"vendored-sources\"\n[source.vendored-sources]\ndirectory = \"${CARGO_VENDOR_DIR}\"\n" > ${WRKSRC}/.cargo/config
1.1 tnn 41: ${RUN}${MKDIR} ${CARGO_VENDOR_DIR}
42: .for _crate in ${CARGO_CRATE_DEPENDS}
43: ${RUN}${PRINTF} '{"package":"%s","files":{}}' \
1.4 minskim 44: $$(${DIGEST} sha256 < ${_DISTDIR}/${_crate}.crate) \
1.1 tnn 45: > ${CARGO_VENDOR_DIR}/${_crate}/.cargo-checksum.json
46: .endfor
1.2 maya 47:
48: .PHONY: show-cargo-depends
49: show-cargo-depends:
50: ${RUN}${AWK} '/^\"checksum/ { print "CARGO_CRATE_DEPENDS+=\t" $$2 "-" $$3""; next } ' ${WRKSRC}/Cargo.lock
CVSweb <webmaster@jp.NetBSD.org>