Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
376b67c
Fix compiler issue on linux
jcmosc Jan 2, 2026
bf5ca0b
Fix string buffer allocation
jcmosc Jan 5, 2026
9f5cb8f
Remove dependency on CF macros
jcmosc Jan 5, 2026
061a591
Make Darwin-specific C code portable
jcmosc Jan 5, 2026
0fbc8bf
Disable fetching layouts asynchronously on non-Darwin platforms
jcmosc Jan 5, 2026
2e89823
Vendor CoreFoundation headers and remove autorelease logic on linux
jcmosc Jan 5, 2026
3b21e07
Disable ObjC code on non-Darwin platforms
jcmosc Jan 5, 2026
9f493cf
fixup macro
jcmosc Jan 5, 2026
efbe1e6
Make AGMakeUniqueID atomic
jcmosc Jan 5, 2026
3a2d889
Delete unused code
jcmosc Jan 5, 2026
3a062d1
fixup vendor
jcmosc Jan 5, 2026
7c3db01
Include CoreFoundation.h in CFPointer.h
jcmosc Jan 6, 2026
0dbb12a
Fix build errors when cross-compiling for linux
jcmosc Jan 8, 2026
e347b14
Build on ubuntu-latest in CI
jcmosc Jan 10, 2026
963e2e8
Add dummy patch version to swift-version in CI
jcmosc Jan 10, 2026
ea53ee3
Run linux CI job in a container
jcmosc Jan 10, 2026
5e65492
Fix variable substitution in CI
jcmosc Jan 10, 2026
c84e3fd
Include stdio.h in files that use vasprintf
jcmosc Jan 10, 2026
d2fd8d4
Define _GNU_SOURCE
jcmosc Jan 10, 2026
39a3d66
Import cstring where memset used
jcmosc Jan 10, 2026
068ba76
Always refer to std::nullptr_t instead of nullptr_t in the global nam…
jcmosc Jan 10, 2026
245b443
Add name to step
jcmosc Jan 10, 2026
64acc4d
Include cstring where memcpy used
jcmosc Jan 10, 2026
551a5df
Install libssl-dev in Ubuntu
jcmosc Jan 10, 2026
d36053c
Don't need sudo inside container
jcmosc Jan 10, 2026
b8edb79
Include deque
jcmosc Jan 10, 2026
dbb86e7
Try setting -Wno-elaborated-enum-base as a C setting too
jcmosc Jan 10, 2026
8d4a102
Add -Wno-elaborated-enum-base to swift build invocation
jcmosc Jan 10, 2026
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
49 changes: 42 additions & 7 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift

on:
Expand All @@ -10,15 +7,53 @@ on:
branches: ["main"]

jobs:
build:
macos-build:
name: macOS
runs-on: macos-26

strategy:
matrix:
swift: ["6.2"]
steps:
- id: swift-version
run: |
MAJOR=$(echo "${{ matrix.swift }}" | cut -d. -f1)
MINOR=$(echo "${{ matrix.swift }}" | cut -d. -f2)
echo "major=$MAJOR" >> $GITHUB_OUTPUT
echo "minor=$MINOR" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- uses: ./.github/actions/checkout-swift-headers
with:
path: Checkouts/swift
swift-version-major: 6
swift-version-minor: 2
swift-version-major: ${{ steps.swift-version.outputs.major }}
swift-version-minor: ${{ steps.swift-version.outputs.minor }}
- name: Build
run: swift build

