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 | 77 ++++++++++++++++++++++++++++++++++++++++----- |
8 |
1 file changed, 70 insertions(+), 7 deletions(-) |
9 |
|
10 |
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass |
11 |
index ccbf87aa9a6..77c8e90755b 100644 |
12 |
--- a/eclass/cargo.eclass |
13 |
+++ b/eclass/cargo.eclass |
14 |
@@ -22,7 +22,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 |
@@ -34,6 +34,29 @@ 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 |
+# If this array is not empty, --no-default-features is passed to cargo. |
33 |
+# To enable default crate features in that case you can add 'default' to the array. |
34 |
+# Extra positional arguments supplied to this function |
35 |
+# will be passed to cargo in all phases. |
36 |
+# Make sure all cargo subcommands support flags passed here. |
37 |
+# |
38 |
+# Example for package that has x11 and wayland as features, and enables default set. |
39 |
+# @CODE |
40 |
+# src_configure() { |
41 |
+# local myfeatures=( |
42 |
+# default |
43 |
+# $(usex X x11 '') |
44 |
+# $(usev wayland) |
45 |
+# ) |
46 |
+# cargo_src_configure |
47 |
+# } |
48 |
+# @CODE |
49 |
+ |
50 |
# @FUNCTION: cargo_crate_uris |
51 |
# @DESCRIPTION: |
52 |
# Generates the URIs to put in SRC_URI to help fetch dependencies. |
53 |
@@ -112,6 +135,7 @@ cargo_live_src_unpack() { |
54 |
mkdir -p "${S}" || die |
55 |
|
56 |
pushd "${S}" > /dev/null || die |
57 |
+ # need to specify CARGO_HOME before cargo_gen_config fired |
58 |
CARGO_HOME="${ECARGO_HOME}" cargo fetch || die |
59 |
CARGO_HOME="${ECARGO_HOME}" cargo vendor "${ECARGO_VENDOR}" || die |
60 |
popd > /dev/null || die |
61 |
@@ -151,6 +175,47 @@ cargo_gen_config() { |
62 |
EOF |
63 |
# honor NOCOLOR setting |
64 |
[[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'" >> "${ECARGO_HOME}/config" |
65 |
+ |
66 |
+ export CARGO_HOME="${ECARGO_HOME}" |
67 |
+} |
68 |
+ |
69 |
+# @FUNCTION: cargo_src_configure |
70 |
+# @DESCRIPTION: |
71 |
+# Configure cargo package features and arguments. |
72 |
+# Example for package that explicitly builds only 'foo' binary and |
73 |
+# enables single feature 'barfeature', disabling default feature set. |
74 |
+# will pass '--no-default-features --features barfeature --bin foo' |
75 |
+# in src_{compile,test,install} |
76 |
+# @CODE |
77 |
+# src_configure() { |
78 |
+# local myfeatures=( |
79 |
+# barfeature |
80 |
+# ) |
81 |
+# cargo_src_configure --bin foo |
82 |
+# } |
83 |
+# @CODE |
84 |
+ |
85 |
+cargo_src_configure() { |
86 |
+ debug-print-function ${FUNCNAME} "$@" |
87 |
+ |
88 |
+ [[ -z ${myfeatures} ]] && declare -a myfeatures=() |
89 |
+ local myfeaturestype=$(declare -p myfeatures 2>&-) |
90 |
+ if [[ "${myfeaturestype}" != "declare -a myfeatures="* ]]; then |
91 |
+ die "myfeatures must be declared as array" |
92 |
+ fi |
93 |
+ |
94 |
+ # transform array from simple feature list |
95 |
+ # to multiple cargo args: |
96 |
+ # --features feature1 --features feature2 ... |
97 |
+ # this format is chosen because 2 other methods of |
98 |
+ # listing features (space OR comma separated) require |
99 |
+ # more fiddling with strings we'd like to avoid here. |
100 |
+ myfeatures=( ${myfeatures[@]/#/--features } ) |
101 |
+ |
102 |
+ # prepend --no-default features if myfeatures array is not empty, append extra args |
103 |
+ readonly ECARGO_ARGS=( ${myfeatures:+--no-default-features ${myfeatures[@]}} ${@} ) |
104 |
+ |
105 |
+ [[ ${ECARGO_ARGS[@]} ]] && einfo "Configured with: ${ECARGO_ARGS[@]}" |
106 |
} |
107 |
|
108 |
# @FUNCTION: cargo_src_compile |
109 |
@@ -159,11 +224,9 @@ cargo_gen_config() { |
110 |
cargo_src_compile() { |
111 |
debug-print-function ${FUNCNAME} "$@" |
112 |
|
113 |
- export CARGO_HOME="${ECARGO_HOME}" |
114 |
- |
115 |
tc-export AR CC |
116 |
|
117 |
- cargo build $(usex debug "" --release) "$@" \ |
118 |
+ cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" \ |
119 |
|| die "cargo build failed" |
120 |
} |
121 |
|
122 |
@@ -173,8 +236,8 @@ cargo_src_compile() { |
123 |
cargo_src_install() { |
124 |
debug-print-function ${FUNCNAME} "$@" |
125 |
|
126 |
- cargo install --path ${CARGO_INSTALL_PATH} \ |
127 |
- --root="${ED}/usr" $(usex debug --debug "") "$@" \ |
128 |
+ cargo install --path ${CARGO_INSTALL_PATH} --root="${ED}/usr" \ |
129 |
+ $(usex debug --debug "") ${ECARGO_ARGS[@]} "$@" \ |
130 |
|| die "cargo install failed" |
131 |
rm -f "${ED}/usr/.crates.toml" |
132 |
rm -f "${ED}/usr/.crates2.json" |
133 |
@@ -188,7 +251,7 @@ cargo_src_install() { |
134 |
cargo_src_test() { |
135 |
debug-print-function ${FUNCNAME} "$@" |
136 |
|
137 |
- cargo test $(usex debug "" --release) "$@" \ |
138 |
+ cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@" \ |
139 |
|| die "cargo test failed" |
140 |
} |
141 |
|
142 |
-- |
143 |
2.27.0 |