Gentoo Archives: gentoo-dev

From: Georgy Yakovlev <gyakovlev@g.o>
To: gentoo-dev@l.g.o
Cc: Georgy Yakovlev <gyakovlev@g.o>
Subject: [gentoo-dev] [PATCH 5/7] cargo.eclass: use custom profile for all builds
Date: Thu, 09 Feb 2023 20:50:58
Message-Id: 20230209204847.3270114-6-gyakovlev@gentoo.org
In Reply to: [gentoo-dev] cargo.eclass improvements by Georgy Yakovlev
1 also move install path to config file, so it can be
2 overriden via command line arg if required.
3
4 Signed-off-by: Georgy Yakovlev <gyakovlev@g.o>
5 ---
6 eclass/cargo.eclass | 33 ++++++++++++++++++++++++++-------
7 1 file changed, 26 insertions(+), 7 deletions(-)
8
9 diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
10 index 0ab7ee0dc9b2..a7c7bffd3c0c 100644
11 --- a/eclass/cargo.eclass
12 +++ b/eclass/cargo.eclass
13 @@ -266,10 +266,26 @@ cargo_gen_config() {
14 [net]
15 offline = true
16
17 + [profile.gentoo]
18 + # https://doc.rust-lang.org/cargo/reference/profiles.html#custom-profiles
19 + inherits = "release"
20 +
21 + # emulate dev profile with USE=debug
22 + # https://doc.rust-lang.org/cargo/reference/profiles.html#dev
23 + debug = $(usex debug true false)
24 + debug-assertions = $(usex debug true false)
25 + overflow-checks = $(usex debug true false)
26 + strip = "none"
27 + $(usex debug 'opt-level = 0' '')
28 + $(usex debug 'lto = false' '')
29 +
30 [build]
31 jobs = $(makeopts_jobs)
32 incremental = false
33
34 + [install]
35 + root = "${ED}/usr"
36 +
37 [term]
38 verbose = true
39 $([[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'")
40 @@ -506,7 +522,7 @@ cargo_src_compile() {
41
42 tc-export AR CC CXX PKG_CONFIG
43
44 - set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
45 + set -- cargo build --profile gentoo ${ECARGO_ARGS[@]} "$@"
46 einfo "${@}"
47 "${@}" || die "cargo build failed"
48 }
49 @@ -524,14 +540,17 @@ cargo_src_install() {
50 die "FATAL: please call cargo_gen_config before using ${FUNCNAME}"
51
52 set -- cargo install $(has --path ${@} || echo --path ./) \
53 - --no-track \
54 - --root "${ED}/usr" \
55 - ${GIT_CRATES[@]:+--frozen} \
56 - $(usex debug --debug "") \
57 - ${ECARGO_ARGS[@]} "$@"
58 + --profile gentoo --no-track \
59 + ${GIT_CRATES[@]:+--frozen} ${ECARGO_ARGS[@]} "$@"
60 einfo "${@}"
61 "${@}" || die "cargo install failed"
62
63 + # HACK: compat symlinks until old ebuilds migrate.
64 + # create target/{debug,release} symlinks that some ebuilds rely on.
65 + # This only affects ebuilds that pick extra generated files from target directory, that's rare.
66 + ln -s gentoo "${S}"/target/debug || :
67 + ln -s gentoo "${S}"/target/release || :
68 +
69 # it turned out to be non-standard dir, so get rid of it future EAPI
70 # and only run for EAPI=7
71 # https://bugs.gentoo.org/715890
72 @@ -553,7 +572,7 @@ cargo_src_test() {
73 [[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \
74 die "FATAL: please call cargo_gen_config before using ${FUNCNAME}"
75
76 - set -- cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
77 + set -- cargo test --profile gentoo ${ECARGO_ARGS[@]} "$@"
78 einfo "${@}"
79 "${@}" || die "cargo test failed"
80 }
81 --
82 2.39.1

Replies