GitHub CI: change build system to meson
authorKirill Isakov <bootctl@gmail.com>
Fri, 18 Mar 2022 17:19:38 +0000 (23:19 +0600)
committerKirill Isakov <bootctl@gmail.com>
Wed, 23 Mar 2022 05:52:50 +0000 (11:52 +0600)
20 files changed:
.ci/build.sh [new file with mode: 0755]
.ci/conf.sh [changed mode: 0644->0755]
.ci/cross/linux/armhf [new file with mode: 0644]
.ci/cross/linux/mipsel [new file with mode: 0644]
.ci/cross/windows/amd64 [new file with mode: 0644]
.ci/deps.sh
.ci/package/deb/build.sh
.ci/package/deb/debian/info [deleted file]
.ci/package/deb/debian/rules
.ci/package/rpm/build.sh
.ci/package/rpm/tinc.spec
.ci/package/win/build.sh
.ci/package/win/installer.nsi
.ci/sanitizers/ignore.txt
.ci/test/prepare.sh
.ci/test/run.sh
.ci/tidy/run.sh
.ci/warn/run.sh
.clang-tidy
.github/workflows/test.yml

diff --git a/.ci/build.sh b/.ci/build.sh
new file mode 100755 (executable)
index 0000000..7be77ce
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+set -eux
+
+flags=$(./.ci/conf.sh "$@")
+
+# shellcheck disable=SC2086
+meson setup build $flags
+
+ninja -C build
old mode 100644 (file)
new mode 100755 (executable)
index d075aba..324331f
@@ -1,67 +1,38 @@
 #!/bin/sh
 
-set -eu
+set -eux
 
 add_flag() {
   printf ' %s ' "$@"
 }
 
 conf_linux() {
-  . /etc/os-release
-
-  if type rpm >&2; then
-    # CentOS 7 has OpenSSL 1.1 installed in a non-default location.
-    if [ -d /usr/include/openssl11 ]; then
-      add_flag --with-openssl-include=/usr/include/openssl11
-    fi
-
-    if [ -d /usr/lib64/openssl11 ]; then
-      add_flag --with-openssl-lib=/usr/lib64/openssl11
-    fi
-
-    # RHEL 8 does not ship miniupnpc.
-    if rpm -q miniupnpc-devel >&2; then
-      add_flag --enable-miniupnpc
-    fi
+  HOST="${HOST:-nonexistent}"
+  if [ "$HOST" = mingw ]; then
+    cross=".ci/cross/windows/amd64"
   else
-    # vde2 is available everywhere except the RHEL family.
-    add_flag --enable-vde
+    cross=".ci/cross/linux/$HOST"
   fi
-
-  # Cross-compilation.
-  if [ -n "${HOST:-}" ]; then
-    case "$HOST" in
-    armhf) triplet=arm-linux-gnueabihf ;;
-    mipsel) triplet=mipsel-linux-gnu ;;
-    *) exit 1 ;;
-    esac
-
-    add_flag --host="$triplet"
+  if [ -f "$cross" ]; then
+    add_flag --cross-file "$cross"
   fi
-
-  add_flag --enable-uml "$@"
+  add_flag -Dminiupnpc=auto -Duml=true
 }
 
 conf_windows() {
-  add_flag \
-    --enable-miniupnpc \
-    --disable-readline \
-    --with-curses-include=/mingw64/include/ncurses \
-    "$@"
+  add_flag -Dminiupnpc=auto
 }
 
 conf_macos() {
-  add_flag \
-    --with-openssl="$(brew --prefix openssl)" \
-    --with-miniupnpc="$(brew --prefix miniupnpc)" \
-    --enable-tunemu \
-    --enable-miniupnpc \
-    "$@"
+  openssl=$(brew --prefix openssl)
+  add_flag -Dminiupnpc=auto -Dpkg_config_path="$openssl/lib/pkgconfig"
 }
 
+add_flag -Dbuildtype=release "$@"
+
 case "$(uname -s)" in
