diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-08-14 09:29:38 +0200 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-08-14 10:51:41 +0200 |
| commit | c487ae59daf6d924cf853e7829ddb95d931772d9 (patch) | |
| tree | c5bad5978a75aedf9316bee61a6141875dddcdfa | |
| parent | ce5b989473dafef31adf51105041381227ab0ff3 (diff) | |
| download | mullvadvpn-c487ae59daf6d924cf853e7829ddb95d931772d9.tar.xz mullvadvpn-c487ae59daf6d924cf853e7829ddb95d931772d9.zip | |
Add script for building test framework artifacts
Pass `TEST_MANAGER_STATIC` when building the `test-manager` crate to
have it link statically against `libpcap`. This is optional, but
building the with the provided container will produce a statically
linked binary.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | test/scripts/Dockerfile | 3 | ||||
| -rwxr-xr-x | test/scripts/build-manager.sh | 27 | ||||
| -rwxr-xr-x | test/scripts/build.sh | 24 | ||||
| -rw-r--r-- | test/test-manager/build.rs | 10 |
5 files changed, 62 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore index 569d6ca706..7b5284edfe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /target/ /build/ /dist +/test/dist .idea/ .DS_Store *.log diff --git a/test/scripts/Dockerfile b/test/scripts/Dockerfile index bf2a08e90e..4501dd279e 100644 --- a/test/scripts/Dockerfile +++ b/test/scripts/Dockerfile @@ -3,7 +3,8 @@ FROM $IMAGE ENV OPENSSL_STATIC=1 \ OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu \ - OPENSSL_INCLUDE_DIR=/usr/include/openssl + OPENSSL_INCLUDE_DIR=/usr/include/openssl \ + TEST_MANAGER_STATIC=1 RUN rustup target add x86_64-pc-windows-gnu diff --git a/test/scripts/build-manager.sh b/test/scripts/build-manager.sh new file mode 100755 index 0000000000..60cf5da98c --- /dev/null +++ b/test/scripts/build-manager.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -eu + +# Build `test-manager` +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +TEST_FRAMEWORK_ROOT="$SCRIPT_DIR/.." +REPO_DIR="$TEST_FRAMEWORK_ROOT/.." + +# shellcheck disable=SC1091 +source "$REPO_DIR/scripts/utils/log" + +build_linux() { + cd "$TEST_FRAMEWORK_ROOT" + # Build the test manager + cargo build -p test-manager --release +} + +case ${1-:""} in + linux) + build_linux + shift + ;; + *) + log_error "Invalid platform. Specify a valid platform as first argument" + exit 1 +esac diff --git a/test/scripts/build.sh b/test/scripts/build.sh new file mode 100755 index 0000000000..be06dd8eb9 --- /dev/null +++ b/test/scripts/build.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -eu + +# Build distributable binaries for the test framework. +# TODO: Support macOS + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +TEST_FRAMEWORK_ROOT="$SCRIPT_DIR/.." + +# Build +build_linux() { + mkdir -p "$TEST_FRAMEWORK_ROOT/dist" + # Build the test manager + "$SCRIPT_DIR/build-manager.sh" linux + cp "$TEST_FRAMEWORK_ROOT/target/release/test-manager" "$TEST_FRAMEWORK_ROOT/dist/" + + # Build the test runner + "$SCRIPT_DIR/build-runner.sh" linux + cp "$TEST_FRAMEWORK_ROOT/target/x86_64-unknown-linux-gnu/release/test-runner" "$TEST_FRAMEWORK_ROOT/dist/" + cp "$TEST_FRAMEWORK_ROOT/target/x86_64-unknown-linux-gnu/release/connection-checker" "$TEST_FRAMEWORK_ROOT/dist/" +} + +build_linux diff --git a/test/test-manager/build.rs b/test/test-manager/build.rs index da8241b224..45ceffea0f 100644 --- a/test/test-manager/build.rs +++ b/test/test-manager/build.rs @@ -1,7 +1,13 @@ +use std::env::var; + fn main() { // Rebuild if SSH provision script changes println!("cargo::rerun-if-changed=../scripts/ssh-setup.sh"); - println!("cargo::rustc-link-search=native=/usr/lib/x86_64-linux-gnu"); - println!("cargo::rustc-link-lib=static=pcap"); + let link_statically = var("TEST_MANAGER_STATIC").is_ok_and(|x| x != "0"); + + if link_statically { + println!("cargo::rustc-link-search=native=/usr/lib/x86_64-linux-gnu"); + println!("cargo::rustc-link-lib=static=pcap"); + } } |
