diff options
author | V3n3RiX <venerix@koprulu.sector> | 2025-03-04 01:46:23 +0000 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2025-03-04 01:46:23 +0000 |
commit | d13006cca857323814c09f5123b87c1a005bba74 (patch) | |
tree | ca4a24c0b40356fb7efce3e245882a9e87b5db3c /eclass | |
parent | eab7afdf0fe1454220af1a74c5556855a937a819 (diff) |
gentoo auto-resync : 04:03:2025 - 01:46:22next
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/Manifest.gz | bin | 40188 -> 40190 bytes | |||
-rwxr-xr-x | eclass/tests/zig-utils.sh | 8 | ||||
-rw-r--r-- | eclass/zig-utils.eclass | 61 | ||||
-rw-r--r-- | eclass/zig.eclass | 32 |
4 files changed, 83 insertions, 18 deletions
diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz Binary files differindex 3a4ab5394327..361e96ed8bcf 100644 --- a/eclass/Manifest.gz +++ b/eclass/Manifest.gz diff --git a/eclass/tests/zig-utils.sh b/eclass/tests/zig-utils.sh index 14af1d2105e3..3c98134b9006 100755 --- a/eclass/tests/zig-utils.sh +++ b/eclass/tests/zig-utils.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2024 Gentoo Authors +# Copyright 2024-2025 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 @@ -197,6 +197,8 @@ c_to_zig_map=( # https://bugs.gentoo.org/924920 ["-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"]=generic+v7a+vfp3d16-soft_float + + ["-march=armv7-a -march=unset"]="generic-soft_float" ) test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}" tend ${?} @@ -210,6 +212,10 @@ c_to_zig_map=( ["-march=armv8.3-a"]="generic+v8_3a" ["-mcpu=cortex-a78 -march=armv8.3-a"]="cortex_a78+v8_3a" + + ["-march=native"]="native" + ["-march=native -mtune=native"]="generic" + ["-mcpu=cortex-a78 -march=native"]="cortex_a78" ) test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}" tend ${?} diff --git a/eclass/zig-utils.eclass b/eclass/zig-utils.eclass index 5502d997935e..e9d91b8f5f52 100644 --- a/eclass/zig-utils.eclass +++ b/eclass/zig-utils.eclass @@ -202,6 +202,35 @@ fi # 0.13.0 # @CODE +# @FUNCTION: _get-c-option +# @INTERNAL +# @USAGE: <option-name> +# @DESCRIPTION: +# Gets value of some compiler option from CFLAGS, starting from the end. +# Must be a full name, without "-" and "=..." part. +# +# Example: +# @CODE +# CFLAGS="-march=i686 -march=i586" +# _get-c-option march # returns i586 +# @CODE +_get-c-option() { + if [[ ${#} -ne 1 ]]; then + die "${FUNCNAME[0]}: expected 1 argument, got ${#}" + fi + + local prefix="-${1}=" + local c_flags=( ${CFLAGS} ) + for (( i=${#c_flags[@]} - 1; i >= 0; i -= 1 )); do + local c_flag="${c_flags[i]}" + if [[ "${c_flag}" == ${prefix}* ]]; then + echo "${c_flag#${prefix}}" + return + fi + done + echo "" +} + # @FUNCTION: zig-utils_c_env_to_zig_target # @USAGE: <C-style target tuple> <CFLAGS> # @DESCRIPTION: @@ -224,8 +253,8 @@ zig-utils_c_env_to_zig_target() { local c_arch="${c_tuple%%-*}" local c_abi="${c_tuple##*-}" - local c_flags="${2}" - local c_flags_march="$(CFLAGS="${c_flags}" get-flag march)" + local -x CFLAGS="${2}" + local c_flags_march="$(_get-c-option march)" local arch os abi @@ -279,11 +308,12 @@ zig-utils_c_env_to_zig_cpu() { local c_tuple="${1}" local c_arch="${c_tuple%%-*}" - local c_flags="${2}" - local c_flags_mabi="$(CFLAGS="${c_flags}" get-flag mabi)" - local c_flags_march="$(CFLAGS="${c_flags}" get-flag march)" - local c_flags_mcpu="$(CFLAGS="${c_flags}" get-flag mcpu)" - local c_flags_mfpu="$(CFLAGS="${c_flags}" get-flag mfpu)" + local -x CFLAGS="${2}" + local c_flags_mabi="$(_get-c-option mabi)" + local c_flags_march="$(_get-c-option march)" + local c_flags_mcpu="$(_get-c-option mcpu)" + local c_flags_mfpu="$(_get-c-option mfpu)" + local c_flags_mtune="$(_get-c-option mtune)" local base_cpu features="" @@ -303,13 +333,28 @@ zig-utils_c_env_to_zig_cpu() { esac case "${c_flags_march}" in - "") ;; + "" | unset) ;; armv*) local c_arm_family="${c_flags_march##arm}" c_arm_family="${c_arm_family//./_}" c_arm_family="${c_arm_family//-/}" features+="+${c_arm_family}" ;; + native) + # GCC docs: This option has no effect if + # the compiler is unable to recognize the + # architecture of the host system. + # + # When -march=native is given and no other + # -mcpu or -mtune is given then ... -march=native + # is treated as -mcpu=native. + if [[ -z "${c_flags_mcpu}${c_flags_mtune}" ]]; then + base_cpu=native + else + : # Zig can not detect CPU features (architecture + # in our case) separately from model, so we ignore it. + fi + ;; *) features+="+${c_flags_march}";; esac diff --git a/eclass/zig.eclass b/eclass/zig.eclass index 2a0178e66d71..0de7ee9eb47a 100644 --- a/eclass/zig.eclass +++ b/eclass/zig.eclass @@ -1,4 +1,4 @@ -# Copyright 2024 Gentoo Authors +# Copyright 2024-2025 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: zig.eclass @@ -152,6 +152,7 @@ _zig_set_zbs_uris() { _zig_set_zbs_uris # @ECLASS_VARIABLE: my_zbs_args +# @DEFAULT_UNSET # @DESCRIPTION: # Bash array with ebuild-specified arguments to pass to the # "zig build" after "src_configure". @@ -159,6 +160,8 @@ _zig_set_zbs_uris # need to override default optimize mode of this eclass (ReleaseSafe) # with your default, please use "--release=small" etc. syntax so that # user can still override it in ZBS_ARGS_EXTRA. +# Note: `--prefix` and other relative arguments will +# process here as relative to BUILD_DIR. # # Example: # @CODE @@ -170,7 +173,6 @@ _zig_set_zbs_uris # zig_src_configure # } # @CODE -: "${my_zbs_args:=}" # @ECLASS_VARIABLE: ZBS_ARGS_EXTRA # @USER_VARIABLE @@ -203,7 +205,6 @@ _zig_set_zbs_uris : "${ZBS_VERBOSE:=ON}" # @ECLASS_VARIABLE: BUILD_DIR -# @DEFAULT_UNSET # @DESCRIPTION: # Directory where all "ezig build" calls will be proceeded. # Defaults to "${WORKDIR}/${P}-build" if not set. @@ -293,14 +294,18 @@ zig_init_base_args() { -Dcpu="${ZIG_CPU}" --release=safe + # We want absolute path here so that it would appear correctly + # when embedded to binaries with build.zig, but without DESTDIR + # it would try to escape sandbox and install directly to root. + # + # Therefore, we set DESTDIR each time to be: + # 1) BUILD_DIR in phases before `src_install`, + # 2) D during `src_install`. + --prefix "${EPREFIX}/usr/" --prefix-exe-dir bin/ --prefix-lib-dir "$(get_libdir)/" --prefix-include-dir include/ - # Should be relative path to make other calls easier, - # so remove leading slash here. - --prefix "${EPREFIX:+${EPREFIX#/}/}usr/" - --libc "${T}/zig_libc.txt" ) if [[ "${ZBS_VERBOSE}" != OFF ]]; then @@ -487,12 +492,17 @@ zig_src_configure() { # @DESCRIPTION: # Calls "ezig build" with previously set ZBS_ARGS. # Args passed to this function will be passed after ZBS_ARGS. +# They can be used to call custom steps or override some +# options temporarily like `--prefix`. +# Note that `--prefix` and other relative arguments will +# process here as relative to BUILD_DIR. zig_src_compile() { pushd "${BUILD_DIR}" > /dev/null || die local args=( "${ZBS_ARGS[@]}" "${@}" ) einfo "ZBS: compiling with: ${args[@]}" - nonfatal ezig build "${args[@]}" || die "ZBS: compilation failed" + DESTDIR="${BUILD_DIR}" nonfatal ezig build "${args[@]}" || + die "ZBS: compilation failed" popd > /dev/null || die } @@ -505,6 +515,8 @@ zig_src_compile() { # Args passed to this function will be passed after ZBS_ARGS. # Note: currently step detection might give false positives in # very rare cases, it will be improved in the future. +# Note that `--prefix` and other relative arguments will +# process here as relative to BUILD_DIR. zig_src_test() { pushd "${BUILD_DIR}" > /dev/null || die @@ -526,7 +538,7 @@ zig_src_test() { nonfatal ezig build --list-steps "${args[@]}" ); then einfo "ZBS: testing with: ${args[@]}" - nonfatal ezig build test "${args[@]}" || + DESTDIR="${BUILD_DIR}" nonfatal ezig build test "${args[@]}" || die "ZBS: tests failed" else einfo "Test step not found, skipping." @@ -541,6 +553,8 @@ zig_src_test() { # Calls "ezig build" with DESTDIR and previously set ZBS_ARGS. # Args passed to this function will be passed after ZBS_ARGS. # Also installs documentation via "einstalldocs". +# Note that `--prefix` and other relative arguments will +# process here as relative to D. zig_src_install() { pushd "${BUILD_DIR}" > /dev/null || die local args=( "${ZBS_ARGS[@]}" "${@}" ) |