Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions ios/Gem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@
isa = PBXNativeTarget;
buildConfigurationList = C30952D5299C39D80004C0F9 /* Build configuration list for PBXNativeTarget "Gem" */;
buildPhases = (
D8GEMST0NE2025040800001 /* Build Gemstone */,
C30952AC299C39D70004C0F9 /* Sources */,
C30952AD299C39D70004C0F9 /* Frameworks */,
C30952AE299C39D70004C0F9 /* Resources */,
Expand Down Expand Up @@ -1122,6 +1123,24 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
D8GEMST0NE2025040800001 /* Build Gemstone */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Build Gemstone";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/bash;
shellScript = "\"$SRCROOT/scripts/generate-stone.sh\"\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
C30952AC299C39D70004C0F9 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -1372,7 +1391,7 @@
EAGER_LINKING = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -1451,7 +1470,7 @@
EAGER_LINKING = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down
6 changes: 2 additions & 4 deletions ios/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ generate-swiftgen:
@echo "==> SwiftGen assets and Localizable.strings"
@swiftgen config run --quiet

export BUILD_MODE := env_var_or_default("BUILD_MODE","")

generate-stone:
@./scripts/generate-stone.sh $BUILD_MODE
generate-stone BUILD_MODE="":
@./scripts/generate-stone.sh {{BUILD_MODE}}

bump TARGET="patch":
@cd .. && just bump {{TARGET}}
68 changes: 49 additions & 19 deletions ios/scripts/generate-stone.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
#!/usr/bin/env bash
#
# Build the Gemstone XCFramework, skipping when Rust sources are unchanged.
# Usage: generate-stone.sh [release]

set -e
set -euo pipefail

CURRENT_DIR=$(dirname `realpath $0`)
PROJ_PATH=${CURRENT_DIR}/../Gem.xcodeproj/project.pbxproj
STONE_DIR=${CURRENT_DIR}/../../core/gemstone
PACKAGES_DIR=${CURRENT_DIR}/../Packages/Gemstone
BUILD_MODE=$1
export PATH="$HOME/.cargo/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"

CURRENT_DIR=$(dirname "$(realpath "$0")")
IOS_DIR="$CURRENT_DIR/.."
PROJ_PATH="$IOS_DIR/Gem.xcodeproj/project.pbxproj"
CORE_DIR="$IOS_DIR/../core"
STONE_DIR="$CORE_DIR/gemstone"
PACKAGES_DIR="$IOS_DIR/Packages/Gemstone"
XCFRAMEWORK="$PACKAGES_DIR/Sources/GemstoneFFI.xcframework"

BUILD_MODE="${1:-${BUILD_MODE:-}}"
if [ -z "$BUILD_MODE" ] && [ "${CONFIGURATION:-Debug}" = "Release" ]; then
BUILD_MODE="release"
fi

compute_hash() {
{
git -C "$CORE_DIR" rev-parse HEAD
git -C "$CORE_DIR" diff
git -C "$CORE_DIR" ls-files --others --exclude-standard -z | \
(cd "$CORE_DIR" && xargs -0 stat -f '%m %z %N' 2>/dev/null)
} | shasum -a 256 | cut -d' ' -f1
}

CACHE_DIR="$IOS_DIR/build/.gemstone-cache"
mkdir -p "$CACHE_DIR"
HASH_FILE="$CACHE_DIR/sources-${BUILD_MODE:-debug}.hash"

current_hash=$(compute_hash)

if [ -f "$HASH_FILE" ] && [ -d "$XCFRAMEWORK" ]; then
cached_hash=$(cat "$HASH_FILE")
if [ "$current_hash" = "$cached_hash" ]; then
echo "note: Gemstone sources unchanged (${BUILD_MODE:-debug}) — skipping rebuild"
exit 0
fi
fi

read_deployment_target() {
echo -n $(/usr/libexec/PlistBuddy -c "Print" "$PROJ_PATH" | grep IPHONEOS_DEPLOYMENT_TARGET | awk -F ' = ' '{print $2}' | uniq)
}

generate() {
if [ -z $BUILD_MODE ]; then
echo "Build Gemstone debug"
else
echo "Build Gemstone $BUILD_MODE"
fi
echo "note: Gemstone sources changed — rebuilding XCFramework (${BUILD_MODE:-debug})..."

pushd ${STONE_DIR} > /dev/null
BUILD_MODE=$BUILD_MODE IPHONEOS_DEPLOYMENT_TARGET=$(read_deployment_target) just build-ios
rm -rf ${PACKAGES_DIR}
cp -Rf target/spm ${PACKAGES_DIR}
pushd "$STONE_DIR" > /dev/null
BUILD_MODE=$BUILD_MODE IPHONEOS_DEPLOYMENT_TARGET=$(read_deployment_target) just build-ios
rm -rf "$PACKAGES_DIR"
cp -Rf target/spm "$PACKAGES_DIR"
popd > /dev/null

popd > /dev/null
}
echo "$current_hash" > "$HASH_FILE"

generate
echo "note: Gemstone XCFramework rebuilt successfully (${BUILD_MODE:-debug})"