Alex Bennée <[email protected]> writes:

> Pierrick Bouvier <[email protected]> writes:
>
>> When a user set explicit cross cc, we ensure it's available and working.
>> When a user set explicit cross cflags, we ensure they work with default
>> or overriden cross_cc.
>>
>> Made the first implementation with a single meson option (array), which
>> proved to be absolutely unreadable.
>> By having one option per target, we directly detect issue at configure
>> time, either for user, or when iterating on all our targets. This
>> ensures user can't mispell any target name, and that we can't forget any
>> new one in the future.
>> Also, it shows them in the configuration summary, which is a bonus.
>>
>> Since we now only need to know compiler to write tcg tests, we can
>> simply alias -cross-prefix-* options to compiler override.
>>
>> Examples
>> --------
>>
>> wrong architecture:
>> $ ./configure --cross-cc-bad='cc'
>> ../meson.build:1:0: ERROR: Unknown option: "tcg_tests_cross_cc_bad"
>>
>> wrong option:
>> $ ./configure --cross-cc-cflags-aarch64='-bad-option'
>> ../tests/tcg/meson.build:228:10: ERROR: Command 
>> `/usr/bin/aarch64-linux-gnu-gcc 
>> /home/pbouvier/.work/qemu/tests/tcg/test_cc.c -bad-option -static -nostdlib 
>> -r -o /dev/null` failed with status 1.
>> A full log can be found at /qemu/build/meson-logs/meson-log.txt
>>
>> cross compile with clang (fails at the moment, since some tests have
>> compilation errors with it):
>> $ ./configure --target-list=aarch64-linux-user --cross-cc-aarch64='clang' 
>> --cross-cc-cflags-aarch64='-target aarch64-linux-gnu'
>>   User defined options
>>   ...
>>     tcg_tests_cross_cc_aarch64      : clang
>>     tcg_tests_cross_cflags_aarch64  : -target aarch64-linux-gnu
>>
>> Signed-off-by: Pierrick Bouvier <[email protected]>
>> ---
>>  configure             | 27 ++++++-------
>>  meson_options.txt     | 89 +++++++++++++++++++++++++++++++++++++++++++
>>  tests/tcg/meson.build | 30 ++++++++++++---
>>  3 files changed, 126 insertions(+), 20 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 568de41dadd..c9e2cdcce5f 100755
>> --- a/configure
>> +++ b/configure
>> @@ -227,19 +227,6 @@ for opt do
>>    ;;
>>    --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
>>    ;;
>> -  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO 
>> option"
>> -  ;;
>> -  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; 
>> cc_arch=${cc_arch%%=*}
>> -                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
>> -  ;;
>> -  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
>> -                eval "cross_cc_${cc_arch}=\$optarg"
>> -  ;;
>> -  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad 
>> --cross-prefix-FOO option"
>> -  ;;
>> -  --cross-prefix-*) cc_arch=${opt#--cross-prefix-}; cc_arch=${cc_arch%%=*}
>> -                    eval "cross_prefix_${cc_arch}=\$optarg"
>> -  ;;
>>    --without-default-features) default_feature="no"
>>    ;;
>>    --wasm64-32bit-address-limit) wasm64_memory64="2"
>> @@ -632,9 +619,19 @@ for opt do
>>    ;;
>>    --extra-ldflags=*)
>>    ;;
>> -  --cross-cc-*)
>> +  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO 
>> option"
>>    ;;
>> -  --cross-prefix-*)
>> +  --cross-cc-cflags-*) arch=${opt#--cross-cc-cflags-}; arch=${arch%%=*}
>> +                       meson_option_add 
>> "-Dtcg_tests_cross_cflags_${arch}=${optarg}"
>> +  ;;
>> +  --cross-cc-*) arch=${opt#--cross-cc-}; arch=${arch%%=*}
>> +                meson_option_add "-Dtcg_tests_cross_cc_${arch}=${optarg}"
>> +  ;;
>> +  --cross-prefix-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad 
>> --cross-prefix-FOO option"
>> +  ;;
>> +  # cross-prefix is just used as a syntactic sugar for -cross-cc.
>> +  --cross-prefix-*) arch=${opt#--cross-prefix-}; arch=${arch%%=*}
>> +                    meson_option_add 
>> "-Dtcg_tests_cross_cc_${arch}=${optarg}gcc"
>>    ;;
>>    --enable-docs) docs=enabled
>>    ;;
>> diff --git a/meson_options.txt b/meson_options.txt
>> index 5e91969414a..fd9ff0df893 100644
>> --- a/meson_options.txt
>> +++ b/meson_options.txt
>> @@ -389,3 +389,92 @@ option('containers', type: 'boolean', value: true,
>>         description: 'use containers to cross compile tcg tests')
>>  option('container_command', type: 'string',
>>         description: 'command to build/run containers')
>> +
>> +option('tcg_tests_cross_cc_aarch64', type: 'string',
>> +       description: 'cc for aarch64 tcg tests')
>> +option('tcg_tests_cross_cflags_aarch64', type: 'string',
>> +       description: 'cflags for aarch64 tcg tests')
>> +option('tcg_tests_cross_cc_aarch64_be', type: 'string',
>> +       description: 'cc for aarch64_be tcg tests')
>> +option('tcg_tests_cross_cflags_aarch64_be', type: 'string',
>> +       description: 'cflags for aarch64_be tcg tests')
>> +option('tcg_tests_cross_cc_alpha', type: 'string',
>> +       description: 'cc for alpha tcg tests')
>> +option('tcg_tests_cross_cflags_alpha', type: 'string',
>> +       description: 'cflags for alpha tcg tests')
>> +option('tcg_tests_cross_cc_arm', type: 'string',
>> +       description: 'cc for arm tcg tests')
>> +option('tcg_tests_cross_cflags_arm', type: 'string',
>> +       description: 'cflags for arm tcg tests')
>> +option('tcg_tests_cross_cc_hexagon', type: 'string',
>> +       description: 'cc for hexagon tcg tests')
>> +option('tcg_tests_cross_cflags_hexagon', type: 'string',
>> +       description: 'cflags for hexagon tcg tests')
>> +option('tcg_tests_cross_cc_hppa', type: 'string',
>> +       description: 'cc for hppa tcg tests')
>> +option('tcg_tests_cross_cflags_hppa', type: 'string',
>> +       description: 'cflags for hppa tcg tests')
>> +option('tcg_tests_cross_cc_i386', type: 'string',
>> +       description: 'cc for i386 tcg tests')
>> +option('tcg_tests_cross_cflags_i386', type: 'string',
>> +       description: 'cflags for i386 tcg tests')
>> +option('tcg_tests_cross_cc_loongarch64', type: 'string',
>> +       description: 'cc for loongarch64 tcg tests')
>> +option('tcg_tests_cross_cflags_loongarch64', type: 'string',
>> +       description: 'cflags for loongarch64 tcg tests')
>> +option('tcg_tests_cross_cc_m68k', type: 'string',
>> +       description: 'cc for m68k tcg tests')
>> +option('tcg_tests_cross_cflags_m68k', type: 'string',
>> +       description: 'cflags for m68k tcg tests')
>> +option('tcg_tests_cross_cc_mips', type: 'string',
>> +       description: 'cc for mips tcg tests')
>> +option('tcg_tests_cross_cflags_mips', type: 'string',
>> +       description: 'cflags for mips tcg tests')
>> +option('tcg_tests_cross_cc_mips64', type: 'string',
>> +       description: 'cc for mips64 tcg tests')
>> +option('tcg_tests_cross_cflags_mips64', type: 'string',
>> +       description: 'cflags for mips64 tcg tests')
>> +option('tcg_tests_cross_cc_mips64el', type: 'string',
>> +       description: 'cc for mips64el tcg tests')
>> +option('tcg_tests_cross_cflags_mips64el', type: 'string',
>> +       description: 'cflags for mips64el tcg tests')
>> +option('tcg_tests_cross_cc_or1k', type: 'string',
>> +       description: 'cc for or1k tcg tests')
>> +option('tcg_tests_cross_cflags_or1k', type: 'string',
>> +       description: 'cflags for or1k tcg tests')
>> +option('tcg_tests_cross_cc_ppc64', type: 'string',
>> +       description: 'cc for ppc64 tcg tests')
>> +option('tcg_tests_cross_cflags_ppc64', type: 'string',
>> +       description: 'cflags for ppc64 tcg tests')
>> +option('tcg_tests_cross_cc_ppc64le', type: 'string',
>> +       description: 'cc for ppc64le tcg tests')
>> +option('tcg_tests_cross_cflags_ppc64le', type: 'string',
>> +       description: 'cflags for ppc64le tcg tests')
>> +option('tcg_tests_cross_cc_riscv64', type: 'string',
>> +       description: 'cc for riscv64 tcg tests')
>> +option('tcg_tests_cross_cflags_riscv64', type: 'string',
>> +       description: 'cflags for riscv64 tcg tests')
>> +option('tcg_tests_cross_cc_s390x', type: 'string',
>> +       description: 'cc for s390x tcg tests')
>> +option('tcg_tests_cross_cflags_s390x', type: 'string',
>> +       description: 'cflags for s390x tcg tests')
>> +option('tcg_tests_cross_cc_sh4', type: 'string',
>> +       description: 'cc for sh4 tcg tests')
>> +option('tcg_tests_cross_cflags_sh4', type: 'string',
>> +       description: 'cflags for sh4 tcg tests')
>> +option('tcg_tests_cross_cc_tricore', type: 'string',
>> +       description: 'cc for tricore tcg tests')
>> +option('tcg_tests_cross_cflags_tricore', type: 'string',
>> +       description: 'cflags for tricore tcg tests')
>> +option('tcg_tests_cross_cc_x86_64', type: 'string',
>> +       description: 'cc for x86_64 tcg tests')
>> +option('tcg_tests_cross_cflags_x86_64', type: 'string',
>> +       description: 'cflags for x86_64 tcg tests')
>> +option('tcg_tests_cross_cc_xtensa', type: 'string',
>> +       description: 'cc for xtensa tcg tests')
>> +option('tcg_tests_cross_cflags_xtensa', type: 'string',
>> +       description: 'cflags for xtensa tcg tests')
>> +option('tcg_tests_cross_cc_xtensaeb', type: 'string',
>> +       description: 'cc for xtensaeb tcg tests')
>> +option('tcg_tests_cross_cflags_xtensaeb', type: 'string',
>> +       description: 'cflags for xtensaeb tcg tests')
>> diff --git a/tests/tcg/meson.build b/tests/tcg/meson.build
>> index ba73eecf1c9..8dd6623ad1d 100644
>> --- a/tests/tcg/meson.build
>> +++ b/tests/tcg/meson.build
>> @@ -180,6 +180,8 @@ foreach target, plan: tcg_tests
>>      continue
>>    endif
>>  
>> +  cc_arch = target.replace('-linux-user', '').replace('-softmmu', '')
>> +
>>    # Detect duplicated executables/tests, and report an error to force user 
>> to
>>    # choose how to deal with it.
>>    built_tests = {}
>> @@ -197,16 +199,34 @@ foreach target, plan: tcg_tests
>>    endforeach
>>  
>>    cc = find_program(plan['cc'], required : false)
>> +  cc_cflags = []
>> +
>> +  check_flags = []
>> +  check_required = false
>> +  cross_cc = get_option('tcg_tests_cross_cc_' + cc_arch)
>> +  if cross_cc != ''
>> +    # we make sure cross cc exists
>> +    cc = find_program(cross_cc, required: true)
>> +    check_required = true
>> +  endif
>> +  cross_cflags = get_option('tcg_tests_cross_cflags_' + cc_arch)
>> +  if cross_cflags != ''
>> +    cc_cflags = cross_cflags.split()
>> +    # and that cross cc can compile programs
>> +    check_flags = cc_cflags
>> +    check_required = true
>> +  endif
>> +
>>    cc_from_system = cc.found()
>>    has_cc = cc.found()
>>    if has_cc
>> -    check_flags = ['-static']
>> +    check_flags += ['-static']
>>      if target.endswith('softmmu')
>> -      check_flags = ['-nostdlib', '-r']
>> +      check_flags += ['-nostdlib', '-r']
>>      endif

What it needs is -ffreestanding - it gets away with it on linux as the
compilers are mostly userspace compilers and it can fallback to those
headers. On macOS or if you install a pure bare metal compiler it would
fail.

<snip>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro

Reply via email to