47d4f044ecc49b7cd3efa6ae061c8a06cb9260c0
[fio.git] / ci / actions-build.sh
1 #!/bin/bash
2 # This script expects to be invoked from the base fio directory.
3 set -eu
4
5 SCRIPT_DIR=$(dirname "$0")
6 # shellcheck disable=SC1091
7 . "${SCRIPT_DIR}/common.sh"
8
9 main() {
10     local extra_cflags="-Werror"
11     local configure_flags=()
12
13     set_ci_target_os
14     case "${CI_TARGET_BUILD}/${CI_TARGET_OS}" in
15         android*/*)
16             export UNAME=Android
17             if [ -z "${CI_TARGET_ARCH}" ]; then
18                 echo "Error: CI_TARGET_ARCH has not been set"
19                 return 1
20             fi
21             NDK=$PWD/android-ndk-r24/toolchains/llvm/prebuilt/linux-x86_64/bin
22             export PATH="${NDK}:${PATH}"
23             if [ "${CI_TARGET_BUILD}" = "android" ]; then
24                 export LIBS="-landroid"
25             fi
26             CC=${NDK}/${CI_TARGET_ARCH}-clang
27             if [ ! -e "${CC}" ]; then
28                 echo "Error: could not find ${CC}"
29                 return 1
30             fi
31             ;;
32         */linux)
33             case "${CI_TARGET_ARCH}" in
34                 "i686")
35                     extra_cflags="${extra_cflags} -m32"
36                     export LDFLAGS="-m32"
37                     ;;
38                 "x86_64")
39                     configure_flags+=(
40                         "--enable-cuda"
41                         "--enable-libiscsi"
42                         "--enable-libnbd"
43                     )
44                     ;;
45             esac
46             ;;
47         */windows)
48             configure_flags+=("--disable-native")
49             case "${CI_TARGET_ARCH}" in
50                 "i686")
51                     configure_flags+=("--build-32bit-win")
52                     ;;
53                 "x86_64")
54                     ;;
55             esac
56             if [ "${CI_TARGET_BUILD}" = "windows-msys2-64" ]; then
57                 configure_flags+=("--disable-tls")
58             fi
59             ;;
60     esac
61     configure_flags+=(--extra-cflags="${extra_cflags}")
62
63     ./configure "${configure_flags[@]}"
64     make -j "$(nproc 2>/dev/null || sysctl -n hw.logicalcpu)"
65 # macOS does not have nproc, so we have to use sysctl to obtain the number of
66 # logical CPUs.
67 }
68
69 main