Skip to content
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/actions/checkout-swift-headers
with:
path: Checkouts/swift
path: .build/checkouts/swift
swift-version-major: ${{ steps.swift-version.outputs.major }}
swift-version-minor: ${{ steps.swift-version.outputs.minor }}
- name: Build
Expand All @@ -33,8 +33,8 @@ jobs:
- name: Upload XCFramework
uses: actions/upload-artifact@v6
with:
name: Compute.xcframework
path: .build/Xcode/Frameworks/Compute.xcframework
name: Compute.xcframework.zip
path: .build/Xcode/Frameworks/Compute.xcframework.zip

linux-build:
name: Linux
Expand All @@ -59,7 +59,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/actions/checkout-swift-headers
with:
path: Checkouts/swift
path: .build/checkouts/swift
swift-version-major: ${{ steps.swift-version.outputs.major }}
swift-version-minor: ${{ steps.swift-version.outputs.minor }}
- name: Build
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@

# Xcode
xcuserdata

# Dependencies
Checkouts
24 changes: 12 additions & 12 deletions Compute.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
);
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 26.2;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
"@loader_path/Frameworks",
Expand All @@ -303,7 +303,7 @@
"@loader_path/Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 26.2;
MACOSX_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
Expand All @@ -327,9 +327,9 @@
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 6.0;
SYSTEM_HEADER_SEARCH_PATHS = (
Checkouts/swift/include,
Checkouts/swift/stdlib/include,
Checkouts/swift/stdlib/public/SwiftShims,
.build/checkouts/swift/include,
.build/checkouts/swift/stdlib/include,
.build/checkouts/swift/stdlib/public/SwiftShims,
);
TARGETED_DEVICE_FAMILY = "1,2,7";
USER_HEADER_SEARCH_PATHS = (
Expand All @@ -339,7 +339,7 @@
USE_HEADERMAP = NO;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
XROS_DEPLOYMENT_TARGET = 26.2;
XROS_DEPLOYMENT_TARGET = 26.0;
};
name = Debug;
};
Expand Down Expand Up @@ -405,7 +405,7 @@
);
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 26.2;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
"@loader_path/Frameworks",
Expand All @@ -415,7 +415,7 @@
"@loader_path/Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 26.2;
MACOSX_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
Expand All @@ -437,9 +437,9 @@
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 6.0;
SYSTEM_HEADER_SEARCH_PATHS = (
Checkouts/swift/include,
Checkouts/swift/stdlib/include,
Checkouts/swift/stdlib/public/SwiftShims,
.build/checkouts/swift/include,
.build/checkouts/swift/stdlib/include,
.build/checkouts/swift/stdlib/public/SwiftShims,
);
TARGETED_DEVICE_FAMILY = "1,2,7";
USER_HEADER_SEARCH_PATHS = (
Expand All @@ -449,7 +449,7 @@
USE_HEADERMAP = NO;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
XROS_DEPLOYMENT_TARGET = 26.2;
XROS_DEPLOYMENT_TARGET = 26.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import PackageDescription

let swiftCheckoutPath = "\(Context.packageDirectory)/Checkouts/swift"
let swiftCheckoutPath = "\(Context.packageDirectory)/.build/checkouts/swift"

var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0"),
Expand Down
29 changes: 6 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,14 @@ platforms.
### Project setup

This project has a dependency on the Swift language codebase, which must be
configured manually.
cloned separately:

1. Clone the `swiftlang/swift` repository to `Checkouts/swift`.

From within the package directory:

```sh
mkdir -p Checkouts
cd Checkouts
git clone git@github.com:swiftlang/swift.git swift
```

2. Write the `CMakeConfig.h` file:

From within the Swift repository:
```sh
./Scripts/clone-swift.sh
```

```sh
cat > include/swift/Runtime/CMakeConfig.h << EOF
#ifndef SWIFT_RUNTIME_CMAKECONFIG_H
#define SWIFT_RUNTIME_CMAKECONFIG_H
#define SWIFT_VERSION_MAJOR "6"
#define SWIFT_VERSION_MINOR "2"
#endif
EOF
```
This script will clone the Swift language repository to
`.build/checkouts/swift`.

### Build as a Swift package

Expand Down
65 changes: 65 additions & 0 deletions Scripts/clone-swift.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/zsh

set -e

# Default values
CHECKOUT_PATH=".build/checkouts/swift"
SWIFT_VERSION=""

# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--path)
CHECKOUT_PATH="$2"
shift 2
;;
--swift-version)
SWIFT_VERSION="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--path <path>] [--swift-version <major.minor>]"
exit 1
;;
esac
done

