forked from surpher/PactSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_test_linux
executable file
·104 lines (84 loc) · 3.17 KB
/
build_test_linux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -euo pipefail
# ### Pre-requisites:
#
# `pact-reference` repo and `PactSwift` repo are on the same folder level
#
# ### Usage:
# ./Support/build_rust_dependencies
#
# In order to minimise the built binary size update $LIBPACT_FFI_DI/Cargo.toml and append the following:
#
# [lib]
# crate-type = ["staticlib"]
#
# [profile.release]
# opt-level = 'z'
# lto = true
# panic = 'abort'
#
#######################
PRODUCT_NAME="PactSwift"
WORKSPACE=${GITHUB_WORKSPACE:-$PWD}
LIBPACT_FFI_VERSION_TAG="libpact_ffi-v0.3.5"
LIBPACT_FFI_DIR="${WORKSPACE}/pact-reference/rust/pact_ffi"
LIBPACT_PRODUCT_DIR="${WORKSPACE}/pact-reference/rust/target/debug"
CI=${CI:-"false"}
PACT_FOUNDATION_REPO="https://github.com/pact-foundation/pact-reference.git"
#######################
# Pre-requisite #
#######################
if [ ! -d "$PWD/$PRODUCT_NAME.xcodeproj" ]
then
echo "🚨 Run this from the same folder where your '$PRODUCT_NAME.xcodeproj' lives."
echo "⚠️ You are runing it in $PWD"
exit 1
fi
echo "ℹ️ Cloning ${PACT_FOUNDATION_REPO}"
git submodule add $PACT_FOUNDATION_REPO
git submodule update --init
echo "ℹ️ Changing location to ${LIBPACT_FFI_DIR}"
cd $LIBPACT_FFI_DIR
echo "ℹ️ Checking out ${LIBPACT_FFI_VERSION_TAG}"
git fetch --all --tags
git checkout tags/$LIBPACT_FFI_VERSION_TAG
#######################
# Setup #
#######################
# Validate dependencies
echo "👮♀️ Checking if Rust is installed..."
if which cargo >/dev/null; then
echo "👍 cargo installed"
elif command -v ~/.cargo/bin/cargo &> /dev/null; then
echo "👍 cargo installed in ~/.cargo/bin/"
else
echo "🚨 Rust/Cargo not installed"
echo "ERROR: cargo is required and is was found on this machine. See https://www.rust-lang.org/tools/install"
exit 1
fi
# Set the nightly toolchain
echo "⚠️ Installing a nightly toolchain..."
rustup install nightly
rustup toolchain install nightly
##############################################
# Build libpact_ffi libraries #
##############################################
# Using debug build flag (or not providing it), otherwise libpact_ffi.so must be moved into /usr/local/lib/
echo "🏗 Building libpact_ffi for current platform (debug build)"
cargo build
echo "✅ libpact_ffi built"
echo "ℹ️ Setting LD_LIBRARY_PATH to include $LIBPACT_PRODUCT_DIR"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH-}:$LIBPACT_PRODUCT_DIR"
#######################
# Cleanup #
#######################
echo "ℹ️ Changing directory back to ${WORKSPACE}"
cd ${WORKSPACE}
##############################################################################################################
# Run Swift buld and test #
# https://github.com/apple/swift-package-manager/blob/main/Documentation/Usage.md#requiring-system-libraries #
##############################################################################################################
echo "ℹ️ Running swift build:"
swift build -Xlinker -L$LIBPACT_PRODUCT_DIR
echo "ℹ️ Running swift test with -Xlinker -L$LIBPACT_PRODUCT_DIR"
swift test -Xlinker -L$LIBPACT_PRODUCT_DIR