-Linux) conf_linux "$@" ;;
-MINGW*) conf_windows "$@" ;;
-Darwin) conf_macos "$@" ;;
+Linux) conf_linux ;;
+MINGW*) conf_windows ;;
+Darwin) conf_macos ;;
 *) exit 1 ;;
 esac
diff --git a/.ci/cross/linux/armhf b/.ci/cross/linux/armhf
new file mode 100644 (file)
index 0000000..f87447e
--- /dev/null
@@ -0,0 +1,4 @@
+[binaries]
+c = 'arm-linux-gnueabihf-gcc'
+pkgconfig = 'arm-linux-gnueabihf-pkg-config'
+
diff --git a/.ci/cross/linux/mipsel b/.ci/cross/linux/mipsel
new file mode 100644 (file)
index 0000000..2bdfb8a
--- /dev/null
@@ -0,0 +1,4 @@
+[binaries]
+c = 'mipsel-linux-gnu-gcc'
+pkgconfig = 'mipsel-linux-gnu-pkg-config'
+
diff --git a/.ci/cross/windows/amd64 b/.ci/cross/windows/amd64
new file mode 100644 (file)
index 0000000..884dae8
--- /dev/null
@@ -0,0 +1,17 @@
+[properties]
+root = '/usr/x86_64-w64-mingw32'
+
+[binaries]
+c = 'x86_64-w64-mingw32-gcc'
+ar = 'x86_64-w64-mingw32-ar'
+as = 'x86_64-w64-mingw32-as'
+strip = 'x86_64-w64-mingw32-strip'
+windres = 'x86_64-w64-mingw32-windres'
+pkgconfig = 'x86_64-w64-mingw32-pkg-config'
+
+[host_machine]
+system = 'windows'
+endian = 'little'
+cpu = 'x86_64'
+cpu_family = 'x86_64'
+
index 2f0dab2..523e7aa 100755 (executable)
@@ -6,25 +6,28 @@ deps_linux_alpine() {
   apk upgrade
 
   apk add \
-    git binutils make autoconf automake gcc linux-headers diffutils \
-    procps socat shadow sudo libgcrypt-dev texinfo texlive gzip \
+    git binutils meson pkgconf gcc linux-headers diffutils \
+    procps socat shadow sudo libgcrypt-dev texinfo gzip \
     openssl-dev zlib-dev lzo-dev ncurses-dev readline-dev musl-dev lz4-dev vde2-dev
 }
 
