forked from xi-editor/xi-mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-rust-xcode.sh
83 lines (70 loc) · 2.67 KB
/
build-rust-xcode.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
#!/bin/bash
# When building from Xcode we want to ensure that `cargo` is in PATH.
# as a convenience, add the default cargo install location
export PATH="$PATH:${HOME}/.cargo/bin"
# Users can optionally set cargo path in xi-mac/.env
if [[ -f "${SRCROOT}/.env" ]]; then
source "${SRCROOT}/.env"
if ! [[ -z "$CARGO_PATH" ]]; then
export PATH="$CARGO_PATH:$PATH"
else
echo "warning: ${SRCROOT}/.env file found, but CARGO_PATH not set."
fi
fi
if ! [[ -x "$(command -v cargo)" ]]; then
echo 'error: Unable to find cargo command. If cargo is not installed visit rustup.rs, otherwise set CARGO_PATH in xi-mac/.env' >&2
exit 127
fi
set -e
function build_target () {
TARGET_NAME="$1"
CARGO_PROJECT_FLAG="$2"
cd "${SRCROOT}/xi-editor/rust"
if [[ ${ACTION:-build} = "build" ]]; then
if [[ $PLATFORM_NAME = "" ]]; then
# default for building with xcodebuild
PLATFORM_NAME="macosx"
fi
if [[ $PLATFORM_NAME = "macosx" ]]; then
RUST_TARGET_OS="darwin"
else
RUST_TARGET_OS="ios"
fi
for ARCH in $ARCHS
do
if [[ $(lipo -info "${BUILT_PRODUCTS_DIR}/${TARGET_NAME}" 2>&1) != *"${ARCH}"* ]]; then
rm -f "${BUILT_PRODUCTS_DIR}/${TARGET_NAME}"
fi
done
if [[ $CONFIGURATION = "Debug" ]]; then
RUST_CONFIGURATION="debug"
RUST_CONFIGURATION_FLAG=""
else
RUST_CONFIGURATION="release"
RUST_CONFIGURATION_FLAG="--release"
fi
EXECUTABLES=()
for ARCH in $ARCHS
do
RUST_ARCH=$ARCH
if [[ $RUST_ARCH = "arm64" ]]; then
RUST_ARCH="aarch64"
fi
cargo build $RUST_CONFIGURATION_FLAG $CARGO_PROJECT_FLAG --target "${RUST_ARCH}-apple-${RUST_TARGET_OS}"
EXECUTABLES+=("target/${RUST_ARCH}-apple-${RUST_TARGET_OS}/${RUST_CONFIGURATION}/${TARGET_NAME}")
done
mkdir -p "${BUILT_PRODUCTS_DIR}"
xcrun --sdk $PLATFORM_NAME lipo -create "${EXECUTABLES[@]}" -output "${BUILT_PRODUCTS_DIR}/${TARGET_NAME}"
elif [[ $ACTION = "clean" ]]; then
cargo clean
rm -f "${BUILT_PRODUCTS_DIR}/${TARGET_NAME}"
fi
}
build_target xi-core ""
build_target xi-syntect-plugin "-p xi-syntect-plugin"
# move syntect plugin into plugins dir
mkdir -p "${BUILT_PRODUCTS_DIR}/plugins/syntect/bin"
mv "${BUILT_PRODUCTS_DIR}/xi-syntect-plugin" "${BUILT_PRODUCTS_DIR}/plugins/syntect/bin/"
cp "${SRCROOT}/xi-editor/rust/syntect-plugin/manifest.toml" "${BUILT_PRODUCTS_DIR}/plugins/syntect/"
# workaround for https://github.com/travis-ci/travis-ci/issues/6522
set +e