Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/mobile/build_rust_deps.sh
6592 views
1
#!/usr/bin/env bash
2
3
# based on https://github.com/mozilla/glean/blob/main/build-scripts/xc-universal-binary.sh
4
5
set -eux
6
7
PATH=$PATH:$HOME/.cargo/bin
8
9
PROFILE=debug
10
RELFLAG=
11
if [[ "$CONFIGURATION" != "Debug" ]]; then
12
PROFILE=release
13
RELFLAG=--release
14
fi
15
16
set -euvx
17
18
# add homebrew bin path, as it's the most commonly used package manager on macOS
19
# this is needed for cmake on apple arm processors as it's not available by default
20
export PATH="$PATH:/opt/homebrew/bin"
21
22
# Make Cargo output cache files in Xcode's directories
23
export CARGO_TARGET_DIR="$DERIVED_FILE_DIR/cargo"
24
25
# Xcode places `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`
26
# at the front of the path, with makes the build fail with `ld: library 'System' not found`, upstream issue:
27
# <https://github.com/rust-lang/rust/issues/80817>.
28
#
29
# Work around it by resetting the path, so that we use the system `cc`.
30
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
31
32
IS_SIMULATOR=0
33
if [ "${LLVM_TARGET_TRIPLE_SUFFIX-}" = "-simulator" ]; then
34
IS_SIMULATOR=1
35
fi
36
37
EXECUTABLES=
38
for arch in $ARCHS; do
39
case "$arch" in
40
x86_64)
41
if [ $IS_SIMULATOR -eq 0 ]; then
42
echo "Building for x86_64, but not a simulator build. What's going on?" >&2
43
exit 2
44
fi
45
46
# Intel iOS simulator
47
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
48
TARGET=x86_64-apple-ios
49
;;
50
51
arm64)
52
if [ $IS_SIMULATOR -eq 0 ]; then
53
# Hardware iOS targets
54
TARGET=aarch64-apple-ios
55
else
56
# M1 iOS simulator
57
TARGET=aarch64-apple-ios-sim
58
fi
59
esac
60
61
cargo build $RELFLAG --target $TARGET --bin bevy_mobile_example
62
63
# Collect the executables
64
EXECUTABLES="$EXECUTABLES $DERIVED_FILE_DIR/cargo/$TARGET/$PROFILE/bevy_mobile_example"
65
done
66
67
# Combine executables, and place them at the output path excepted by Xcode
68
lipo -create -output "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" $EXECUTABLES
69
70