-deps_linux_debian() {
-  export DEBIAN_FRONTEND=noninteractive
-
-  HOST=${HOST:-}
+deps_linux_debian_mingw() {
+  apt-get install -y \
+    mingw-w64 mingw-w64-tools \
+    wine wine-binfmt \
+    libgcrypt-mingw-w64-dev \
+    "$@"
+}
 
+deps_linux_debian_linux() {
   if [ -n "$HOST" ]; then
     dpkg --add-architecture "$HOST"
   fi
 
   apt-get update
-  apt-get upgrade -y
 
   apt-get install -y \
-    git binutils make autoconf automake gcc diffutils sudo texinfo texlive netcat-openbsd procps socat \
+    binutils make gcc \
     zlib1g-dev:"$HOST" \
     libssl-dev:"$HOST" \
     liblzo2-dev:"$HOST" \
@@ -38,6 +41,36 @@ deps_linux_debian() {
 
   if [ -n "$HOST" ]; then
     apt-get install -y crossbuild-essential-"$HOST" qemu-user
+  else
+    linux_openssl3
+  fi
+}
+
+deps_linux_debian() {
+  export DEBIAN_FRONTEND=noninteractive
+
+  apt-get update
+  apt-get upgrade -y
+  apt-get install -y git pkgconf diffutils sudo texinfo \
+    netcat-openbsd procps socat
+
+  HOST=${HOST:-}
+  if [ "$HOST" = mingw ]; then
+    deps_linux_debian_mingw "$@"
+  else
+    deps_linux_debian_linux "$@"
+  fi
+
+  . /etc/os-release
+
+  # Debian Buster ships an old version of meson (0.49).
+  # MinGW cross-compilation requires something newer than 0.55 that ships in Bullseye,
+  # or it fails when looking for dependencies in the OpenSSL wrap.
+  if [ "${ID:-}/${VERSION_CODENAME:-}" = debian/buster ] || [ "$HOST" = mingw ]; then
+    apt-get install -y python3 python3-pip ninja-build
+    pip3 install meson
+  else
+    apt-get install -y meson
   fi
 }
 
@@ -54,7 +87,7 @@ deps_linux_rhel() {
   yum upgrade -y
 
   yum install -y \
-    git binutils make autoconf automake gcc diffutils sudo texinfo-tex netcat procps systemd perl-IPC-Cmd \
+    git binutils make meson pkgconf gcc diffutils sudo texinfo-tex netcat procps systemd perl-IPC-Cmd \
     findutils socat lzo-devel zlib-devel lz4-devel ncurses-devel readline-devel libgcrypt-devel "$@"
 
   if yum info openssl11-devel; then
@@ -69,11 +102,6 @@ deps_linux_rhel() {
 }
 
 linux_openssl3() {
-  if [ -n "${HOST:-}" ]; then
-    echo >&2 "Not installing OpenSSL 3 to a cross-compilation job"
-    return
-  fi
-
   src=/usr/local/src/openssl
   ssl3=/opt/ssl3
 
@@ -86,7 +114,12 @@ linux_openssl3() {
   make -j"$(nproc)"
   make install_sw
 
-  ldconfig -v $ssl3/lib64
+  if [ -f /etc/ld.so.conf ]; then
+    echo $ssl3/lib64 >>/etc/ld.so.conf
+    ldconfig -v
+  else
+    ldconfig -v $ssl3/lib64
+  fi
 
   cd -
 }
@@ -101,7 +134,6 @@ deps_linux() {
 
   debian | ubuntu)
     deps_linux_debian "$@"
-    linux_openssl3
     ;;
 
   centos | almalinux | fedora)
@@ -114,7 +146,7 @@ deps_linux() {
 }
 
 deps_macos() {
-  brew install coreutils netcat automake lzo lz4 miniupnpc libgcrypt openssl "$@"
+  brew install coreutils netcat lzo lz4 miniupnpc libgcrypt openssl meson "$@"
   pip3 install --user compiledb
 }
 
index fa72fac..61396f1 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-set -euo pipefail
+set -euxo pipefail
 
 . /etc/os-release
 
@@ -18,8 +18,9 @@ export DEBIAN_FRONTEND=noninteractive
 apt-get install -y devscripts git-buildpackage dh-make
 
 export USER=${USER:-$(whoami)}
+export EMAIL=ci@tinc-vpn.org
 
-os="$ID-$VERSION_ID"
+os="$ID-${VERSION_ID:-unknown}"
 templates=$(dirname "$0")/debian
 
 git clean -dfx
@@ -47,5 +48,5 @@ cp "$templates/"* debian/
 # remove useless READMEs created by dh_make
 rm -f debian/README.*
 
-dpkg-buildpackage -d -us -uc
+dpkg-buildpackage -rfakeroot -us -uc -b
 mv ../*.deb .
diff --git a/.ci/package/deb/debian/info b/.ci/package/deb/debian/info
deleted file mode 100644 (file)
index 5468d6c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-doc/tinc.info
index e1cbc60..fd9343f 100755 (executable)
@@ -1,21 +1,7 @@
 #!/usr/bin/make -f
 
 %:
-       dh $@
-
-override_dh_auto_configure:
-       dh_auto_configure -- --enable-uml --enable-miniupnpc \
-               --with-systemd=/lib/systemd/system/
-       $(MAKE) clean
-
-override_dh_auto_install:
-       dh_auto_install -- install-html
-       # Remove info dir file
-       rm -f debian/tinc/usr/share/info/dir
+       dh $@ --buildsystem=meson
 
 override_dh_auto_test:
-       # Don't run the tests, it involves starting tinc daemons and making network connections.
-       # I don't think the autobuilders will like this.
-
-override_dh_installinit:
-       dh_installinit -r
+       # Disable tests.
index b07df47..48f57ad 100755 (executable)
@@ -1,23 +1,16 @@
 #!/bin/bash
 
-set -euo pipefail
+set -euxo pipefail
+
+if ! rpm -qi openssl-devel; then
+  exit 0
+fi
 
 find_tag() {
   git describe --always --tags --match='release-*' "$@"
 }
 
-# CentOS 7 has OpenSSL 1.1 installed in a non-default location.
-if [ -d /usr/include/openssl11 ]; then
-  set -- "$@" --with-openssl-include=/usr/include/openssl11
-fi
-
-if [ -d /usr/lib64/openssl11 ]; then
-  set -- "$@" --with-openssl-lib=/usr/lib64/openssl11
-fi
-
 spec=$HOME/rpmbuild/SPECS/tinc.spec
-configure=$(sh .ci/conf.sh)
-
 version=$(find_tag HEAD | sed 's/-/_/g')
 version=${version//release_/}
 
@@ -28,10 +21,8 @@ rpmdev-setuptree
 
 cp "$(dirname "$0")/tinc.spec" "$spec"
 sed -i "s/__VERSION__/$version/" "$spec"
-sed -i "s#__CONFIGURE_ARGS__#$configure#" "$spec"
 
 git clean -dfx
-autoreconf -fsi
 cp -a . ~/rpmbuild/BUILD
 
 rpmbuild -bb "$spec"
index eda70d4..58bbaf6 100644 (file)
@@ -6,7 +6,15 @@ Summary:        A virtual private network daemon
 License:        GPLv2+
 URL:            https://www.tinc-vpn.org/
 
+BuildRequires: gcc
+BuildRequires: meson
 BuildRequires: systemd
+BuildRequires: openssl-devel
+BuildRequires: lzo-devel
+BuildRequires: zlib-devel
+BuildRequires: lz4-devel
+BuildRequires: ncurses-devel
+BuildRequires: readline-devel
 
 Requires(post):   systemd
 Requires(preun):  systemd
@@ -22,16 +30,16 @@ information with each other over the Internet without exposing any
 information to others.
 
 %define debug_package %{nil}
+%define __meson_auto_features auto
 
 %prep
 
 %build
-%configure --with-systemd=%{_unitdir} __CONFIGURE_ARGS__
-%make_build
+%meson
+%meson_build
 
 %install
-%make_install
-rm -f %{buildroot}%{_infodir}/dir
+%meson_install
 
 %post
 %systemd_post %{name}@.service
@@ -43,7 +51,7 @@ rm -f %{buildroot}%{_infodir}/dir
 %systemd_postun_with_restart %{name}@.service
 
 %files
-%doc AUTHORS COPYING.README NEWS README.md THANKS doc/sample* doc/*.tex
+%doc AUTHORS COPYING.README NEWS README.md THANKS doc/sample*
 %license COPYING
 %{_mandir}/man*/%{name}*.*
 %{_infodir}/%{name}.info.*
index 098f455..d9738dd 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-set -euo pipefail
+set -euxo pipefail
 
 curl -o wintap.exe -L 'https://build.openvpn.net/downloads/releases/latest/tap-windows-latest-stable.exe'
 
index 4c4dd35..90645d0 100644 (file)
@@ -18,8 +18,8 @@ RequestExecutionLevel admin
 Section "Tinc"
   SetOutPath $INSTDIR
 
-  File ..\..\..\src\tinc.exe
-  File ..\..\..\src\tincd.exe
+  File ..\..\..\build\src\tinc.exe
+  File ..\..\..\build\src\tincd.exe
   File ..\..\..\wintap.exe
 
   CreateDirectory "$SMPROGRAMS\Tinc"
index c088e06..f214878 100644 (file)
@@ -1,9 +1,5 @@
-# plain make
-src:ed25519/*
-src:chacha-poly1305/*
-src:xoshiro.c
+# meson
+src:../src/ed25519/*
+src:../src/chacha-poly1305/*
+src:../src/xoshiro.c
 
-# make distcheck
-src:../../../src/ed25519/*
-src:../../../src/chacha-poly1305/*
-src:../../../src/xoshiro.c
index 8a01a3f..82f103f 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-set -eu
+set -eux
 
 if [ "$(id -u)" != 0 ] && sudo --preserve-env --non-interactive true; then
   echo >&2 "sudo already configured"
@@ -12,3 +12,8 @@ useradd --user-group build
 echo 'build ALL=(ALL) NOPASSWD: ALL' >/etc/sudoers.d/build
 chmod 440 /etc/sudoers.d/build
 visudo --check
+
+if [ -n "${HOST:-}" ]; then
+  update-binfmts --enable
+  rm -f /dev/net/tun
+fi
index 2d1eb07..fa23e24 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-set -eu
+set -eux
 
 bail() {
   echo >&2 "@"
@@ -31,64 +31,41 @@ run_tests() {
 
   header "Running test flavor $flavor"
 
-  autoreconf -fsi
+  ./.ci/build.sh "$@"
 
-  DISTCHECK_CONFIGURE_FLAGS=$(sh .ci/conf.sh "$@")
-  export DISTCHECK_CONFIGURE_FLAGS
-
-  # shellcheck disable=SC2086
-  ./configure $DISTCHECK_CONFIGURE_FLAGS
-
-  make -j"$(nproc)" all extra
-
-  if [ "$(uname -s)" = Linux ]; then
-    cmd=distcheck
-  else
-    cmd=check
+  if [ "${HOST:-}" = mingw ]; then
+    echo >&2 "Integration tests cannot run under wine, skipping"
+    return 0
   fi
 
   code=0
-  make $cmd -j2 VERBOSE=1 || code=$?
+  meson test -C build --verbose || code=$?
 
-  sudo tar -c -z -f "/tmp/logs/tests.$flavor.tar.gz" test/ sanitizer/
+  sudo tar -c -z -f "/tmp/logs/tests.$flavor.tar.gz" build/ sanitizer/
 
   return $code
 }
 
 case "$(uname -s)" in
-Linux)
-  if [ -n "${HOST:-}" ]; then
-    # Needed for cross-compilation for 32-bit targets.
-    export CPPFLAGS="${CPPFLAGS:-} -D_FILE_OFFSET_BITS=64"
-  fi
-  ;;
-
-MINGW*)
-  # No-op.
-  sudo() { "$@"; }
-  ;;
-
-Darwin)
-  nproc() { sysctl -n hw.ncpu; }
-  gcrypt=$(brew --prefix libgcrypt)
-  openssl=$(brew --prefix openssl)
-  export CPPFLAGS="${CPPFLAGS:-} -I/usr/local/include -I$gcrypt/include -I$openssl/include -I$gcrypt/include"
-  ;;
+MINGW* | Darwin) sudo() { "$@"; } ;;
 esac
 
-case "$1" in
+flavor=$1
+shift
+
+case "$flavor" in
 default)
-  run_tests default
+  run_tests default "$@"
   ;;
 nolegacy)
-  run_tests nolegacy --disable-legacy-protocol
+  run_tests nolegacy -Dcrypto=nolegacy "$@"
   ;;
 gcrypt)
-  run_tests gcrypt --with-libgcrypt
+  run_tests gcrypt -Dcrypto=gcrypt "$@"
   ;;
 openssl3)
   if [ -d /opt/ssl3 ]; then
-    run_tests openssl3 --with-openssl=/opt/ssl3 --with-openssl-include=/opt/ssl3/include --with-openssl-lib=/opt/ssl3/lib64
+    run_tests openssl3 -Dpkg_config_path=/opt/ssl3/lib64/pkgconfig "$@"
   else
     echo >&2 "OpenSSL 3 not installed, skipping test"
   fi
index d196975..36700a2 100755 (executable)
@@ -2,6 +2,8 @@
 
 set -eu
 
+./.ci/build.sh "$@"
+
 # Which paths to ignore.
 paths='src/solaris src/mingw src/gcrypt'
 
@@ -26,11 +28,6 @@ for path in $paths; do
   path_filters=" $path_filters ! ( -path $path -prune ) "
 done
 
-if ! [ -f compile_commands.json ]; then
-  make clean
-  compiledb make all extra
-fi
-
 echo >&2 "Running clang-tidy without $paths"
 
 # This is fine, our paths are relative and do not contain any whitespace.
@@ -38,4 +35,4 @@ echo >&2 "Running clang-tidy without $paths"
 find src \
   $path_filters \
   -name '*.c' \
-  -exec clang-tidy --header-filter='.*' '{}' +
+  -exec clang-tidy -p build --header-filter='.*' '{}' +
index 65f46eb..a4b3d9d 100755 (executable)
@@ -3,20 +3,15 @@
 set -euo pipefail
 
 test -n "$CC"
-export CFLAGS="${CFLAGS:-} -Werror"
 
 result=0
 
 check_warnings() {
   git clean -dfx
-
-  autoreconf -fsi
-  # shellcheck disable=SC2046
-  ./configure $(sh .ci/conf.sh)
-  make -j"$(nproc)" all extra || result=$?
+  ./.ci/build.sh -Dwerror=true "$@" || result=$?
 }
 
 check_warnings
-check_warnings --disable-legacy-protocol
+check_warnings -Dcrypto=nolegacy
 
 exit $result
index 4a56007..d0a89c1 100644 (file)
@@ -1,2 +1,3 @@
 Checks: '-*,bugprone-narrowing-conversions'
+HeaderFilterRegex: '.*'
 WarningsAsErrors: '*'
index b5392ff..0dd0de2 100644 (file)
@@ -17,6 +17,7 @@ jobs:
         arch:
           - armhf
           - mipsel
+          - mingw
 
     container:
       image: debian:bullseye
@@ -30,10 +31,7 @@ jobs:
         run: HOST=${{ matrix.arch }} sh .ci/deps.sh
 
       - name: Prepare the system
-        run: |
-          sh .ci/test/prepare.sh
-          update-binfmts --enable
-          rm -f /dev/net/tun
+        run: HOST=${{ matrix.arch }} sh .ci/test/prepare.sh
 
       - name: Run tests with default settings
         run: sudo -u build CI=1 HOST=${{ matrix.arch }} sh .ci/test/run.sh default
@@ -76,17 +74,12 @@ jobs:
       - name: Install deps
         run: sudo sh .ci/deps.sh
 
-      - name: Configure and compile
-        run: |
-          autoreconf -fsi
-          ./configure $(sh .ci/conf.sh)
-
       - name: Run clang-tidy
         run: sh .ci/tidy/run.sh
         if: always()
 
       - name: Check code formatting
-        run: "! astyle -r --options=.astylerc --dry-run --formatted '*.c' '*.h' | grep '^Formatted'"
+        run: "! astyle --exclude=build -r --options=.astylerc --dry-run --formatted '*.c' '*.h' | grep '^Formatted'"
         if: always()
 
       - name: Check scripts formatting
@@ -104,13 +97,13 @@ jobs:
       - name: Check warnings (gcc)
         run: bash .ci/warn/run.sh
         env:
-          CC: gcc
+          CC: gcc-10
         if: always()
 
       - name: Check warnings (clang)
         run: bash .ci/warn/run.sh
         env:
-          CC: clang
+          CC: clang-12
         if: always()
 
   sanitizer:
@@ -291,8 +284,8 @@ jobs:
           # https://packages.msys2.org/package/
           install: >-
             base-devel
-            autoconf-wrapper
-            automake-wrapper
+            mingw-w64-x86_64-meson
+            mingw-w64-x86_64-pkgconf
             mingw-w64-x86_64-gcc
             mingw-w64-x86_64-openssl
             mingw-w64-x86_64-libgcrypt