• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# shellcheck disable=SC1003 # works for us now...
3# shellcheck disable=SC2086 # we want word splitting
4# shellcheck disable=SC1091 # paths only become valid at runtime
5
6. "${SCRIPTS_DIR}/setup-test-env.sh"
7
8section_switch meson-cross-file "meson: cross file generate"
9
10set -e
11set -o xtrace
12
13comma_separated() {
14  local IFS=,
15  echo "$*"
16}
17
18CROSS_FILE=/cross_file-"$CROSS".txt
19
20export PATH=$PATH:$PWD/.gitlab-ci/build
21
22touch native.file
23printf > native.file "%s\n" \
24  "[binaries]" \
25  "c = 'compiler-wrapper-${CC:-gcc}.sh'" \
26  "cpp = 'compiler-wrapper-${CXX:-g++}.sh'"
27
28# We need to control the version of llvm-config we're using, so we'll
29# tweak the cross file or generate a native file to do so.
30if test -n "$LLVM_VERSION"; then
31    LLVM_CONFIG="llvm-config-${LLVM_VERSION}"
32    echo "llvm-config = '$(which "$LLVM_CONFIG")'" >> native.file
33    if [ -n "$CROSS" ]; then
34      sed -i -e '/\[binaries\]/a\' -e "llvm-config = '$(which "$LLVM_CONFIG")'" $CROSS_FILE
35    fi
36    $LLVM_CONFIG --version
37fi
38
39# cross-xfail-$CROSS, if it exists, contains a list of tests that are expected
40# to fail for the $CROSS configuration, one per line. you can then mark those
41# tests in their meson.build with:
42#
43# test(...,
44#      should_fail: meson.get_external_property('xfail', '').contains(t),
45#     )
46#
47# where t is the name of the test, and the '' is the string to search when
48# not cross-compiling (which is empty, because for amd64 everything is
49# expected to pass).
50if [ -n "$CROSS" ]; then
51    CROSS_XFAIL=.gitlab-ci/cross-xfail-"$CROSS"
52    if [ -s "$CROSS_XFAIL" ]; then
53        sed -i \
54            -e '/\[properties\]/a\' \
55            -e "xfail = '$(tr '\n' , < $CROSS_XFAIL)'" \
56            "$CROSS_FILE"
57    fi
58fi
59
60if [ -n "$HOST_BUILD_OPTIONS" ]; then
61    section_switch meson-host-configure "meson: host configure"
62
63    # Stash the PKG_CONFIG_LIBDIR so that we can use the base x86_64 image
64    # libraries.
65    tmp_pkg_config_libdir=$PKG_CONFIG_LIBDIR
66    unset PKG_CONFIG_LIBDIR
67
68    # Compile a host version for the few tools we need for a cross build (for
69    # now just intel-clc)
70    rm -rf _host_build
71    meson setup _host_build \
72          --native-file=native.file \
73          -D prefix=/usr \
74          -D libdir=lib \
75          ${HOST_BUILD_OPTIONS}
76
77    pushd _host_build
78
79    section_switch meson-host-build "meson: host build"
80
81    meson configure
82    ninja
83    ninja install
84    popd
85
86    # Restore PKG_CONFIG_LIBDIR
87    if [ -n "$tmp_pkg_config_libdir" ]; then
88        export PKG_CONFIG_LIBDIR=$tmp_pkg_config_libdir
89    fi
90fi
91
92# Only use GNU time if available, not any shell built-in command
93case $CI_JOB_NAME in
94    # ASAN leak detection is incompatible with strace
95    *-asan*)
96        if test -f /usr/bin/time; then
97            MESON_TEST_ARGS+=--wrapper=$PWD/.gitlab-ci/meson/time.sh
98        fi
99        Xvfb :0 -screen 0 1024x768x16 &
100        export DISPLAY=:0.0
101        ;;
102    *)
103        if test -f /usr/bin/time -a -f /usr/bin/strace; then
104            MESON_TEST_ARGS+=--wrapper=$PWD/.gitlab-ci/meson/time-strace.sh
105        fi
106        ;;
107esac
108
109# LTO handling
110case $CI_PIPELINE_SOURCE in
111    schedule)
112      # run builds with LTO only for nightly
113      if [ "$CI_JOB_NAME" == "debian-ppc64el" ]; then
114	      # /tmp/ccWlDCPV.s: Assembler messages:
115	      # /tmp/ccWlDCPV.s:15250880: Error: operand out of range (0xfffffffffdd4e688 is not between 0xfffffffffe000000 and 0x1fffffc)
116	      LTO=false
117      # enable one by one for now
118      elif [ "$CI_JOB_NAME" == "fedora-release" ] || [ "$CI_JOB_NAME" == "debian-build-testing" ]; then
119	      LTO=true
120      else
121	      LTO=false
122      fi
123      ;;
124    *)
125      LTO=false
126      ;;
127esac
128
129if [ "$LTO" == "true" ]; then
130    MAX_LD=2
131else
132    MAX_LD=${FDO_CI_CONCURRENT:-4}
133fi
134
135# shellcheck disable=2206
136force_fallback_for=(
137  # FIXME: explain what these are needed for
138  perfetto
139  syn
140  paste
141  pest
142  pest_derive
143  pest_generator
144  pest_meta
145  roxmltree
146  indexmap
147  ${FORCE_FALLBACK_FOR:-}
148)
149
150section_switch meson-configure "meson: configure"
151
152rm -rf _build
153meson setup _build \
154      --native-file=native.file \
155      --wrap-mode=nofallback \
156      --force-fallback-for "$(comma_separated "${force_fallback_for[@]}")" \
157      ${CROSS+--cross "$CROSS_FILE"} \
158      -D prefix=$PWD/install \
159      -D libdir=lib \
160      -D buildtype=${BUILDTYPE:?} \
161      -D build-tests=true \
162      -D c_args="$(echo -n $C_ARGS)" \
163      -D c_link_args="$(echo -n $C_LINK_ARGS)" \
164      -D cpp_args="$(echo -n $CPP_ARGS)" \
165      -D cpp_link_args="$(echo -n $CPP_LINK_ARGS)" \
166      -D enable-glcpp-tests=false \
167      -D libunwind=${UNWIND} \
168      ${DRI_LOADERS} \
169      ${GALLIUM_ST} \
170      -D gallium-opencl=disabled \
171      -D gallium-drivers=${GALLIUM_DRIVERS:-[]} \
172      -D vulkan-drivers=${VULKAN_DRIVERS:-[]} \
173      -D video-codecs=all \
174      -D werror=true \
175      -D b_lto=${LTO} \
176      -D backend_max_links=${MAX_LD} \
177      ${EXTRA_OPTION}
178cd _build
179meson configure
180
181uncollapsed_section_switch meson-build "meson: build"
182
183ninja
184
185
186uncollapsed_section_switch meson-test "meson: test"
187LC_ALL=C.UTF-8 meson test --num-processes "${FDO_CI_CONCURRENT:-4}" --print-errorlogs ${MESON_TEST_ARGS}
188section_switch meson-install "meson: install"
189ninja install
190cd ..
191section_end meson-install
192