forked from openwallet-foundation/askar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·94 lines (83 loc) · 2.8 KB
/
build.sh
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
#!/bin/sh
# NOTE:
# MacOS universal build currently requires MacOS 11 (Big Sur) for the appropriate SDK,
# and `sudo xcode-select --install` must be run to install the command line utilities.
# Rust's `beta` channel must be installed because aarch64 is still a tier-2 target:
# `rustup toolchain install beta`.
# The build command becomes `BUILD_TARGET=apple-darwin BUILD_TOOLCHAIN=beta ./build.sh`
RUSTUP=${RUSTUP:-`command -v rustup`}
PROJECT=aries-askar
if [ ! -x "$RUSTUP" ]; then
echo "rustup command not found: it can be obtained from https://rustup.rs/"
exit 1
fi
TOOLCHAIN=`$RUSTUP default`
TARGET="${BUILD_TARGET-}"
if [ -z "$BUILD_TOOLCHAIN" ]; then
BUILD_TOOLCHAIN=${TOOLCHAIN%%-*}
if [ -z "$BUILD_TOOLCHAIN" ]; then
echo "Error: Could not determine default Rust toolchain"
exit 1
fi
fi
MACOS_UNIVERSAL_TARGETS="aarch64-apple-darwin x86_64-apple-darwin"
# Fail on any execution errors
set -e
if [ "$TARGET" = "apple-darwin" ]; then
# MacOS universal build
INSTALLED_TARGETS=`$RUSTUP +$BUILD_TOOLCHAIN target list --installed`
# Install target(s) as needed
echo "Checking install targets for MacOS universal build .."
for target in $MACOS_UNIVERSAL_TARGETS; do
if ! `echo "$INSTALLED_TARGETS" | grep -q $target`; then
$RUSTUP +$BUILD_TOOLCHAIN target add $target
fi
done
elif [ -z "$TARGET" ]; then
case "$TOOLCHAIN" in
*apple-darwin*)
# Check if the required targets for a universal build are installed
INSTALLED_TARGETS=`$RUSTUP +$BUILD_TOOLCHAIN target list --installed`
TARGET="apple-darwin"
for target in $MACOS_UNIVERSAL_TARGETS; do
if ! `echo "$INSTALLED_TARGETS" | grep -q $target`; then
TARGET=
break
fi
done
if [ "$TARGET" = "apple-darwin" ]; then
echo "Automatically enabled MacOS universal build"
else
echo "Universal MacOS build not enabled"
fi
esac
fi
if [ "$TARGET" = "apple-darwin" ]; then
MAJOR_VER=`sw_vers | grep ProductVersion | cut -f 2 | cut -f 1 -d .`
if [ "$MAJOR_VER" -lt 11 ]; then
echo "MacOS universal build requires OS 11 (Big Sur) or newer"
TARGET=
fi
fi
if [ "$TARGET" = "apple-darwin" ]; then
# Build both targets and combine them into a universal library with `lipo`
TARGET_LIBS=
for target in $MACOS_UNIVERSAL_TARGETS; do
echo "Building $PROJECT for toolchain '$BUILD_TOOLCHAIN', target '$target'.."
$RUSTUP run $BUILD_TOOLCHAIN cargo build --release --target $target
TARGET_LIBS="./target/$target/release/libaries_askar.dylib $TARGET_LIBS"
done
mkdir -p ./target/release
OUTPUT="./target/release/libaries_askar.dylib"
echo "Combining targets into universal library"
lipo -create -output $OUTPUT $TARGET_LIBS
else
# Build normal target
echo "Building $PROJECT for toolchain '$BUILD_TOOLCHAIN'.."
CMD="$RUSTUP run $BUILD_TOOLCHAIN cargo build --release"
if [ -n "$TARGET" ]; then
$CMD --target "$TARGET"
else
$CMD
fi
fi