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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
_Headers
.DS_Store

AG/*/Sources/Modules/AttributeGraph.swiftmodule/template*.swiftinterface
GF/*/Sources/Modules/Gestures.swiftmodule/template*.swiftinterface

# Tuist generated (from Example/)
DarwinPrivateFrameworks.xcodeproj
Derived/

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

2 changes: 2 additions & 0 deletions AG/DeviceSwiftShims/Runtime/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extension Metadata: Swift.Hashable, Swift.CustomStringConvertible {
}
}

#if ATTRIBUTEGRAPH_RELEASE_2024
extension Signature: Swift.Equatable {
public static func == (_ lhs: Signature, _ rhs: Signature) -> Bool {
return lhs.bytes.0 == rhs.bytes.0 && lhs.bytes.1 == rhs.bytes.1
Expand All @@ -73,3 +74,4 @@ extension Signature: Swift.Equatable {
&& lhs.bytes.18 == rhs.bytes.18 && lhs.bytes.19 == rhs.bytes.19
}
}
#endif
47 changes: 41 additions & 6 deletions AG/generate_swiftinterface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,28 @@ PACKAGE_DIR="$(dirname "${SCRIPT_DIR}")"
VERSION=${DARWINPRIVATEFRAMEWORKS_TARGET_RELEASE:-2024}
FRAMEWORK_ROOT="${SCRIPT_DIR}/${VERSION}"
SHIMS_DIR="${SCRIPT_DIR}/DeviceSwiftShims"
TEMPLATE_PATH="${FRAMEWORK_ROOT}/Sources/Modules/AttributeGraph.swiftmodule/template.swiftinterface"
TEMPLATE_PATH="${FRAMEWORK_ROOT}/Sources/Modules/AttributeGraph.swiftmodule/template-${VERSION}.swiftinterface"
SWIFTPM_SCRATCH_PATH=$(mktemp -d)
SWIFTPM_CACHE_PATH="${PACKAGE_DIR}/.build"
SWIFTPM_BUILD_LOG=""
SWIFTC_LOG=""
TMPDIR_WORK=""

cleanup() {
if [ -n "${SWIFTPM_SCRATCH_PATH}" ]; then
rm -rf "${SWIFTPM_SCRATCH_PATH}"
fi
if [ -n "${SWIFTPM_BUILD_LOG}" ]; then
rm -f "${SWIFTPM_BUILD_LOG}"
fi
if [ -n "${SWIFTC_LOG}" ]; then
rm -f "${SWIFTC_LOG}"
fi
if [ -n "${TMPDIR_WORK}" ]; then
rm -rf "${TMPDIR_WORK}"
fi
}
trap cleanup EXIT

# Verify Swift compiler version matches the expected version for this framework
EXPECTED_SWIFT_VERSION="6.1" # 2024 -> 6.1, 2025 -> 6.2
Expand All @@ -28,46 +49,60 @@ if [ "${SWIFT_VERSION}" != "${EXPECTED_SWIFT_VERSION}" ]; then
fi

# Build package dependencies via SPM
swift build --package-path "${PACKAGE_DIR}" --target _AttributeGraphDeviceSwiftShims 2>/dev/null
if [ $? -ne 0 ]; then
# The command plugin already holds the package build lock. Use a separate
# scratch path for this nested build so update-xcframeworks does not deadlock.
SWIFTPM_BUILD_LOG=$(mktemp)
mkdir -p "${SWIFTPM_CACHE_PATH}"
if ! swift build --disable-sandbox --package-path "${PACKAGE_DIR}" --cache-path "${SWIFTPM_CACHE_PATH}" --scratch-path "${SWIFTPM_SCRATCH_PATH}" --target _AttributeGraphDeviceSwiftShims 2>"${SWIFTPM_BUILD_LOG}"; then
cat "${SWIFTPM_BUILD_LOG}" >&2
echo "Error: failed to build package dependencies"
exit 1
fi

# Locate the SPM modules directory for import search paths
BUILD_BIN_PATH=$(swift build --package-path "${PACKAGE_DIR}" --show-bin-path 2>/dev/null)
if ! BUILD_BIN_PATH=$(swift build --disable-sandbox --package-path "${PACKAGE_DIR}" --cache-path "${SWIFTPM_CACHE_PATH}" --scratch-path "${SWIFTPM_SCRATCH_PATH}" --show-bin-path 2>"${SWIFTPM_BUILD_LOG}"); then
cat "${SWIFTPM_BUILD_LOG}" >&2
echo "Error: failed to locate package build directory"
exit 1
fi
MODULES_DIR="${BUILD_BIN_PATH}/Modules"

TMPDIR_WORK=$(mktemp -d)
trap "rm -rf ${TMPDIR_WORK}" EXIT
CLANG_MODULE_CACHE="${TMPDIR_WORK}/ModuleCache"
mkdir -p "${CLANG_MODULE_CACHE}"

GENERATED="${TMPDIR_WORK}/generated.swiftinterface"

# Use macOS SDK to match the host-built SPM modules
MACOS_SDK_VERSION=$(xcrun --sdk macosx --show-sdk-version)

# Compile DeviceSwiftShims against the macOS xcframework to emit a swiftinterface
SWIFTC_LOG=$(mktemp)
xcrun --sdk macosx swiftc \
-emit-module-interface-path "${GENERATED}" \
-emit-module-path "${TMPDIR_WORK}/module.swiftmodule" \
-module-name AttributeGraph \
-enable-library-evolution \
-swift-version 5 \
-Osize \
-D "ATTRIBUTEGRAPH_RELEASE_${VERSION}" \
-enable-upcoming-feature InternalImportsByDefault \
-enable-experimental-feature Extern \
-target "arm64-apple-macos${MACOS_SDK_VERSION}" \
-module-cache-path "${CLANG_MODULE_CACHE}" \
-F "${FRAMEWORK_ROOT}/AttributeGraph.xcframework/macos-arm64e-arm64-x86_64/" \
-I "${MODULES_DIR}" \
$(find "${SHIMS_DIR}" -name '*.swift') \
2>/dev/null
2>"${SWIFTC_LOG}"

if [ ! -f "${GENERATED}" ]; then
cat "${SWIFTC_LOG}" >&2
echo "Error: failed to generate swiftinterface"
exit 1
fi

# Strip the compiler header comments (update.sh generates per-platform headers)
mkdir -p "$(dirname "${TEMPLATE_PATH}")"
sed -e '/^\/\/ swift-/d' \
"${GENERATED}" > "${TEMPLATE_PATH}"

Expand Down
39 changes: 30 additions & 9 deletions AG/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ filepath() {
}

VERSION=${DARWINPRIVATEFRAMEWORKS_TARGET_RELEASE:-2024}
FRAMEWORK_ROOT="$(dirname $(filepath $0))/$VERSION"
SCRIPT_DIR="$(dirname "$(filepath "$0")")"
FRAMEWORK_ROOT="${SCRIPT_DIR}/${VERSION}"
TEMPLATE_PATH="${FRAMEWORK_ROOT}/Sources/Modules/AttributeGraph.swiftmodule/template-${VERSION}.swiftinterface"

# Version mapping logic
if [ "$VERSION" = "2021" ]; then
Expand Down Expand Up @@ -42,7 +44,7 @@ generate_swiftinterface() {
local name="$1".swiftinterface
local target="$2"
generate_swiftinterface_header $target > $name
cat template.swiftinterface >> $name
cat "${TEMPLATE_PATH}" >> $name
}

update_version_in_header() {
Expand All @@ -53,9 +55,6 @@ update_version_in_header() {
sed -i '' "s/#define ATTRIBUTEGRAPH_RELEASE [0-9]\{4\}/#define ATTRIBUTEGRAPH_RELEASE ${version}/g" "$file"
}

# Regenerate template.swiftinterface from DeviceSwiftShims sources
DARWINPRIVATEFRAMEWORKS_TARGET_RELEASE=${VERSION} "$(dirname "$(filepath "$0")")/generate_swiftinterface.sh"

generate_framework() {
local framework_name=$1
local arch_name=$2
Expand All @@ -75,6 +74,7 @@ generate_framework() {

update_version_in_header "${path}/Headers/AGVersion.h" "${VERSION}"

mkdir -p ${path}/Modules/${framework_name}.swiftmodule
cd ${path}/Modules/${framework_name}.swiftmodule
}

Expand Down Expand Up @@ -102,6 +102,7 @@ generate_macos_framework() {
ln -sf Versions/Current/Resources Resources
ln -sf Versions/Current/${framework_name}.tbd ${framework_name}.tbd

mkdir -p ${path}/Versions/A/Modules/${framework_name}.swiftmodule
cd ${path}/Versions/A/Modules/${framework_name}.swiftmodule
}

Expand All @@ -115,26 +116,46 @@ generate_xcframework() {

generate_xcframework $framework_name

# Regenerate template.swiftinterface from DeviceSwiftShims sources. This needs a
# bootstrap xcframework because the shims import the binary AttributeGraph target.
generate_framework $framework_name ios-arm64-x86_64-simulator

generate_framework $framework_name ios-arm64-arm64e
# iPhoneOS platform does not support links Swift API of AttributeGraph
cd ../
rm -rf ./$framework_name.swiftmodule

generate_macos_framework $framework_name macos-arm64e-arm64-x86_64

if [ -n "$XROS_VERSION" ] && [ -d "${FRAMEWORK_ROOT}/tbds/xros-arm64-x86_64-simulator" ]; then
generate_framework $framework_name xros-arm64-x86_64-simulator
fi

if ! DARWINPRIVATEFRAMEWORKS_TARGET_RELEASE=${VERSION} "${SCRIPT_DIR}/generate_swiftinterface.sh"; then
echo "Error: failed to regenerate AttributeGraph Swift interface for release ${VERSION}"
exit 1
fi

generate_framework $framework_name ios-arm64-x86_64-simulator
generate_swiftinterface x86_64-apple-ios-simulator x86_64-apple-ios${IOS_VERSION}-simulator
generate_swiftinterface arm64-apple-ios-simulator arm64-apple-ios${IOS_VERSION}-simulator
rm template.swiftinterface
rm -f template*.swiftinterface

generate_framework $framework_name ios-arm64-arm64e
# iPhoneOS platform does not support links Swift API of AttributeGraph
cd ../
rm -r ./$framework_name.swiftmodule
rm -rf ./$framework_name.swiftmodule

generate_macos_framework $framework_name macos-arm64e-arm64-x86_64
generate_swiftinterface x86_64-apple-macos x86_64-apple-macos${MACOS_VERSION}
generate_swiftinterface arm64-apple-macos arm64-apple-macos${MACOS_VERSION}
generate_swiftinterface arm64e-apple-macos arm64e-apple-macos${MACOS_VERSION}
rm template.swiftinterface
rm -f template*.swiftinterface

# Add visionOS support if available
if [ -n "$XROS_VERSION" ] && [ -d "${FRAMEWORK_ROOT}/tbds/xros-arm64-x86_64-simulator" ]; then
generate_framework $framework_name xros-arm64-x86_64-simulator
generate_swiftinterface x86_64-apple-xros-simulator x86_64-apple-xros${XROS_VERSION}-simulator
generate_swiftinterface arm64-apple-xros-simulator arm64-apple-xros${XROS_VERSION}-simulator
rm template.swiftinterface
rm -f template*.swiftinterface
fi
Loading
Loading