Re: [gentoo-dev] [PATCH] meson.eclass: implement basic cross-compiler support
This has been pushed.
Re: [gentoo-dev] [PATCH] meson.eclass: implement basic cross-compiler support
On Mon, May 29, 2017 at 5:06 PM, Michał Górnywrote: > On pon, 2017-05-29 at 16:58 -0400, Mike Gilbert wrote: >> + # system roughly corresponds to uname -s (lowercase) >> + local system=unknown >> + case ${CHOST} in >> + *-aix*) system=aix ;; >> + *-cygwin*) system=cygwin ;; >> + *-darwin*) system=darwin ;; >> + *-freebsd*) system=freebsd ;; >> + *-linux*) system=linux ;; >> + *-solaris*) system=sunos ;; > > Don't you want to die on unknown system? Or is it likely to work anyway? Good question. The 'system' property controls some built-in logic in meson itself (mainly for MS Windows), and may be referenced by project files as 'host_machine.system()'. Setting it to 'unknown' may cause failures for projects that actually look at it. However, I think most projects would work without having this set to a known value. >> + esac >> + >> + local cpu_family=$(tc-arch) >> + case ${cpu_family} in >> + amd64) cpu_family=x86_64 ;; >> + arm64) cpu_family=aarch64 ;; > > That's purely mapping from known-wrong values, correct? Maybe it'd be > reasonable to assert for all correct too, and fail on unknown? Yes, it corrects two obvious deviations from uname -m on Linux. x86 is ok since that is what meson expects/generates for i?86. I'm not sure what you mean by "assert for all correct"; if you mean check for all valid values for cpu_family, such a list does not exist. Similar to 'system' this property may or may not be used depending on the project. Defaulting to "unknown" should be fine in many cases. I don't think we need to fail. >> + # Both meson(1) and _meson_create_cross_file need these >> + tc-export AR CC CXX STRIP > > Wouldn't it be reasonable to make them local first anyway? I would try > to avoid polluting the environment. Makes sense. I'll revise this to "local -x CC=$(tc-getCC)", etc.
Re: [gentoo-dev] [PATCH] meson.eclass: implement basic cross-compiler support
On pon, 2017-05-29 at 16:58 -0400, Mike Gilbert wrote: > --- > eclass/meson.eclass | 74 > + > 1 file changed, 57 insertions(+), 17 deletions(-) > > diff --git a/eclass/meson.eclass b/eclass/meson.eclass > index 758e4180ba7a..0fdb1d848973 100644 > --- a/eclass/meson.eclass > +++ b/eclass/meson.eclass > @@ -39,8 +39,7 @@ esac > > if [[ -z ${_MESON_ECLASS} ]]; then > > -# FIXME: We will need to inherit toolchain-funcs as well to support crossdev. > -inherit ninja-utils > +inherit ninja-utils toolchain-funcs > > fi > > @@ -71,17 +70,52 @@ DEPEND=">=dev-util/meson-0.39.1 > # Optional meson arguments as Bash array; this should be defined before > # calling meson_src_configure. > > -# Create a cross file for meson > -# fixme: This function should write a cross file as described at the > -# following url. > -# http://mesonbuild.com/Cross-compilation.html > -# _meson_create_cross_file() { > -#touch "${T}"/meson.crossfile > -# } > +# @FUNCTION: _meson_create_cross_file > +# @INTERNAL > +# @DESCRIPTION: > +# Creates a cross file. meson uses this to define settings for > +# cross-compilers. This function is called from meson_src_configure. > +_meson_create_cross_file() { > + # Reference: http://mesonbuild.com/Cross-compilation.html > + > + # system roughly corresponds to uname -s (lowercase) > + local system=unknown > + case ${CHOST} in > + *-aix*) system=aix ;; > + *-cygwin*) system=cygwin ;; > + *-darwin*) system=darwin ;; > + *-freebsd*) system=freebsd ;; > + *-linux*) system=linux ;; > + *-solaris*) system=sunos ;; Don't you want to die on unknown system? Or is it likely to work anyway? > + esac > + > + local cpu_family=$(tc-arch) > + case ${cpu_family} in > + amd64) cpu_family=x86_64 ;; > + arm64) cpu_family=aarch64 ;; That's purely mapping from known-wrong values, correct? Maybe it'd be reasonable to assert for all correct too, and fail on unknown? > + esac > + > + # This may require adjustment based on CFLAGS > + local cpu=${CHOST%%-*} > + > + cat > "${T}/meson.${CHOST}" <<-EOF > + [binaries] > + ar = '${AR}' > + c = '${CC}' > + cpp = '${CXX}' > + strip = '${STRIP}' > + > + [host_machine] > + system = '${system}' > + cpu_family = '${cpu_family}' > + cpu = '${cpu}' > + endian = '$(tc-endian)' > + EOF > +} > > # @FUNCTION: meson_src_configure > # @DESCRIPTION: > -# This is the meson_src_configure function > +# This is the meson_src_configure function. > meson_src_configure() { > debug-print-function ${FUNCNAME} "$@" > > @@ -94,13 +128,19 @@ meson_src_configure() { > --sysconfdir "${EPREFIX}/etc" > ) > > -# fixme: uncomment this for crossdev support > -#if tc-is-cross-compiler; then > -#_meson_create_cross_file || die "unable to write meson cross > file" > -#mesonargs+=( > -#--cross-file "${T}"/meson.crossfile > -#) > -#fi > + # Both meson(1) and _meson_create_cross_file need these > + tc-export AR CC CXX STRIP Wouldn't it be reasonable to make them local first anyway? I would try to avoid polluting the environment. > + > + if tc-is-cross-compiler; then > + _meson_create_cross_file || die "unable to write meson cross > file" > + mesonargs+=( > + --cross-file "${T}"/meson.${CHOST} > + ) > + # In cross mode, meson uses CC/CXX as the "build" compilers > + local -x AR=$(tc-getBUILD_AR) > + local -x CC=$(tc-getBUILD_CC) > + local -x CXX=$(tc-getBUILD_CXX) > + fi > > # Append additional arguments from ebuild > mesonargs+=("${emesonargs[@]}") -- Best regards, Michał Górny signature.asc Description: This is a digitally signed message part
[gentoo-dev] [PATCH] meson.eclass: implement basic cross-compiler support
--- eclass/meson.eclass | 74 + 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/eclass/meson.eclass b/eclass/meson.eclass index 758e4180ba7a..0fdb1d848973 100644 --- a/eclass/meson.eclass +++ b/eclass/meson.eclass @@ -39,8 +39,7 @@ esac if [[ -z ${_MESON_ECLASS} ]]; then -# FIXME: We will need to inherit toolchain-funcs as well to support crossdev. -inherit ninja-utils +inherit ninja-utils toolchain-funcs fi @@ -71,17 +70,52 @@ DEPEND=">=dev-util/meson-0.39.1 # Optional meson arguments as Bash array; this should be defined before # calling meson_src_configure. -# Create a cross file for meson -# fixme: This function should write a cross file as described at the -# following url. -# http://mesonbuild.com/Cross-compilation.html -# _meson_create_cross_file() { -# touch "${T}"/meson.crossfile -# } +# @FUNCTION: _meson_create_cross_file +# @INTERNAL +# @DESCRIPTION: +# Creates a cross file. meson uses this to define settings for +# cross-compilers. This function is called from meson_src_configure. +_meson_create_cross_file() { + # Reference: http://mesonbuild.com/Cross-compilation.html + + # system roughly corresponds to uname -s (lowercase) + local system=unknown + case ${CHOST} in + *-aix*) system=aix ;; + *-cygwin*) system=cygwin ;; + *-darwin*) system=darwin ;; + *-freebsd*) system=freebsd ;; + *-linux*) system=linux ;; + *-solaris*) system=sunos ;; + esac + + local cpu_family=$(tc-arch) + case ${cpu_family} in + amd64) cpu_family=x86_64 ;; + arm64) cpu_family=aarch64 ;; + esac + + # This may require adjustment based on CFLAGS + local cpu=${CHOST%%-*} + + cat > "${T}/meson.${CHOST}" <<-EOF + [binaries] + ar = '${AR}' + c = '${CC}' + cpp = '${CXX}' + strip = '${STRIP}' + + [host_machine] + system = '${system}' + cpu_family = '${cpu_family}' + cpu = '${cpu}' + endian = '$(tc-endian)' + EOF +} # @FUNCTION: meson_src_configure # @DESCRIPTION: -# This is the meson_src_configure function +# This is the meson_src_configure function. meson_src_configure() { debug-print-function ${FUNCNAME} "$@" @@ -94,13 +128,19 @@ meson_src_configure() { --sysconfdir "${EPREFIX}/etc" ) -# fixme: uncomment this for crossdev support -# if tc-is-cross-compiler; then -# _meson_create_cross_file || die "unable to write meson cross file" -# mesonargs+=( -# --cross-file "${T}"/meson.crossfile -# ) -# fi + # Both meson(1) and _meson_create_cross_file need these + tc-export AR CC CXX STRIP + + if tc-is-cross-compiler; then + _meson_create_cross_file || die "unable to write meson cross file" + mesonargs+=( + --cross-file "${T}"/meson.${CHOST} + ) + # In cross mode, meson uses CC/CXX as the "build" compilers + local -x AR=$(tc-getBUILD_AR) + local -x CC=$(tc-getBUILD_CC) + local -x CXX=$(tc-getBUILD_CXX) + fi # Append additional arguments from ebuild mesonargs+=("${emesonargs[@]}") -- 2.13.0