Gentoo Archives: gentoo-dev

From: Mike Gilbert <floppym@g.o>
To: gentoo-dev@l.g.o
Cc: Mike Gilbert <floppym@g.o>
Subject: [gentoo-dev] [PATCH] meson.eclass: implement support for native machine files
Date: Sat, 25 Apr 2020 19:01:12
Message-Id: 20200425190102.43445-1-floppym@gentoo.org
1 Using a native file avoids putting meson into cross-compiler mode for
2 multilib builds.
3
4 Reference: https://mesonbuild.com/Machine-files.html
5 Reference: https://mesonbuild.com/Native-environments.html
6
7 Bug: https://bugs.gentoo.org/719382
8 Signed-off-by: Mike Gilbert <floppym@g.o>
9 ---
10 eclass/meson.eclass | 107 +++++++++++++++++++++++++++++++++++---------
11 1 file changed, 87 insertions(+), 20 deletions(-)
12
13 diff --git a/eclass/meson.eclass b/eclass/meson.eclass
14 index 423a497e840c..7b1a6a9735bd 100644
15 --- a/eclass/meson.eclass
16 +++ b/eclass/meson.eclass
17 @@ -125,17 +125,17 @@ _meson_env_array() {
18 python -c "${__MESON_ARRAY_PARSER}" "$@"
19 }
20
21 -# @FUNCTION: _meson_create_cross_file
22 +# @FUNCTION: _meson_get_machine_info
23 +# @USAGE: <tuple>
24 +# @RETURN: system/cpu_family/cpu variables
25 # @INTERNAL
26 # @DESCRIPTION:
27 -# Creates a cross file. meson uses this to define settings for
28 -# cross-compilers. This function is called from meson_src_configure.
29 -_meson_create_cross_file() {
30 - # Reference: http://mesonbuild.com/Cross-compilation.html
31 +# Translate toolchain tuple into machine values for meson.
32 +_meson_get_machine_info() {
33 + local tuple=$1
34
35 # system roughly corresponds to uname -s (lowercase)
36 - local system=unknown
37 - case ${CHOST} in
38 + case ${tuple} in
39 *-aix*) system=aix ;;
40 *-cygwin*) system=cygwin ;;
41 *-darwin*) system=darwin ;;
42 @@ -145,19 +145,29 @@ _meson_create_cross_file() {
43 *-solaris*) system=sunos ;;
44 esac
45
46 - local cpu_family=$(tc-arch)
47 + cpu_family=$(tc-arch "${tuple}")
48 case ${cpu_family} in
49 amd64) cpu_family=x86_64 ;;
50 arm64) cpu_family=aarch64 ;;
51 esac
52
53 # This may require adjustment based on CFLAGS
54 - local cpu=${CHOST%%-*}
55 + cpu=${tuple%%-*}
56 +}
57 +
58 +# @FUNCTION: _meson_create_cross_file
59 +# @RETURN: path to cross file
60 +# @INTERNAL
61 +# @DESCRIPTION:
62 +# Creates a cross file. meson uses this to define settings for
63 +# cross-compilers. This function is called from meson_src_configure.
64 +_meson_create_cross_file() {
65 + local system cpu_family cpu
66 + _meson_get_machine_info "${CHOST}"
67
68 - local needs_exe_wrapper=false
69 - tc-is-cross-compiler && needs_exe_wrapper=true
70 + local fn=${T}/meson.${CHOST}.ini
71
72 - cat > "${T}/meson.${CHOST}.${ABI}" <<-EOF
73 + cat > "${fn}" <<-EOF
74 [binaries]
75 ar = $(_meson_env_array "$(tc-getAR)")
76 c = $(_meson_env_array "$(tc-getCC)")
77 @@ -181,16 +191,67 @@ _meson_create_cross_file() {
78 objc_link_args = $(_meson_env_array "${OBJCFLAGS} ${LDFLAGS}")
79 objcpp_args = $(_meson_env_array "${OBJCXXFLAGS} ${CPPFLAGS}")
80 objcpp_link_args = $(_meson_env_array "${OBJCXXFLAGS} ${LDFLAGS}")
81 - needs_exe_wrapper = ${needs_exe_wrapper}
82 + needs_exe_wrapper = true
83 sys_root = '${SYSROOT}'
84 - pkg_config_libdir = '${PKG_CONFIG_LIBDIR-${EPREFIX}/usr/$(get_libdir)/pkgconfig}'
85 + pkg_config_libdir = '${EPREFIX}/usr/$(get_libdir)/pkgconfig'
86
87 [host_machine]
88 system = '${system}'
89 cpu_family = '${cpu_family}'
90 cpu = '${cpu}'
91 - endian = '$(tc-endian)'
92 + endian = '$(tc-endian "${CHOST}")'
93 + EOF
94 +
95 + echo "${fn}"
96 +}
97 +
98 +# @FUNCTION: _meson_create_native_file
99 +# @RETURN: path to native file
100 +# @INTERNAL
101 +# @DESCRIPTION:
102 +# Creates a native file. meson uses this to define settings for
103 +# native compilers. This function is called from meson_src_configure.
104 +_meson_create_native_file() {
105 + local system cpu_family cpu
106 + _meson_get_machine_info "${CBUILD}"
107 +
108 + local fn=${T}/meson.${CBUILD}.ini
109 +
110 + cat > "${fn}" <<-EOF
111 + [binaries]
112 + ar = $(_meson_env_array "$(tc-getBUILD_AR)")
113 + c = $(_meson_env_array "$(tc-getBUILD_CC)")
114 + cpp = $(_meson_env_array "$(tc-getBUILD_CXX)")
115 + fortran = $(_meson_env_array "$(tc-getBUILD_PROG FC gfortran)")
116 + llvm-config = '$(tc-getBUILD_PROG LLVM_CONFIG llvm-config)'
117 + objc = $(_meson_env_array "$(tc-getBUILD_PROG OBJC cc)")
118 + objcpp = $(_meson_env_array "$(tc-getBUILD_PROG OBJCXX c++)")
119 + pkgconfig = '$(tc-getBUILD_PKG_CONFIG)'
120 + strip = $(_meson_env_array "$(tc-getBUILD_STRIP)")
121 + windres = $(_meson_env_array "$(tc-getBUILD_PROG RC windres)")
122 +
123 + [properties]
124 + c_args = $(_meson_env_array "${BUILD_CFLAGS} ${BUILD_CPPFLAGS}")
125 + c_link_args = $(_meson_env_array "${BUILD_CFLAGS} ${BUILD_LDFLAGS}")
126 + cpp_args = $(_meson_env_array "${BUILD_CXXFLAGS} ${BUILD_CPPFLAGS}")
127 + cpp_link_args = $(_meson_env_array "${BUILD_CXXFLAGS} ${BUILD_LDFLAGS}")
128 + fortran_args = $(_meson_env_array "${BUILD_FCFLAGS}")
129 + fortran_link_args = $(_meson_env_array "${BUILD_FCFLAGS} ${BUILD_LDFLAGS}")
130 + objc_args = $(_meson_env_array "${BUILD_OBJCFLAGS} ${BUILD_CPPFLAGS}")
131 + objc_link_args = $(_meson_env_array "${BUILD_OBJCFLAGS} ${BUILD_LDFLAGS}")
132 + objcpp_args = $(_meson_env_array "${BUILD_OBJCXXFLAGS} ${BUILD_CPPFLAGS}")
133 + objcpp_link_args = $(_meson_env_array "${BUILD_OBJCXXFLAGS} ${BUILD_LDFLAGS}")
134 + needs_exe_wrapper = false
135 + pkg_config_libdir = '${EPREFIX}/usr/$(get_libdir)/pkgconfig'
136 +
137 + [build_machine]
138 + system = '${system}'
139 + cpu_family = '${cpu_family}'
140 + cpu = '${cpu}'
141 + endian = '$(tc-endian "${CHOST}")'
142 EOF
143 +
144 + echo "${fn}"
145 }
146
147 # @FUNCTION: meson_use
148 @@ -226,6 +287,11 @@ meson_feature() {
149 meson_src_configure() {
150 debug-print-function ${FUNCNAME} "$@"
151
152 + tc-export_build_env
153 + : ${BUILD_FCFLAGS:=${FCFLAGS}}
154 + : ${BUILD_OBJCFLAGS:=${OBJCFLAGS}}
155 + : ${BUILD_OBJCXXFLAGS:=${OBJCXXFLAGS}}
156 +
157 local mesonargs=(
158 meson setup
159 --buildtype plain
160 @@ -234,12 +300,13 @@ meson_src_configure() {
161 --prefix "${EPREFIX}/usr"
162 --sysconfdir "${EPREFIX}/etc"
163 --wrap-mode nodownload
164 - --pkg-config-path="${PKG_CONFIG_PATH-${EPREFIX}/usr/share/pkgconfig}"
165 + --build.pkg-config-path="${EPREFIX}/usr/share/pkgconfig"
166 + --pkg-config-path="${EPREFIX}/usr/share/pkgconfig"
167 + --native-file "$(_meson_create_native_file)"
168 )
169
170 - if tc-is-cross-compiler || [[ ${ABI} != ${DEFAULT_ABI-${ABI}} ]]; then
171 - _meson_create_cross_file || die "unable to write meson cross file"
172 - mesonargs+=( --cross-file "${T}/meson.${CHOST}.${ABI}" )
173 + if tc-is-cross-compiler; then
174 + mesonargs+=( --cross-file "$(_meson_create_cross_file)" )
175 fi
176
177 BUILD_DIR="${BUILD_DIR:-${WORKDIR}/${P}-build}"
178 @@ -273,7 +340,7 @@ meson_src_configure() {
179 python_export_utf8_locale
180
181 echo "${mesonargs[@]}" >&2
182 - tc-env_build "${mesonargs[@]}" || die
183 + "${mesonargs[@]}" || die
184 }
185
186 # @FUNCTION: meson_src_compile
187 --
188 2.26.2