diff --git a/native/package.json b/native/package.json --- a/native/package.json +++ b/native/package.json @@ -19,7 +19,7 @@ "logfirebase": "adb shell logcat | grep -E -i 'FIRMessagingModule|firebase'", "redux-devtools": "redux-devtools --port=8043 --open", "codegen-jsi": "flow && babel codegen/src/ -d codegen/dist/ && node codegen/dist", - "react-native": "PATH=/usr/bin:/bin:\"$PATH\" react-native", + "react-native": "./scripts/run-react-native.sh", "expo": "PATH=/usr/bin:/bin:\"$PATH\" expo", "xcodebuild": "cd ios && PATH=/usr/bin:/bin:\"$PATH\" xcodebuild", "update-version": "node scripts/update-mobile-version.mjs", diff --git a/native/scripts/run-react-native.sh b/native/scripts/run-react-native.sh new file mode 100755 --- /dev/null +++ b/native/scripts/run-react-native.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# This script is necessary for running react-native CLI commands from the Nix environment +# We need it because the Nix environment overrides a bunch of compiler env vars +# Our Rust build has dependencies that assume the standard macOS compiler environment + +set -euo pipefail + +export CPATH= +export CPLUS_INCLUDE_PATH= +export OBJC_INCLUDE_PATH= + +CC=$(/usr/bin/xcrun --sdk macosx --find clang) +CXX=$(/usr/bin/xcrun --sdk macosx --find clang++) +export CC +export CXX + +SDKROOT=$(/usr/bin/xcrun --sdk macosx --show-sdk-path) +export SDKROOT +export CFLAGS="-isysroot $SDKROOT" +export RUSTFLAGS="-C link-arg=-isysroot -C link-arg=$SDKROOT -C link-arg=-Wl,-search_paths_first" + +DEVELOPER_DIR=$(/usr/bin/xcode-select -p) +DEVELOPER_BIN="$DEVELOPER_DIR/usr/bin" +TOOLCHAIN_DIR="$DEVELOPER_DIR/Toolchains/XcodeDefault.xctoolchain" +TOOLCHAIN_BIN="$TOOLCHAIN_DIR/usr/bin" +TOOLCHAIN_INCLUDE="$TOOLCHAIN_DIR/usr/include/c++/v1" + +export PATH="$TOOLCHAIN_BIN:$DEVELOPER_BIN:/usr/bin:/bin:$PATH" +export CXXFLAGS="-isysroot $SDKROOT -stdlib=libc++ -isystem $TOOLCHAIN_INCLUDE" + +exec react-native "$@"