linux-build:
name: Linux
runs-on: ubuntu-latest
strategy:
matrix:
swift: ["6.2"]
container:
image: swift:${{ matrix.swift }}-jammy
steps:
- name: Install dependencies
run: |
apt-get update
apt-get install -y libssl-dev
- name: Swift version
id: swift-version
run: |
MAJOR=$(echo "${{ matrix.swift }}" | cut -d. -f1)
MINOR=$(echo "${{ matrix.swift }}" | cut -d. -f2)
echo "major=$MAJOR" >> $GITHUB_OUTPUT
echo "minor=$MINOR" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- uses: ./.github/actions/checkout-swift-headers
with:
path: Checkouts/swift
swift-version-major: ${{ steps.swift-version.outputs.major }}
swift-version-minor: ${{ steps.swift-version.outputs.minor }}
- name: Build
run: swift build -Xcc -Wno-elaborated-enum-base
27 changes: 25 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ let package = Package(
dependencies: dependencies,
targets: [
.target(
name: "Utilities"
name: "Platform",
cSettings: [
.define("_GNU_SOURCE", .when(platforms: [.linux]))
]
),
.target(
name: "SwiftCorelibsCoreFoundation"
),
.target(
name: "Utilities",
dependencies: [
"Platform",
.target(name: "SwiftCorelibsCoreFoundation", condition: .when(platforms: [.linux])),
]
),
.testTarget(
name: "UtilitiesTests",
Expand Down Expand Up @@ -67,9 +80,19 @@ let package = Package(
),
.target(
name: "ComputeCxx",
dependencies: ["Utilities", "ComputeCxxSwiftSupport"],
dependencies: [
"Platform",
"Utilities",
"ComputeCxxSwiftSupport",
.target(name: "SwiftCorelibsCoreFoundation", condition: .when(platforms: [.linux])),
],
cSettings: [
.unsafeFlags(["-Wno-elaborated-enum-base"])
],
cxxSettings: [
.headerSearchPath(""),
.headerSearchPath("internalInclude"),
.define("_GNU_SOURCE", .when(platforms: [.linux])),
.unsafeFlags([
"-Wno-elaborated-enum-base",
"-static",
Expand Down
4 changes: 4 additions & 0 deletions Sources/Compute/Attribute/AnyAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ extension AnyAttribute: @retroactive CustomStringConvertible {
extension AnyAttribute: @retroactive Equatable {}

extension AnyAttribute: @retroactive Hashable {}

extension AnyAttribute {
public typealias _ObjectiveCType = Self.RawValue // Fixes compiler crash
}
25 changes: 21 additions & 4 deletions Sources/Compute/Attribute/AttributeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extension _AttributeType {
vtable.pointee.self_destroy = { attributeType, body in
attributeType.pointee.attributeBody._destroySelf(body)
}
#if os(macOS)
vtable.pointee.self_description = { attributeType, body in
let description: String
if let selfType = attributeType.pointee.self_id.type
Expand All @@ -60,15 +61,31 @@ extension _AttributeType {
} else {
description = attributeType.pointee.self_id.description
}
return Unmanaged<CFString>.passRetained(description as NSString)
.autorelease()
return Unmanaged<CFString>.passRetained(description as CFString).autorelease()
}
vtable.pointee.value_description = { attributeType, value in
let valueType = attributeType.pointee.value_id.type
let description = String._describing(value, of: valueType)
return Unmanaged<CFString>.passRetained(description as NSString)
.autorelease()
return Unmanaged<CFString>.passRetained(description as CFString).autorelease()
}
#else
vtable.pointee.copy_self_description = { attributeType, body in
let description: String
if let selfType = attributeType.pointee.self_id.type
as? any CustomStringConvertible.Type
{
description = String._describing(body, of: selfType)
} else {
description = attributeType.pointee.self_id.description
}
return Unmanaged<CFString>.passRetained(description.cfString)
}
vtable.pointee.copy_value_description = { attributeType, value in
let valueType = attributeType.pointee.value_id.type
let description = String._describing(value, of: valueType)
return Unmanaged<CFString>.passRetained(description.cfString)
}
#endif
vtable.pointee.update_default = { attributeType, body in
attributeType.pointee.attributeBody._updateDefault(body)
}
Expand Down
7 changes: 5 additions & 2 deletions Sources/Compute/Runtime/Metadata.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ComputeCxx
import Foundation

extension Metadata {

Expand Down Expand Up @@ -45,7 +44,11 @@ extension Metadata {
extension Metadata: @retroactive CustomStringConvertible {

public var description: String {
return __AGTypeDescription(self) as String
#if os(macOS)
return __AGTypeDescription(self) as String
#else
return String(__AGTypeCopyDescription(self))
#endif
}

}
Expand Down
33 changes: 33 additions & 0 deletions Sources/Compute/Utility/FoundationExtensions/String+CFString.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation

extension String {
init(_ cfString: CFString) {
if let ptr = CFStringGetCStringPtr(cfString, CFStringBuiltInEncodings.UTF8.rawValue) {
self.init(cString: ptr)
return
}

let length = CFStringGetLength(cfString)
let maxSize = CFStringGetMaximumSizeForEncoding(length, CFStringBuiltInEncodings.UTF8.rawValue) + 1

let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: maxSize)
defer { buffer.deallocate() }

guard CFStringGetCString(cfString, buffer, maxSize, CFStringBuiltInEncodings.UTF8.rawValue) else {
self = ""
return
}
self.init(cString: buffer)
}

var cfString: CFString {
guard let cString = self.cString(using: .utf8),
let cfString = CFStringCreateWithCString(nil, cString, CFStringBuiltInEncodings.UTF8.rawValue)
else {
let utf8 = Array(self.utf8)
return CFStringCreateWithBytes(nil, utf8, utf8.count, CFStringBuiltInEncodings.UTF8.rawValue, false)
}
return cfString
}

}
7 changes: 4 additions & 3 deletions Sources/ComputeCxx/Array/ArrayRef.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once

#include <CoreFoundation/CFBase.h>
#include <iterator>

CF_ASSUME_NONNULL_BEGIN
#include <ComputeCxx/AGBase.h>

AG_ASSUME_NONNULL_BEGIN

namespace AG {

Expand Down Expand Up @@ -62,4 +63,4 @@ template <typename T> class ArrayRef {

} // namespace AG

CF_ASSUME_NONNULL_END
AG_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#pragma once

#include <CoreFoundation/CFBase.h>

#include "Attribute/AttributeData/Edge/OutputEdge.h"
#include "Attribute/AttributeID/AttributeID.h"
#include "Attribute/AttributeID/RelativeAttributeID.h"
#include "Attribute/AttributeID/WeakAttributeID.h"
#include "ComputeCxx/AGBase.h"
#include "Data/Vector.h"

CF_ASSUME_NONNULL_BEGIN
AG_ASSUME_NONNULL_BEGIN

namespace AG {

Expand Down Expand Up @@ -92,4 +91,4 @@ class MutableIndirectNode : public IndirectNode {

} // namespace AG

CF_ASSUME_NONNULL_END
AG_ASSUME_NONNULL_END
7 changes: 3 additions & 4 deletions Sources/ComputeCxx/Attribute/AttributeData/Node/Node.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#pragma once

#include <CoreFoundation/CFBase.h>

#include "Attribute/AttributeData/Edge/InputEdge.h"
#include "Attribute/AttributeData/Edge/OutputEdge.h"
#include "Attribute/AttributeID/RelativeAttributeID.h"
#include "ComputeCxx/AGAttribute.h"
#include "ComputeCxx/AGBase.h"
#include "ComputeCxx/AGGraph.h"
#include "Data/Pointer.h"
#include "Data/Vector.h"

CF_ASSUME_NONNULL_BEGIN
AG_ASSUME_NONNULL_BEGIN

namespace AG {

Expand Down Expand Up @@ -179,4 +178,4 @@ class Node {

} // namespace AG

CF_ASSUME_NONNULL_END
AG_ASSUME_NONNULL_END
9 changes: 4 additions & 5 deletions Sources/ComputeCxx/Attribute/AttributeID/AttributeID.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#pragma once

#include <CoreFoundation/CFBase.h>
#include <cassert>
#include <optional>
#include <stdint.h>

#include "ComputeCxx/AGAttribute.h"
#include "ComputeCxx/AGBase.h"
#include "Data/Page.h"
#include "Data/Pointer.h"
#include "Data/Zone.h"

CF_ASSUME_NONNULL_BEGIN
AG_ASSUME_NONNULL_BEGIN

namespace AG {

Expand Down Expand Up @@ -69,7 +68,7 @@ class AttributeID {
public:
static constexpr uint32_t KindMask = 0x3;

explicit constexpr AttributeID(nullptr_t = nullptr) : _value(0) {};
explicit constexpr AttributeID(std::nullptr_t = nullptr) : _value(0) {};
explicit AttributeID(data::ptr<class Node> node) : _value(node.offset() | Kind::Node) {};
explicit AttributeID(data::ptr<class IndirectNode> indirect_node)
: _value(indirect_node.offset() | Kind::IndirectNode) {};
Expand Down Expand Up @@ -132,4 +131,4 @@ class AttributeID {

} // namespace AG

CF_ASSUME_NONNULL_END
AG_ASSUME_NONNULL_END
7 changes: 3 additions & 4 deletions Sources/ComputeCxx/Attribute/AttributeID/OffsetAttributeID.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include <CoreFoundation/CFBase.h>
#include <stdint.h>
#include "ComputeCxx/AGBase.h"

#include "AttributeID.h"

CF_ASSUME_NONNULL_BEGIN
AG_ASSUME_NONNULL_BEGIN

namespace AG {

Expand All @@ -25,4 +24,4 @@ class OffsetAttributeID {

} // namespace AG

CF_ASSUME_NONNULL_END
AG_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RelativeAttributeID {
uint16_t _value;

public:
explicit constexpr RelativeAttributeID(nullptr_t = nullptr) : _value(0) {};
explicit constexpr RelativeAttributeID(std::nullptr_t = nullptr) : _value(0) {};
explicit constexpr RelativeAttributeID(uint16_t value) : _value(value) {};
constexpr RelativeAttributeID(AttributeID attribute)
: _value(((attribute & ~AttributeID::KindMask) - attribute.page_ptr().offset()) | attribute.kind()) {};
Expand Down
8 changes: 3 additions & 5 deletions Sources/ComputeCxx/Attribute/AttributeID/WeakAttributeID.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#pragma once

#include <CoreFoundation/CFBase.h>
#include <stdint.h>

#include "AttributeID.h"
#include "ComputeCxx/AGBase.h"
#include "ComputeCxx/AGWeakAttribute.h"

CF_ASSUME_NONNULL_BEGIN
AG_ASSUME_NONNULL_BEGIN

namespace AG {

Expand Down Expand Up @@ -35,4 +33,4 @@ class WeakAttributeID {

} // namespace AG

CF_ASSUME_NONNULL_END
AG_ASSUME_NONNULL_END
Loading