-
Notifications
You must be signed in to change notification settings - Fork 16
/
build-tun2tor.sh
executable file
·48 lines (36 loc) · 1.67 KB
/
build-tun2tor.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
#!/usr/bin/env sh
# Get absolute path to this script.
DIR=$(cd `dirname $0` && pwd)
FILENAME="libtun2tor.a"
# See https://github.com/TimNN/cargo-lipo/issues/41#issuecomment-774793892
if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then
# Assume we're in Xcode, which means we're probably cross-compiling.
# In this case, we need to add an extra library search path for build scripts and proc-macros,
# which run on the host instead of the target.
# (macOS Big Sur does not have linkable libraries in /usr/lib/.)
export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}"
# The $PATH used by Xcode likely won't contain Cargo, fix that.
# This assumes a default `rustup` setup.
export PATH="${HOME}/.cargo/bin:{$PATH}"
# Delete old build, if any.
rm -f "${BUILT_PRODUCTS_DIR}/${FILENAME}"
# --xcode-integ determines --release and --targets from Xcode's env vars.
# Depending your setup, specify the rustup toolchain explicitly.
cargo lipo --xcode-integ --manifest-path "${DIR}/Cargo.toml"
# cargo-lipo drops result in different folder, depending on the config.
if [[ $CONFIGURATION = "Debug" ]]; then
SOURCE="$DIR/target/universal/debug/${FILENAME}"
else
SOURCE="$DIR/target/universal/release/${FILENAME}"
fi
# Copy compiled library to BUILT_PRODUCTS_DIR. Use that in your Xcode project
# settings under General -> Frameworks and Libraries.
# You will also need to have tun2tor.h somewhere in your search paths!
# (Easiest way: have it referenced in your project files list.)
if [ -e "${SOURCE}" ]; then
cp -a "${SOURCE}" "${BUILT_PRODUCTS_DIR}"
fi
else
# Direct command line usage.
cargo lipo --manifest-path $DIR/Cargo.toml
fi