blob: 1a39211edacba634f721c9c6fd9dba060498cf33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# $NetBSD: cargo.mk,v 1.25 2021/05/31 10:17:53 he Exp $
#
# Common logic that can be used by packages that depend on cargo crates
# from crates.io. This lets existing pkgsrc infrastructure fetch and verify
# cargo crates instead of using the rust package manager in the build phase.
# Inspired by cargo.mk from FreeBSD ports.
#
# Usage example:
#
# CARGO_CRATE_DEPENDS+= sha1-0.20
# .include "../../lang/rust/cargo.mk"
#
# If modifying the list of dependencies, re-run the build once without
# --offline in CARGO_ARGS to generate a new valid Cargo.lock.
# e.g: make CARGO_ARGS="build --release" build
#
# a list of CARGO_CRATE_DEPENDS can be generated via
# make print-cargo-depends > cargo-depends.mk
#
# See also www/geckodriver for a full example.
MASTER_SITES?= -${MASTER_SITE_CRATESIO}${PKGBASE}/${PKGVERSION_NOREV}/download
CHECK_SSP_SUPPORTED= no
.include "../../lang/rust/rust.mk"
USE_TOOLS+= bsdtar digest
CARGO_VENDOR_DIR= ${WRKDIR}/vendor
DISTFILES?= ${DEFAULT_DISTFILES}
.for crate in ${CARGO_CRATE_DEPENDS}
DISTFILES+= ${crate}.crate
SITES.${crate}.crate+= -${MASTER_SITE_CRATESIO}${crate:C/-[0-9]+\.[0-9.]+.*$//}/${crate:C/^.*-([0-9]+\.[0-9.]+.*)$/\1/}/download
EXTRACT_DIR.${crate}.crate?= ${CARGO_VENDOR_DIR}
.endfor
.include "../../mk/bsd.prefs.mk"
# Triggers NetBSD ld.so bug (PR toolchain/54192)
# See Makefile for further information.
.if ${MACHINE_PLATFORM:MNetBSD-[1-9].*} && !${MACHINE_PLATFORM:MNetBSD-9.99.*}
MAKE_JOBS_SAFE= no
.endif
post-extract: cargo-vendor-crates
.PHONY: cargo-vendor-crates
cargo-vendor-crates:
@${STEP_MSG} "Extracting local cargo crates"
${RUN}${MKDIR} ${WRKSRC}/.cargo
${RUN}${PRINTF} "[source.crates-io]\nreplace-with = \"vendored-sources\"\n[source.vendored-sources]\ndirectory = \"${CARGO_VENDOR_DIR}\"\n" > ${WRKSRC}/.cargo/config
${RUN}${MKDIR} ${CARGO_VENDOR_DIR}
.for crate in ${CARGO_CRATE_DEPENDS}
${RUN}${PRINTF} '{"package":"%s","files":{}}' \
`$(${DIGEST} sha256 < ${_DISTDIR}/${crate}.crate` \
> ${CARGO_VENDOR_DIR}/${crate}/.cargo-checksum.json
.endfor
# Legacy name
.PHONY: show-cargo-depends
show-cargo-depends: print-cargo-depends
.PHONY: print-cargo-depends
print-cargo-depends:
${RUN}${AWK} 'BEGIN {print "# $$Net" "BSD$$"; print;} \
/^name = / { split($$3, a, "\""); name=a[2]; } \
/^version = / { split($$3, a, "\""); vers=a[2]; } \
/^source = / { \
print "CARGO_CRATE_DEPENDS+=\t" name "-" vers; \
}' ${WRKSRC}/Cargo.lock
DEFAULT_CARGO_ARGS= build --offline --release -j${_MAKE_JOBS_N} \
${CARGO_NO_DEFAULT_FEATURES:M[yY][eE][sS]:C/[yY][eE][sS]/--no-default-features/} \
${CARGO_FEATURES:C/.*/--features/W} \
${CARGO_FEATURES:S/ /,/Wg}
CARGO_ARGS?= ${DEFAULT_CARGO_ARGS}
.if !target(do-build)
do-build: do-cargo-build
.endif
.PHONY: do-cargo-build
do-cargo-build:
${RUN} cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${PREFIX}/bin/cargo ${CARGO_ARGS}
|