1 |
simple src_configure implementation inspired by cmake.eclass |
2 |
|
3 |
Closes: https://bugs.gentoo.org/721936 |
4 |
|
5 |
Signed-off-by: Georgy Yakovlev <gyakovlev@g.o> |
6 |
--- |
7 |
eclass/cargo.eclass | 51 ++++++++++++++++++++++++++++++++++++++------- |
8 |
1 file changed, 44 insertions(+), 7 deletions(-) |
9 |
|
10 |
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass |
11 |
index ad90a0c7dd8..b084e082730 100644 |
12 |
--- a/eclass/cargo.eclass |
13 |
+++ b/eclass/cargo.eclass |
14 |
@@ -23,7 +23,7 @@ esac |
15 |
|
16 |
inherit multiprocessing toolchain-funcs |
17 |
|
18 |
-EXPORT_FUNCTIONS src_unpack src_compile src_install src_test |
19 |
+EXPORT_FUNCTIONS src_unpack src_configure src_compile src_install src_test |
20 |
|
21 |
IUSE="${IUSE} debug" |
22 |
|
23 |
@@ -35,6 +35,24 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" |
24 |
# Allows overriding the default cwd to run cargo install from |
25 |
: ${CARGO_INSTALL_PATH:=.} |
26 |
|
27 |
+# @VARIABLE: myfeatures |
28 |
+# @DEFAULT_UNSET |
29 |
+# @DESCRIPTION: |
30 |
+# Optional cargo features defined as bash array. Should be defined before calling |
31 |
+# src_configure. |
32 |
+# Example for package that has x11 and wayland as features. |
33 |
+# Also disables default features, as optional parameter is passed. |
34 |
+# @CODE |
35 |
+# src_configure() { |
36 |
+# local myfeatures=( |
37 |
+# $(usex X x11 '') |
38 |
+# $(usev wayland) |
39 |
+# ) |
40 |
+# |
41 |
+# cargo_src_configure --no-default-features |
42 |
+# } |
43 |
+# @CODE |
44 |
+ |
45 |
# @FUNCTION: cargo_crate_uris |
46 |
# @DESCRIPTION: |
47 |
# Generates the URIs to put in SRC_URI to help fetch dependencies. |
48 |
@@ -113,6 +131,7 @@ cargo_live_src_unpack() { |
49 |
mkdir -p "${S}" || die |
50 |
|
51 |
pushd "${S}" > /dev/null || die |
52 |
+ # need to specify CARGO_HOME before cargo_gen_config fired |
53 |
CARGO_HOME="${ECARGO_HOME}" cargo fetch || die |
54 |
CARGO_HOME="${ECARGO_HOME}" cargo vendor "${ECARGO_VENDOR}" || die |
55 |
popd > /dev/null || die |
56 |
@@ -152,6 +171,26 @@ cargo_gen_config() { |
57 |
EOF |
58 |
# honor NOCOLOR setting |
59 |
[[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'" >> "${ECARGO_HOME}/config" |
60 |
+ |
61 |
+ export CARGO_HOME="${ECARGO_HOME}" |
62 |
+} |
63 |
+ |
64 |
+# @FUNCTION: cargo_src_configure |
65 |
+# @DESCRIPTION: |
66 |
+# Configure cargo package features |
67 |
+cargo_src_configure() { |
68 |
+ debug-print-function ${FUNCNAME} "$@" |
69 |
+ |
70 |
+ [[ -z ${myfeatures} ]] && declare -a myfeatures=() |
71 |
+ local myfeaturestype=$(declare -p myfeatures 2>&-) |
72 |
+ if [[ "${myfeaturestype}" != "declare -a myfeatures="* ]]; then |
73 |
+ die "myfeatures must be declared as array" |
74 |
+ fi |
75 |
+ |
76 |
+ # transform array from simple feature list |
77 |
+ # to multiple cargo args: |
78 |
+ # --features feature1 --features feature2 ... |
79 |
+ readonly ECARGO_FEATURES=( ${myfeatures[@]/#/--features } ) |
80 |
} |
81 |
|
82 |
# @FUNCTION: cargo_src_compile |
83 |
@@ -160,11 +199,9 @@ cargo_gen_config() { |
84 |
cargo_src_compile() { |
85 |
debug-print-function ${FUNCNAME} "$@" |
86 |
|
87 |
- export CARGO_HOME="${ECARGO_HOME}" |
88 |
- |
89 |
tc-export AR CC |
90 |
|
91 |
- cargo build $(usex debug "" --release) "$@" \ |
92 |
+ cargo build $(usex debug "" --release) ${ECARGO_FEATURES[@]} "$@" \ |
93 |
|| die "cargo build failed" |
94 |
} |
95 |
|
96 |
@@ -174,8 +211,8 @@ cargo_src_compile() { |
97 |
cargo_src_install() { |
98 |
debug-print-function ${FUNCNAME} "$@" |
99 |
|
100 |
- cargo install --path ${CARGO_INSTALL_PATH} \ |
101 |
- --root="${ED}/usr" $(usex debug --debug "") "$@" \ |
102 |
+ cargo install --path ${CARGO_INSTALL_PATH} --root="${ED}/usr" \ |
103 |
+ $(usex debug --debug "") ${ECARGO_FEATURES[@]} "$@" \ |
104 |
|| die "cargo install failed" |
105 |
rm -f "${ED}/usr/.crates.toml" |
106 |
rm -f "${ED}/usr/.crates2.json" |
107 |
@@ -189,7 +226,7 @@ cargo_src_install() { |
108 |
cargo_src_test() { |
109 |
debug-print-function ${FUNCNAME} "$@" |
110 |
|
111 |
- cargo test $(usex debug "" --release) "$@" \ |
112 |
+ cargo test $(usex debug "" --release) ${ECARGO_FEATURES[@]} "$@" \ |
113 |
|| die "cargo test failed" |
114 |
} |
115 |
|
116 |
-- |
117 |
2.27.0 |