# Detect Swift version if not provided
if [ -z "$SWIFT_VERSION" ]; then
SWIFT_VERSION=$(swift --version 2>/dev/null | grep -oE 'Swift version [0-9]+\.[0-9]+' | grep -oE '[0-9]+\.[0-9]+')
echo "Detected Swift version: $SWIFT_VERSION"
fi

SWIFT_VERSION_MAJOR=$(echo "$SWIFT_VERSION" | cut -d. -f1)
SWIFT_VERSION_MINOR=$(echo "$SWIFT_VERSION" | cut -d. -f2)

# Remove existing checkout if present
rm -rf "$CHECKOUT_PATH"
mkdir -p "$CHECKOUT_PATH"

# Clone with sparse checkout
git clone --filter=blob:none --no-checkout --depth 1 \
--branch "release/$SWIFT_VERSION_MAJOR.$SWIFT_VERSION_MINOR" \
git@github.com:swiftlang/swift.git "$CHECKOUT_PATH"

cd "$CHECKOUT_PATH"

git sparse-checkout set --no-cone \
include/swift \
stdlib/include \
stdlib/public/SwiftShims \
stdlib/public/runtime/MetadataAllocatorTags.def

git checkout

# Write CMakeConfig.h file
cat > include/swift/Runtime/CMakeConfig.h << EOF
#ifndef SWIFT_RUNTIME_CMAKECONFIG_H
#define SWIFT_RUNTIME_CMAKECONFIG_H
#define SWIFT_VERSION_MAJOR "$SWIFT_VERSION_MAJOR"
#define SWIFT_VERSION_MINOR "$SWIFT_VERSION_MINOR"
#endif
EOF

echo "The Swift repository has been cloned to $CHECKOUT_PATH"
21 changes: 21 additions & 0 deletions Scripts/create-xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,26 @@ xcodebuild archive \
-archivePath "$BUILD_DIR/Archives/Compute-macOS.xcarchive" \
ENABLE_USER_SCRIPT_SANDBOXING=NO

xcodebuild archive \
-project Compute.xcodeproj \
-scheme Compute \
-destination "generic/platform=iOS" \
-archivePath "$BUILD_DIR/Archives/Compute-iOS.xcarchive" \
ENABLE_USER_SCRIPT_SANDBOXING=NO

xcodebuild archive \
-project Compute.xcodeproj \
-scheme Compute \
-destination "generic/platform=iOS Simulator" \
-archivePath "$BUILD_DIR/Archives/Compute-iOS-Simulator.xcarchive" \
ENABLE_USER_SCRIPT_SANDBOXING=NO

rm -rf "$BUILD_DIR/Frameworks/Compute.xcframework"

xcodebuild -create-xcframework \
-archive "$BUILD_DIR/Archives/Compute-macOS.xcarchive" -framework Compute.framework \
-archive "$BUILD_DIR/Archives/Compute-iOS.xcarchive" -framework Compute.framework \
-archive "$BUILD_DIR/Archives/Compute-iOS-Simulator.xcarchive" -framework Compute.framework \
-output "$BUILD_DIR/Frameworks/Compute.xcframework"

# Post-process swiftinterface files to replace ComputeCxx references with Compute
Expand All @@ -36,3 +52,8 @@ find "$BUILD_DIR/Frameworks/Compute.xcframework" -type d -name "Compute.framewor
echo "Added Headers symlink to: $framework_dir"
fi
done

# Zip the framework, preserving symlinks
cd "$BUILD_DIR/Frameworks"
zip -r -y Compute.xcframework.zip Compute.xcframework
echo "Created Compute.xcframework.zip"
2 changes: 1 addition & 1 deletion Sources/Compute/Attribute/AttributeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension _AttributeType {
vtable.pointee.self_destroy = { attributeType, body in
attributeType.pointee.attributeBody._destroySelf(body)
}
#if os(macOS)
#if os(iOS) || os(macOS)
vtable.pointee.self_description = { attributeType, body in
let description: String
if let selfType = attributeType.pointee.self_id.type
Expand Down
2 changes: 1 addition & 1 deletion Sources/Compute/Runtime/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Metadata {
extension Metadata: @retroactive CustomStringConvertible {

public var description: String {
#if os(macOS)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
Maybe use #if canImport(Darwin) or #if canImport(ObjectiveC) since the upstream may add other Darwin platform support like watchOS and visionOS?

#if os(iOS) || os(macOS)
return __AGTypeDescription(self) as String
#else
return String(__AGTypeCopyDescription(self))
Expand Down