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
2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 37 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var sharedCSettings: [CSetting] = [
.define("NDEBUG", .when(configuration: .release)),
]

var sharedCXXSettings: [CXXSetting] = [
var sharedCxxSettings: [CXXSetting] = [
.unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)),
.define("NDEBUG", .when(configuration: .release)),
]
Expand All @@ -185,7 +185,7 @@ sharedCSettings.append(
"-isystem", "\(swiftCheckoutPath)/stdlib/public/SwiftShims",
])
)
sharedCXXSettings.append(
sharedCxxSettings.append(
.unsafeFlags([
"-isystem", "\(swiftCheckoutPath)/include",
"-isystem", "\(swiftCheckoutPath)/stdlib/include",
Expand All @@ -208,7 +208,7 @@ if libraryEvolutionCondition {
}
if !compatibilityTestCondition {
sharedCSettings.append(.define("OPENATTRIBUTEGRAPH"))
sharedCXXSettings.append(.define("OPENATTRIBUTEGRAPH"))
sharedCxxSettings.append(.define("OPENATTRIBUTEGRAPH"))
sharedSwiftSettings.append(.define("OPENATTRIBUTEGRAPH"))
}

Expand All @@ -231,38 +231,49 @@ extension [Platform] {
}
}

// MARK: - Targets
// MARK: - Plugin

let swiftClonePlugin = Target.plugin(
name: "CloneSwiftPlugin",
capability: .buildTool()
)

let openAttributeGraphTarget = Target.target(
name: "OpenAttributeGraph",
dependencies: ["OpenAttributeGraphCxx"],
cSettings: sharedCSettings,
cxxSettings: sharedCXXSettings,
swiftSettings: sharedSwiftSettings
// MARK: - Targets

let platformTarget = Target.target(
name: "Platform",
cSettings: [
.define("_GNU_SOURCE", .when(platforms: [.linux])),
]
)
// FIXME: Merge into one target
// OpenAttributeGraph is a C++ & Swift mix target.
// The SwiftPM support for such usage is still in progress.
let openAttributeGraphSPITarget = Target.target(
let openAttributeGraphCxxTarget = Target.target(
name: "OpenAttributeGraphCxx",
dependencies: [.target(name: platformTarget.name)],
cSettings: sharedCSettings + [
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
],
cxxSettings: sharedCXXSettings,
cxxSettings: sharedCxxSettings,
linkerSettings: [
.linkedLibrary("z"),
],
plugins: [.plugin(name: swiftClonePlugin.name)]
)
let openAttributeGraphTarget = Target.target(
name: "OpenAttributeGraph",
dependencies: [
.target(name: openAttributeGraphCxxTarget.name),
],
cSettings: sharedCSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings
)
let openAttributeGraphShimsTarget = Target.target(
name: "OpenAttributeGraphShims",
cSettings: sharedCSettings,
cxxSettings: sharedCXXSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings
)

Expand All @@ -271,41 +282,41 @@ let openAttributeGraphShimsTarget = Target.target(
let openAttributeGraphTestsTarget = Target.testTarget(
name: "OpenAttributeGraphTests",
dependencies: [
"OpenAttributeGraph",
.target(name: openAttributeGraphTarget.name),
],
exclude: ["README.md"],
cSettings: sharedCSettings,
cxxSettings: sharedCXXSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings
)
let openAttributeGraphCxxTestsTarget = Target.testTarget(
name: "OpenAttributeGraphCxxTests",
dependencies: [
"OpenAttributeGraphCxx",
.target(name: openAttributeGraphCxxTarget.name),
],
exclude: ["README.md"],
cSettings: sharedCSettings + [.define("SWIFT_TESTING")],
cxxSettings: sharedCXXSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings + [.interoperabilityMode(.Cxx)]
)
let openAttributeGraphShimsTestsTarget = Target.testTarget(
name: "OpenAttributeGraphShimsTests",
dependencies: [
"OpenAttributeGraphShims",
.target(name: openAttributeGraphShimsTarget.name),
],
exclude: ["README.md"],
cSettings: sharedCSettings,
cxxSettings: sharedCXXSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings
)
let openAttributeGraphCompatibilityTestsTarget = Target.testTarget(
name: "OpenAttributeGraphCompatibilityTests",
dependencies: [
.product(name: "Numerics", package: "swift-numerics"),
] + (compatibilityTestCondition ? [] : ["OpenAttributeGraph"]),
] + (compatibilityTestCondition ? [] : [.target(name: openAttributeGraphTarget.name)]),
exclude: ["README.md"],
cSettings: sharedCSettings,
cxxSettings: sharedCXXSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings
)

Expand All @@ -314,16 +325,17 @@ let openAttributeGraphCompatibilityTestsTarget = Target.testTarget(
let package = Package(
name: "OpenAttributeGraph",
products: [
.library(name: "OpenAttributeGraph", type: .dynamic, targets: ["OpenAttributeGraph", "OpenAttributeGraphCxx"]),
.library(name: "OpenAttributeGraphShims", type: .dynamic, targets: ["OpenAttributeGraph", "OpenAttributeGraphCxx", "OpenAttributeGraphShims"]),
.library(name: "OpenAttributeGraph", type: .dynamic, targets: [openAttributeGraphTarget.name, openAttributeGraphCxxTarget.name]),
.library(name: "OpenAttributeGraphShims", type: .dynamic, targets: [openAttributeGraphTarget.name, openAttributeGraphCxxTarget.name, openAttributeGraphShimsTarget.name]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
],
targets: [
swiftClonePlugin,
platformTarget,
openAttributeGraphTarget,
openAttributeGraphSPITarget,
openAttributeGraphCxxTarget,
openAttributeGraphShimsTarget,
],
cxxLanguageStandard: .cxx20
Expand Down Expand Up @@ -362,6 +374,6 @@ if attributeGraphCondition {
default: nil
}
} else {
openAttributeGraphShimsTarget.dependencies.append("OpenAttributeGraph")
openAttributeGraphShimsTarget.dependencies.append(.target(name: openAttributeGraphTarget.name))
package.platforms = [.iOS(.v13), .macOS(.v10_15), .macCatalyst(.v13), .tvOS(.v13), .watchOS(.v5)]
}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ For a simpler setup, you can use the prebuilt XCFramework available on the [rele

The current suggested toolchain to build the project is Swift 6.1.2 / Xcode 16.4.

### Clone Swift headers

The project requires Swift toolchain headers for compilation. You can either clone them manually or let the build plugin handle it:

```shell
# Option 1: Clone headers manually
./Scripts/clone-swift.sh

# Option 2: Let the build plugin clone headers (requires --disable-sandbox)
swift build --disable-sandbox
```

### Set up LIB_SWIFT_PATH on non-Darwin platform

If your swift binary path is located in your `<toolchain>/usr/bin/swift` (eg. installed by [swiftbox](https://github.com/stevapple/swiftbox)), no setup is required.
Expand Down
2 changes: 1 addition & 1 deletion Scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ OPENATTRIBUTEGRAPH_ROOT="$(dirname $(dirname $(filepath $0)))"

cd $OPENATTRIBUTEGRAPH_ROOT

swift build
swift build --disable-sandbox
8 changes: 2 additions & 6 deletions Sources/OpenAttributeGraphCxx/Misc/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ void precondition_failure(const char *format, ...) {
vasprintf(&s, format, va);
va_end(va);
if (s != nullptr) {
#if OAG_TARGET_OS_DARWIN
os_log_error(error_log(), "precondition failure: %s", s);
#endif /* OAG_TARGET_OS_DARWIN */
platform_log_error(error_log(), "precondition failure: %s", s);
#if OAG_TARGET_RELEASE >= OAG_RELEASE_2023
// OAG::Graph::trace_assertion_failure(true, "precondition failure: %s", s)
#endif
Expand All @@ -39,9 +37,7 @@ void non_fatal_precondition_failure(const char *format, ...) {
vasprintf(&s, format, va);
va_end(va);
if (s != nullptr) {
#if OAG_TARGET_OS_DARWIN
os_log_fault(error_log(), "precondition failure: %s", s);
#endif /* OAG_TARGET_OS_DARWIN */
platform_log_fault(error_log(), "precondition failure: %s", s);
free(s);
}
return;
Expand Down
15 changes: 6 additions & 9 deletions Sources/OpenAttributeGraphCxx/Misc/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@
// OAGLog.cpp
// OpenAttributeGraphCxx
//
// Audited for 2021 Release
// Status: Complete
// Audited for 6.5.1

#include <OpenAttributeGraphCxx/Misc/log.hpp>

#if OAG_TARGET_OS_DARWIN

namespace OAG {
os_log_t misc_log() {
static os_log_t log = os_log_create("org.OpenSwiftUIProject.OpenAttributeGraph", "misc");
platform_log_t misc_log() {
static platform_log_t log = platform_log_create("org.OpenSwiftUIProject.OpenAttributeGraph", "misc");
return log;
}
os_log_t error_log() {
static os_log_t log = os_log_create("org.OpenSwiftUIProject.OpenAttributeGraph", "error");
platform_log_t error_log() {
static platform_log_t log = platform_log_create("org.OpenSwiftUIProject.OpenAttributeGraph", "error");
return log;
}
} /* OAG */

#endif /* OAG_TARGET_OS_DARWIN */
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
// log.hpp
// OpenAttributeGraphCxx
//
// Audited for 2021 Release
// Status: Complete
// Audited for 6.5.1

#ifndef log_hpp
#define log_hpp

#include <OpenAttributeGraph/OAGBase.h>

#if OAG_TARGET_OS_DARWIN

#include <os/log.h>
#include <platform/log.h>

namespace OAG {
os_log_t misc_log();
os_log_t error_log();
platform_log_t misc_log();
platform_log_t error_log();
} /* OAG */

#endif /* OAG_TARGET_OS_DARWIN */

#endif /* log_hpp */
24 changes: 24 additions & 0 deletions Sources/Platform/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This module is derived from the Platform target in the Compute project:
https://github.com/jcmosc/Compute

MIT License

Copyright (c) 2025 James Moschou

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions Sources/Platform/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Platform {
header "platform/platform.h"
}
63 changes: 63 additions & 0 deletions Sources/Platform/include/platform/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

#ifndef __has_feature
#define __has_feature(x) 0
#endif
#ifndef __has_extension
#define __has_extension(x) 0
#endif

#if !defined(PLATFORM_EXTERN_C_BEGIN)
#if defined(__cplusplus)
#define PLATFORM_EXTERN_C_BEGIN extern "C" {
#define PLATFORM_EXTERN_C_END }
#else
#define PLATFORM_EXTERN_C_BEGIN
#define PLATFORM_EXTERN_C_END
#endif
#endif

#if __GNUC__
#define PLATFORM_EXPORT extern __attribute__((__visibility__("default")))
#else
#define PLATFORM_EXPORT extern
#endif

#if __GNUC__
#define PLATFORM_INLINE static __inline__
#else
#define PLATFORM_INLINE static inline
#endif

#if __has_feature(assume_nonnull)
#define PLATFORM_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
#define PLATFORM_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
#else
#define PLATFORM_ASSUME_NONNULL_BEGIN
#define PLATFORM_ASSUME_NONNULL_END
#endif

#if !__has_feature(nullability)
#ifndef _Nullable
#define _Nullable
#endif
#ifndef _Nonnull
#define _Nonnull
#endif
#ifndef _Null_unspecified
#define _Null_unspecified
#endif
#endif

#if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \
__has_extension(cxx_strong_enums)
#define PLATFORM_ENUM(_name, _type, ...) \
typedef enum : _type { __VA_ARGS__ } _name##_t
#else
#define PLATFORM_ENUM(_name, _type, ...) \
typedef _type _name##_t; enum { __VA_ARGS__ }
#endif
Loading