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