1 |
This adds 2 eclass variables |
2 |
|
3 |
ECARGO_BUILD_FLAGS |
4 |
ECARGO_INSTALL_FLAGS |
5 |
|
6 |
contents will be passed to "cargo build" and "cargo install" calls in |
7 |
cargo_src_compile() and cargo_src_install() respectively. |
8 |
|
9 |
Closes: https://github.com/gentoo/gentoo/pull/10725 |
10 |
Signed-off-by: Georgy Yakovlev <gyakovlev@g.o> |
11 |
--- |
12 |
eclass/cargo.eclass | 25 +++++++++++++++++++++++-- |
13 |
1 file changed, 23 insertions(+), 2 deletions(-) |
14 |
|
15 |
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass |
16 |
index 50f7830c51b..ea58c63b456 100644 |
17 |
--- a/eclass/cargo.eclass |
18 |
+++ b/eclass/cargo.eclass |
19 |
@@ -1,142 +1,163 @@ |
20 |
# Copyright 1999-2018 Gentoo Authors |
21 |
# Distributed under the terms of the GNU General Public License v2 |
22 |
|
23 |
# @ECLASS: cargo.eclass |
24 |
# @MAINTAINER: |
25 |
# rust@g.o |
26 |
# @AUTHOR: |
27 |
# Doug Goldstein <cardoe@g.o> |
28 |
# @SUPPORTED_EAPIS: 6 7 |
29 |
# @BLURB: common functions and variables for cargo builds |
30 |
|
31 |
if [[ -z ${_CARGO_ECLASS} ]]; then |
32 |
_CARGO_ECLASS=1 |
33 |
|
34 |
CARGO_DEPEND="" |
35 |
[[ ${CATEGORY}/${PN} != dev-util/cargo ]] && CARGO_DEPEND="virtual/cargo" |
36 |
|
37 |
case ${EAPI} in |
38 |
6) DEPEND="${CARGO_DEPEND}";; |
39 |
7) BDEPEND="${CARGO_DEPEND}";; |
40 |
*) die "EAPI=${EAPI:-0} is not supported" ;; |
41 |
esac |
42 |
|
43 |
inherit multiprocessing |
44 |
|
45 |
EXPORT_FUNCTIONS src_unpack src_compile src_install |
46 |
|
47 |
IUSE="${IUSE} debug" |
48 |
|
49 |
ECARGO_HOME="${WORKDIR}/cargo_home" |
50 |
ECARGO_VENDOR="${ECARGO_HOME}/gentoo" |
51 |
|
52 |
+# @ECLASS-VARIABLE: ECARGO_BUILD_FLAGS |
53 |
+# @DEFAULT_UNSET |
54 |
+# @DESCRIPTION: |
55 |
+# This allows to pass additional build flags to cargo in cargo_src_compile() |
56 |
+# |
57 |
+# Example: |
58 |
+# @CODE |
59 |
+# ECARGO_BUILD_FLAGS="$(usex pcre "--features pcre2" "")" |
60 |
+# @CODE |
61 |
+ |
62 |
+# @ECLASS-VARIABLE: ECARGO_INSTALL_FLAGS |
63 |
+# @DEFAULT_UNSET |
64 |
+# @DESCRIPTION: |
65 |
+# This allows to pass additional install flags to cargo in cargo_src_install() |
66 |
+# |
67 |
+# Example: |
68 |
+# @CODE |
69 |
+# ECARGO_INSTALL_FLAGS="--path=." |
70 |
+# @CODE |
71 |
+ |
72 |
+ |
73 |
# @FUNCTION: cargo_crate_uris |
74 |
# @DESCRIPTION: |
75 |
# Generates the URIs to put in SRC_URI to help fetch dependencies. |
76 |
cargo_crate_uris() { |
77 |
local crate |
78 |
for crate in "$@"; do |
79 |
local name version url pretag |
80 |
name="${crate%-*}" |
81 |
version="${crate##*-}" |
82 |
pretag="^[a-zA-Z]+" |
83 |
if [[ $version =~ $pretag ]]; then |
84 |
version="${name##*-}-${version}" |
85 |
name="${name%-*}" |
86 |
fi |
87 |
url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate" |
88 |
echo "${url}" |
89 |
done |
90 |
} |
91 |
|
92 |
# @FUNCTION: cargo_src_unpack |
93 |
# @DESCRIPTION: |
94 |
# Unpacks the package and the cargo registry |
95 |
cargo_src_unpack() { |
96 |
debug-print-function ${FUNCNAME} "$@" |
97 |
|
98 |
mkdir -p "${ECARGO_VENDOR}" || die |
99 |
mkdir -p "${S}" || die |
100 |
|
101 |
local archive shasum pkg |
102 |
for archive in ${A}; do |
103 |
case "${archive}" in |
104 |
*.crate) |
105 |
ebegin "Loading ${archive} into Cargo registry" |
106 |
tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_VENDOR}/" || die |
107 |
# generate sha256sum of the crate itself as cargo needs this |
108 |
shasum=$(sha256sum "${DISTDIR}"/${archive} | cut -d ' ' -f 1) |
109 |
pkg=$(basename ${archive} .crate) |
110 |
cat <<- EOF > ${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json |
111 |
{ |
112 |
"package": "${shasum}", |
113 |
"files": {} |
114 |
} |
115 |
EOF |
116 |
# if this is our target package we need it in ${WORKDIR} too |
117 |
# to make ${S} (and handle any revisions too) |
118 |
if [[ ${P} == ${pkg}* ]]; then |
119 |
tar -xf "${DISTDIR}"/${archive} -C "${WORKDIR}" || die |
120 |
fi |
121 |
eend $? |
122 |
;; |
123 |
cargo-snapshot*) |
124 |
ebegin "Unpacking ${archive}" |
125 |
mkdir -p "${S}"/target/snapshot |
126 |
tar -xzf "${DISTDIR}"/${archive} -C "${S}"/target/snapshot --strip-components 2 || die |
127 |
# cargo's makefile needs this otherwise it will try to |
128 |
# download it |
129 |
touch "${S}"/target/snapshot/bin/cargo || die |
130 |
eend $? |
131 |
;; |
132 |
*) |
133 |
unpack ${archive} |
134 |
;; |
135 |
esac |
136 |
done |
137 |
|
138 |
cargo_gen_config |
139 |
} |
140 |
|
141 |
# @FUNCTION: cargo_gen_config |
142 |
# @DESCRIPTION: |
143 |
# Generate the $CARGO_HOME/config necessary to use our local registry |
144 |
cargo_gen_config() { |
145 |
debug-print-function ${FUNCNAME} "$@" |
146 |
|
147 |
cat <<- EOF > "${ECARGO_HOME}/config" |
148 |
[source.gentoo] |
149 |
directory = "${ECARGO_VENDOR}" |
150 |
|
151 |
[source.crates-io] |
152 |
replace-with = "gentoo" |
153 |
local-registry = "/nonexistant" |
154 |
EOF |
155 |
} |
156 |
|
157 |
# @FUNCTION: cargo_src_compile |
158 |
# @DESCRIPTION: |
159 |
# Build the package using cargo build |
160 |
cargo_src_compile() { |
161 |
debug-print-function ${FUNCNAME} "$@" |
162 |
|
163 |
export CARGO_HOME="${ECARGO_HOME}" |
164 |
|
165 |
cargo build -j $(makeopts_jobs) $(usex debug "" --release) \ |
166 |
- || die "cargo build failed" |
167 |
+ ${ECARGO_BUILD_FLAGS} || die "cargo build failed" |
168 |
} |
169 |
|
170 |
# @FUNCTION: cargo_src_install |
171 |
# @DESCRIPTION: |
172 |
# Installs the binaries generated by cargo |
173 |
cargo_src_install() { |
174 |
debug-print-function ${FUNCNAME} "$@" |
175 |
|
176 |
cargo install -j $(makeopts_jobs) --root="${D}/usr" $(usex debug --debug "") \ |
177 |
- || die "cargo install failed" |
178 |
+ ${ECARGO_INSTALL_FLAGS} || die "cargo install failed" |
179 |
rm -f "${D}/usr/.crates.toml" |
180 |
|
181 |
[ -d "${S}/man" ] && doman "${S}/man" || return 0 |
182 |
} |
183 |
|
184 |
fi |
185 |
-- |
186 |
2.20.1 |