Skip to content

Commit e9e235f

Browse files
authored
Add Compute source build support (#214)
1 parent 322a79c commit e9e235f

5 files changed

Lines changed: 104 additions & 33 deletions

File tree

‎.github/workflows/compute.yml‎

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@ on:
77
branches: [main]
88

99
jobs:
10-
# TODO: Enable once Compute binary is available for Linux or source integration is supported
11-
# compute_ubuntu_build:
12-
# name: Build with Compute on Ubuntu
13-
# strategy:
14-
# fail-fast: false
15-
# matrix:
16-
# swift_version: ["6.1.3"]
17-
# runs-on: ubuntu-22.04
18-
# env:
19-
# OPENATTRIBUTEGRAPH_WERROR: 1
20-
# OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
21-
# OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
22-
# container: swift:${{ matrix.swift_version }}-jammy
23-
# steps:
24-
# - uses: actions/checkout@v4
25-
# - name: Checkout Swift headers
26-
# uses: ./.github/actions/checkout-swift-headers
27-
# - name: Build in debug mode
28-
# run: swift build -c debug
10+
compute_ubuntu_build:
11+
name: Build with Compute (source) on Ubuntu
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
swift_version: ["6.2"]
16+
runs-on: ubuntu-22.04
17+
env:
18+
# -Wno-elaborated-enum-base is not working for Compute dependency. Disable warnings-as-errors for now to unblock CI. We should fix the underlying issue and re-enable warnings-as-errors in the future.
19+
# OPENATTRIBUTEGRAPH_WERROR: 1
20+
OPENATTRIBUTEGRAPH_WERROR: 0
21+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
22+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE_USE_BINARY: 0
23+
OPENATTRIBUTEGRAPH_USE_LOCAL_DEPS: 1
24+
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
25+
container: swift:${{ matrix.swift_version }}-jammy
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Set up Linux build environment
29+
run: Scripts/CI/linux_compute_build.sh
30+
shell: bash
31+
- name: Checkout Swift headers
32+
uses: ./.github/actions/checkout-swift-headers
33+
- name: Build in debug mode
34+
run: swift build -c debug -Xcc -Wno-elaborated-enum-base
2935

3036
compute_macos_build:
31-
name: Build with Compute on macOS
37+
name: Build with Compute (binary) on macOS
3238
strategy:
3339
fail-fast: false
3440
matrix:
@@ -38,6 +44,7 @@ jobs:
3844
env:
3945
OPENATTRIBUTEGRAPH_WERROR: 1
4046
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
47+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE_USE_BINARY: 1
4148
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
4249
steps:
4350
- uses: actions/checkout@v4
@@ -51,7 +58,7 @@ jobs:
5158
run: swift build -c debug
5259

5360
compute_ios_build:
54-
name: Build with Compute on iOS
61+
name: Build with Compute (binary) on iOS
5562
strategy:
5663
fail-fast: false
5764
matrix:
@@ -65,6 +72,7 @@ jobs:
6572
env:
6673
OPENATTRIBUTEGRAPH_WERROR: 1
6774
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
75+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE_USE_BINARY: 1
6876
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
6977
steps:
7078
- uses: actions/checkout@v4

‎Package.resolved‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Package.swift‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,17 @@ extension Target {
230230
self.swiftSettings = swiftSettings
231231
}
232232

233-
func addComputeBinarySettings() {
233+
func addComputeSettings() {
234234
dependencies.append(
235235
"Compute",
236236
)
237237
var swiftSettings = swiftSettings ?? []
238238
swiftSettings.append(.define("OPENATTRIBUTEGRAPH_COMPUTE"))
239239
self.swiftSettings = swiftSettings
240+
241+
var linkerSettings = linkerSettings ?? []
242+
linkerSettings.append(.linkedLibrary("swiftDemangle", .when(platforms: .darwinPlatforms)))
243+
self.linkerSettings = linkerSettings
240244
}
241245
}
242246

@@ -272,16 +276,20 @@ let swiftClonePlugin = Target.plugin(
272276
// MARK: - Targets
273277

274278
let platformTarget = Target.target(
275-
name: "Platform",
279+
// Avoid target collision with Compute package
280+
name: "OpenAttributeGraphPlatform",
281+
path: "Sources/Platform",
276282
cSettings: sharedCSettings + [
277283
.define("_GNU_SOURCE", .when(platforms: [.linux])),
278284
]
279285
)
280286
let utilitiesTarget = Target.target(
281-
name: "Utilities",
287+
// Avoid target collision with Compute package
288+
name: "OpenAttributeGraphUtilities",
282289
dependencies: [
283290
.target(name: platformTarget.name),
284291
],
292+
path: "Sources/Utilities",
285293
cxxSettings: sharedCxxSettings
286294
)
287295
// FIXME: Merge into one target
@@ -365,7 +373,7 @@ let package = Package(
365373
name: "OpenAttributeGraph",
366374
products: [
367375
.library(name: "OpenAttributeGraph", type: .dynamic, targets: [openAttributeGraphTarget.name, openAttributeGraphCxxTarget.name]),
368-
.library(name: "OpenAttributeGraphShims", type: .dynamic, targets: [openAttributeGraphTarget.name, openAttributeGraphCxxTarget.name, openAttributeGraphShimsTarget.name]),
376+
.library(name: "OpenAttributeGraphShims", type: .dynamic, targets: [openAttributeGraphShimsTarget.name]),
369377
],
370378
dependencies: [
371379
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
@@ -421,22 +429,30 @@ if buildForDarwinPlatform {
421429
}
422430

423431
if computeCondition {
424-
let computeBinary = envBoolValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY", default: true)
432+
let computeBinary = envBoolValue("OPENATTRIBUTESHIMS_COMPUTE_USE_BINARY", default: false)
425433
if computeBinary {
426-
let computeVersion = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_VERSION", default: "0.0.1")
427-
let computeURL = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_URL", default: "https://github.com/Kyle-Ye/Compute/releases/download/\(computeVersion)/Compute.xcframework.zip")
428-
let computeChecksum = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_CHECKSUM", default: "95a256da2055d7c73184aeb9be088ba7019f7ea79b8a31e2dd930526c5ccbe8f")
434+
let computeVersion = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_USE_BINARY_VERSION", default: "0.0.1")
435+
// TODO: Use upstream link when avaiable. Tracked on https://github.com/jcmosc/Compute/issues/20
436+
let computeURL = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_USE_BINARY_URL", default: "https://github.com/Kyle-Ye/Compute/releases/download/\(computeVersion)/Compute.xcframework.zip")
437+
let computeChecksum = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_USE_BINARY_CHECKSUM", default: "95a256da2055d7c73184aeb9be088ba7019f7ea79b8a31e2dd930526c5ccbe8f")
429438
package.targets.append(
430439
.binaryTarget(
431440
name: "Compute",
432441
url: computeURL,
433442
checksum: computeChecksum
434-
),
443+
)
435444
)
436-
openAttributeGraphShimsTarget.addComputeBinarySettings()
437445
} else {
438-
// TODO
446+
let computeRepo: Package.Dependency
447+
if useLocalDeps {
448+
computeRepo = Package.Dependency.package(path: "../Compute")
449+
} else {
450+
// TODO: No release tag or branch yet.
451+
computeRepo = Package.Dependency.package(url: "https://github.com/jcmosc/Compute", revision: "34c5af92008a2db18e8b598fb426e3e2872e752c")
452+
}
453+
package.dependencies.append(computeRepo)
439454
}
455+
openAttributeGraphShimsTarget.addComputeSettings()
440456
package.platforms = [.iOS(.v18), .macOS(.v15), .macCatalyst(.v18), .tvOS(.v18), .watchOS(.v10), .visionOS(.v2)]
441457
} else if attributeGraphCondition {
442458
setupDPFDependency()

‎Scripts/CI/compute_setup.sh‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# A `realpath` alternative using the default C implementation.
4+
filepath() {
5+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
6+
}
7+
8+
REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))"
9+
cd $REPO_ROOT
10+
11+
clone_checkout_compute() {
12+
cd $REPO_ROOT
13+
revision=$(Scripts/CI/get_revision.sh compute)
14+
cd ..
15+
if [ ! -d Compute ]; then
16+
git clone https://github.com/jcmosc/Compute.git
17+
cd Compute
18+
else
19+
echo "Compute already exists, skipping clone."
20+
cd Compute
21+
git fetch --all --quiet
22+
git stash --quiet || true
23+
git reset --hard --quiet origin/main
24+
fi
25+
git checkout --quiet $revision
26+
git submodule update --init --recursive
27+
}
28+
29+
clone_checkout_compute

‎Scripts/CI/linux_compute_build.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# A `realpath` alternative using the default C implementation.
4+
filepath() {
5+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
6+
}
7+
8+
REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))"
9+
cd $REPO_ROOT
10+
11+
# Fix SSH submodule checkout failure for git@github.com:jcmosc/swift-runtime-headers.git
12+
git config --global url."https://github.com/".insteadOf "git@github.com:"
13+
14+
# Install Linux dependencies
15+
apt-get update
16+
apt-get install -y libssl-dev
17+
18+
Scripts/CI/compute_setup.sh

0 commit comments

Comments
 (0)