Re: [gentoo-dev] [PATCH 4/7] cargo.eclass: set progress.when = "never" in config

2023-02-09 Thread Michał Górny
On Thu, 2023-02-09 at 12:48 -0800, Georgy Yakovlev wrote:
> to avoid possible log file pollution
> 
> Signed-off-by: Georgy Yakovlev 
> ---
>  eclass/cargo.eclass | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
> index 9c624d607cdd..0ab7ee0dc9b2 100644
> --- a/eclass/cargo.eclass
> +++ b/eclass/cargo.eclass
> @@ -273,6 +273,7 @@ cargo_gen_config() {
>   [term]
>   verbose = true
>   $([[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 
> 'never'")
> + progress.when = "never"
>   $(_cargo_gen_git_config)
>   _EOF_
>  

What's that and why don't we want it?  I thought we generally preferred
more verbosity.

-- 
Best regards,
Michał Górny




Re: [gentoo-dev] [PATCH 5/7] cargo.eclass: use custom profile for all builds

2023-02-09 Thread Ionen Wolkens
On Thu, Feb 09, 2023 at 12:48:45PM -0800, Georgy Yakovlev wrote:
> + strip = "none"

strip was stabilized in rust-1.59, this will likely fail without
USE=nightly on older rusts and other patch is only setting >=1.57

Haven't checked other options, I just happened to remember this one.
-- 
ionen


signature.asc
Description: PGP signature


[gentoo-dev] [PATCH 6/7] cargo.eclass: set codegen-units = 1

2023-02-09 Thread Georgy Yakovlev
This might increase build and lto times a bit,
but may result in faster and better optimized result.
It also honors resource limits properly.

Signed-off-by: Georgy Yakovlev 
---
 eclass/cargo.eclass | 5 +
 1 file changed, 5 insertions(+)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index a7c7bffd3c0c..00b8078f80ea 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -279,6 +279,11 @@ cargo_gen_config() {
$(usex debug 'opt-level = 0' '')
$(usex debug 'lto = false' '')
 
+   # 
https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units
+   # We use single codegen unit for most optimized code and to honor -j 
from MAKEOPTS.
+   # Users can override via e.g. CARGO_PROFILE_gentoo_CODEGEN_UNITS="16" 
in make.conf.
+   codegen-units = 1
+
[build]
jobs = $(makeopts_jobs)
incremental = false
-- 
2.39.1




[gentoo-dev] [PATCH 5/7] cargo.eclass: use custom profile for all builds

2023-02-09 Thread Georgy Yakovlev
also move install path to config file, so it can be
overriden via command line arg if required.

Signed-off-by: Georgy Yakovlev 
---
 eclass/cargo.eclass | 33 ++---
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 0ab7ee0dc9b2..a7c7bffd3c0c 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -266,10 +266,26 @@ cargo_gen_config() {
[net]
offline = true
 
+   [profile.gentoo]
+   # 
https://doc.rust-lang.org/cargo/reference/profiles.html#custom-profiles
+   inherits = "release"
+
+   # emulate dev profile with USE=debug
+   # https://doc.rust-lang.org/cargo/reference/profiles.html#dev
+   debug = $(usex debug true false)
+   debug-assertions = $(usex debug true false)
+   overflow-checks = $(usex debug true false)
+   strip = "none"
+   $(usex debug 'opt-level = 0' '')
+   $(usex debug 'lto = false' '')
+
[build]
jobs = $(makeopts_jobs)
incremental = false
 
+   [install]
+   root = "${ED}/usr"
+
[term]
verbose = true
$([[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 
'never'")
@@ -506,7 +522,7 @@ cargo_src_compile() {
 
tc-export AR CC CXX PKG_CONFIG
 
-   set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
+   set -- cargo build --profile gentoo ${ECARGO_ARGS[@]} "$@"
einfo "${@}"
"${@}" || die "cargo build failed"
 }
@@ -524,14 +540,17 @@ cargo_src_install() {
die "FATAL: please call cargo_gen_config before using 
${FUNCNAME}"
 
set -- cargo install $(has --path ${@} || echo --path ./) \
-   --no-track \
-   --root "${ED}/usr" \
-   ${GIT_CRATES[@]:+--frozen} \
-   $(usex debug --debug "") \
-   ${ECARGO_ARGS[@]} "$@"
+   --profile gentoo --no-track \
+${GIT_CRATES[@]:+--frozen} ${ECARGO_ARGS[@]} "$@"
einfo "${@}"
"${@}" || die "cargo install failed"
 
+   # HACK: compat symlinks until old ebuilds migrate.
+   # create target/{debug,release} symlinks that some ebuilds rely on.
+   # This only affects ebuilds that pick extra generated files from target 
directory, that's rare.
+   ln -s gentoo "${S}"/target/debug || :
+   ln -s gentoo "${S}"/target/release || :
+
# it turned out to be non-standard dir, so get rid of it future EAPI
# and only run for EAPI=7
# https://bugs.gentoo.org/715890
@@ -553,7 +572,7 @@ cargo_src_test() {
[[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \
die "FATAL: please call cargo_gen_config before using 
${FUNCNAME}"
 
-   set -- cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
+   set -- cargo test --profile gentoo ${ECARGO_ARGS[@]} "$@"
einfo "${@}"
"${@}" || die "cargo test failed"
 }
-- 
2.39.1




[gentoo-dev] [PATCH 4/7] cargo.eclass: set progress.when = "never" in config

2023-02-09 Thread Georgy Yakovlev
to avoid possible log file pollution

Signed-off-by: Georgy Yakovlev 
---
 eclass/cargo.eclass | 1 +
 1 file changed, 1 insertion(+)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 9c624d607cdd..0ab7ee0dc9b2 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -273,6 +273,7 @@ cargo_gen_config() {
[term]
verbose = true
$([[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 
'never'")
+   progress.when = "never"
$(_cargo_gen_git_config)
_EOF_
 
-- 
2.39.1




[gentoo-dev] [PATCH 7/7] cargo.eclass: filter out lto flags for C/CXX compilers

2023-02-09 Thread Georgy Yakovlev
we do it in src_compile to avoid excessive flag stripping in projects
using cargo.eclass just to fetch crates.

Closes: https://bugs.gentoo.org/893658
Signed-off-by: Georgy Yakovlev 
---
 eclass/cargo.eclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 00b8078f80ea..27ccee1295b3 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -49,7 +49,7 @@ case "${EAPI:-0}" in
;;
 esac
 
-inherit multiprocessing toolchain-funcs
+inherit flag-o-matic multiprocessing toolchain-funcs
 
 if [[ ! ${CARGO_OPTIONAL} ]]; then
BDEPEND="${RUST_DEPEND}"
@@ -525,6 +525,7 @@ cargo_src_compile() {
[[ ${_CARGO_GEN_CONFIG_HAS_RUN} ]] || \
die "FATAL: please call cargo_gen_config before using 
${FUNCNAME}"
 
+   filter-lto
tc-export AR CC CXX PKG_CONFIG
 
set -- cargo build --profile gentoo ${ECARGO_ARGS[@]} "$@"
-- 
2.39.1




[gentoo-dev] [PATCH 3/7] cargo.eclass: document undocumented variables, mark as readonly

2023-02-09 Thread Georgy Yakovlev
Signed-off-by: Georgy Yakovlev 
---
 eclass/cargo.eclass | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 1a8d665fdad2..9c624d607cdd 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -58,8 +58,15 @@ fi
 
 IUSE="${IUSE} debug"
 
-ECARGO_HOME="${WORKDIR}/cargo_home"
-ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
+# @ECLASS_VARIABLE: ECARGO_HOME
+# @DESCRIPTION:
+# Directory for CARGO_HOME used by build process.
+readonly ECARGO_HOME="${WORKDIR}/cargo_home"
+
+# @ECLASS_VARIABLE: ECARGO_VENDOR
+# @DESCRIPTION:
+# Directory for 'cargo vendor' subcommand output.
+readonly ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
 
 # @ECLASS_VARIABLE: CRATES
 # @DEFAULT_UNSET
-- 
2.39.1




[gentoo-dev] [PATCH 2/7] cargo.eclass: pass --no-track to cargo install

2023-02-09 Thread Georgy Yakovlev
and drop file removal hack.
with --no-track those files are never created.

Signed-off-by: Georgy Yakovlev 
---
 eclass/cargo.eclass | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index d37293ada136..1a8d665fdad2 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -516,6 +516,7 @@ cargo_src_install() {
die "FATAL: please call cargo_gen_config before using 
${FUNCNAME}"
 
set -- cargo install $(has --path ${@} || echo --path ./) \
+   --no-track \
--root "${ED}/usr" \
${GIT_CRATES[@]:+--frozen} \
$(usex debug --debug "") \
@@ -523,9 +524,6 @@ cargo_src_install() {
einfo "${@}"
"${@}" || die "cargo install failed"
 
-   rm -f "${ED}/usr/.crates.toml" || die
-   rm -f "${ED}/usr/.crates2.json" || die
-
# it turned out to be non-standard dir, so get rid of it future EAPI
# and only run for EAPI=7
# https://bugs.gentoo.org/715890
-- 
2.39.1




[gentoo-dev] [PATCH 1/7] cargo.eclass: bump minimum rust to 1.57.0

2023-02-09 Thread Georgy Yakovlev
and mark RUST_DEPEND as readonly

Signed-off-by: Georgy Yakovlev 
---
 eclass/cargo.eclass | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index a92fe97ec502..d37293ada136 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -13,28 +13,32 @@
 if [[ -z ${_CARGO_ECLASS} ]]; then
 _CARGO_ECLASS=1
 
-# check and document RUST_DEPEND and options we need below in case conditions.
+# @ECLASS_VARIABLE: RUST_DEPEND
+# @INTERNAL
+# @DESCRIPTION:
+# Minimum rust/cargo version that should be used with this eclass.
+# Versions below that may not provide functionality we rely on.
+# This variable should not be overriden by ebuilds, just manually
+# add more recent version if package requires it.
 # https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md
-RUST_DEPEND="virtual/rust"
+# 1.37 added 'cargo vendor' subcommand and net.offline config knob
+# 1.39 added --workspace
+# 1.46 added --target dir
+# 1.48 added term.progress config option
+# 1.51 added split-debuginfo profile option
+# 1.52 may need setting RUSTC_BOOTSTRAP envvar for some crates
+# 1.53 added cargo update --offline, can be used to update vulnerable crates 
from pre-fetched registry without editing toml
+# 1.57 added named profile support in stable
+readonly RUST_DEPEND=">=virtual/rust-1.57"
 
 case "${EAPI:-0}" in
0|1|2|3|4|5|6)
die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
;;
7)
-   # 1.37 added 'cargo vendor' subcommand and net.offline config 
knob
-   RUST_DEPEND=">=virtual/rust-1.37.0"
;;
 
8)
-   # 1.39 added --workspace
-   # 1.46 added --target dir
-   # 1.48 added term.progress config option
-   # 1.51 added split-debuginfo profile option
-   # 1.52 may need setting RUSTC_BOOTSTRAP envvar for some crates
-   # 1.53 added cargo update --offline, can be used to update 
vulnerable crates from pre-fetched registry without editing toml
-   RUST_DEPEND=">=virtual/rust-1.53"
-
if [[ -z ${CRATES} && "${PV}" != ** ]]; then
eerror "undefined CRATES variable in non-live EAPI=8 
ebuild"
die "CRATES variable not defined"
-- 
2.39.1




[gentoo-dev] cargo.eclass improvements

2023-02-09 Thread Georgy Yakovlev
Series of patches to cargo.eclass
most important chages are:
1. minimum rust/cargo version bump, which will propogate to all
consumers.
2. introduction of custom build profile (similar to what we do in Cmake)
 This will allow to consistently specify build options, yeat allows
 overrides from users or developers via envvars and/or args.

PR: https://github.com/gentoo/gentoo/pull/29510

PS: still WIP, but most changes are ready.
Another upcoming change is to allow running 'cargo update' to be able to
bump vulnerable/outdated pkgs listed in CRATES.




Re: [gentoo-dev] [PATCH] toolchain.eclass: Register the D tc_feature

2023-02-09 Thread Sam James


> On 9 Feb 2023, at 20:04, Arsen Arsenović  wrote:
> 
> This behavior is relied on elsewhere, for setting BDEPENDs correctly.
> 
> Signed-off-by: Arsen Arsenović 
> ---
> Hi there,
> 
> I was trying to merge GDC, and noticed that the non-selfhost BDEPEND is
> missing for GCC 13.  Specifically, the following block was never
> enterred:
> 
>  # TODO: Add a pkg_setup & pkg_pretend check for whether the active compiler
>  # supports D.
>  if tc_has_feature d && tc_version_is_at_least 12.0 ; then
>   # D in 12+ is self-hosting and needs D to bootstrap.
>   # TODO: package some binary we can use, like for Ada
>   # bug #840182
>   BDEPEND+=" d? ( || ( sys-devel/gcc[d(-)]   fi
> 
> This change enables the correct dependency to be emitted.
> 

Can you add a Fixes: for the original commit where I added the D hack?

> eclass/toolchain.eclass | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
> index 6d8901d21812..06c044fd1d38 100644
> --- a/eclass/toolchain.eclass
> +++ b/eclass/toolchain.eclass
> @@ -1,4 +1,4 @@
> -# Copyright 1999-2022 Gentoo Authors
> +# Copyright 1999-2023 Gentoo Authors
> # Distributed under the terms of the GNU General Public License v2
> 
> # @ECLASS: toolchain.eclass
> @@ -271,7 +271,7 @@ if [[ ${PN} != kgcc64 && ${PN} != gcc-* ]] ; then
> tc_version_is_at_least 8.0 &&
> IUSE+=" systemtap" TC_FEATURES+=( systemtap )
> 
> - tc_version_is_at_least 9.0 && IUSE+=" d"
> + tc_version_is_at_least 9.0 && IUSE+=" d" TC_FEATURES+=( d )

Thanks. I thought I'd checked for TC_FEATURES being populated.

Please push once added Fixes:, cheers!

Best,
sam



signature.asc
Description: Message signed with OpenPGP


[gentoo-dev] [PATCH] toolchain.eclass: Register the D tc_feature

2023-02-09 Thread Arsen Arsenović
This behavior is relied on elsewhere, for setting BDEPENDs correctly.

Signed-off-by: Arsen Arsenović 
---
Hi there,

I was trying to merge GDC, and noticed that the non-selfhost BDEPEND is
missing for GCC 13.  Specifically, the following block was never
enterred:

  # TODO: Add a pkg_setup & pkg_pretend check for whether the active compiler
  # supports D.
  if tc_has_feature d && tc_version_is_at_least 12.0 ; then
# D in 12+ is self-hosting and needs D to bootstrap.
# TODO: package some binary we can use, like for Ada
# bug #840182
BDEPEND+=" d? ( || ( sys-devel/gcc[d(-)] 

[gentoo-dev] Eclass for nodejs

2023-02-09 Thread Desarrollos WEB

Hi,

I am creating an eclass for nodejs using in my overlay for the ebuilds 
of zigbee2mqtt and pm2

I have started from several similar classes to make the eclass
I've set it up to use ebuilds with /packages like sys-apps/yarn and 
dev-lang/typescript and also with ebuilds that pre-download the Go-style 
node_modules directory (https://wiki.gentoo.org/wiki/Writing_go_Ebuilds) 
to facilitate the creation of such ebuilds


I wanted to comment with you if I'm on the right track, or if I should 
separate the eclass for package type ebuilds and another for node_modules


You can see the code at 
https://github.com/inode64/inode64-overlay/blob/main/eclass/nodejs.eclass


--
Best regards,
Fco. Javier Félix



Re: [gentoo-dev] Putting CC and CXX into make.conf

2023-02-09 Thread James Le Cuirot
On Thu, 2023-02-09 at 14:03 +0100, Michał Górny wrote:
> Hi,
> 
> I'd like to propose that we work towards having good defaults for CC
> and CXX variables in make.conf files.  Something like:
> 
>   CC=${CHOST}-gcc
>   CXX=${CHOST}-g++
> 
> or:
> 
>   CC=${CHOST}-cc
>   CXX=${CHOST}-c++
> 
> Why?
> 
> Right now we're pretty much relying on autoconf defaults: if CC/CXX is
> unset, autoconf looks for ${CHOST}-gcc and ${CHOST}-g++ appropriately. 
> However, autoconf is only one of the many build systems (and no longer
> very popular, I'd say) and whenever apps use another build system or
> override the default lookup in autoconf, we need to 'tc-export CC CXX'
> in order to ensure that the right name is picked.
> 
> Furthermore, some of us (myself included) actually set CC and CXX
> in their make.conf to a different value.  As a result, they are exported
> already on our systems and it's hard for us to notice that our ebuilds
> are missing the tc-export call.
> 
> I'm not aware of any downsides to having them set by default, except for
> the potentially problematic migration of existing systems.
> 
> What are your thoughts?

I've long been surprised that CC/CXX are not exported when the FLAGS are. We
already set these when cross-compiling or when using Clang, and that's been
fine, so I really don't see any issue.


signature.asc
Description: This is a digitally signed message part


[gentoo-dev] Putting CC and CXX into make.conf

2023-02-09 Thread Michał Górny
Hi,

I'd like to propose that we work towards having good defaults for CC
and CXX variables in make.conf files.  Something like:

  CC=${CHOST}-gcc
  CXX=${CHOST}-g++

or:

  CC=${CHOST}-cc
  CXX=${CHOST}-c++

Why?

Right now we're pretty much relying on autoconf defaults: if CC/CXX is
unset, autoconf looks for ${CHOST}-gcc and ${CHOST}-g++ appropriately. 
However, autoconf is only one of the many build systems (and no longer
very popular, I'd say) and whenever apps use another build system or
override the default lookup in autoconf, we need to 'tc-export CC CXX'
in order to ensure that the right name is picked.

Furthermore, some of us (myself included) actually set CC and CXX
in their make.conf to a different value.  As a result, they are exported
already on our systems and it's hard for us to notice that our ebuilds
are missing the tc-export call.

I'm not aware of any downsides to having them set by default, except for
the potentially problematic migration of existing systems.

What are your thoughts?

-- 
Best regards,
Michał Górny