From 5c7896764b8dc86e77db88e6b566e571ea7ce25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Mu=CC=88ller?= Date: Sun, 19 Oct 2025 14:48:02 +0200 Subject: [PATCH 1/3] Adds support for building using swiftly - when building on Linux the usage of swiftly improves the installation of Swift toolchains. Updated README and Package.swift to help building it when using swiftly. --- Package.swift | 16 +++++++++++----- README.md | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 32129fd..3ee2d27 100644 --- a/Package.swift +++ b/Package.swift @@ -17,6 +17,16 @@ func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { } } +func detectIncludePath() -> String { + if let path = Context.environment["SWIFT_TOOLCHAIN_PATH"] { + return path + "/usr/lib/swift" + } + let swiftBinPath = Context.environment["_"] ?? "/usr/bin/swift" + let swiftBinURL = URL(fileURLWithPath: swiftBinPath) + let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path + return SDKPath.appending("/usr/lib/swift") +} + #if os(macOS) // NOTE: #if os(macOS) check is not accurate if we are cross compiling for Linux platform. So we add an env key to specify it. let buildForDarwinPlatform = envEnable("OPENSWIFTUI_BUILD_FOR_DARWIN_PLATFORM", default: true) @@ -34,11 +44,7 @@ let isSPIBuild = envEnable("SPI_BUILD") let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode" let development = envEnable("OPENATTRIBUTEGRAPH_DEVELOPMENT", default: false) - -let swiftBinPath = Context.environment["_"] ?? "/usr/bin/swift" -let swiftBinURL = URL(fileURLWithPath: swiftBinPath) -let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path -let includePath = SDKPath.appending("/usr/lib/swift") +let includePath = detectIncludePath() var sharedCSettings: [CSetting] = [ .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), diff --git a/README.md b/README.md index e1abf2b..9bcbec2 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ dependencies: [ ``` > [!NOTE] +> > - You may need to configure the Swift toolchain header for proper integration of OpenAttributeGraph > - By default, OpenAttributeGraphShims will use the private AttributeGraph as its implementation on Apple platforms @@ -49,6 +50,20 @@ 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. +### Usage with ```swiftly```` + +If you have installed [Swiftly](https://github.com/swiftlang/swiftly) for managing your installed swift toolchains (Linux) set the following variable to your shell: + +```bash +export SWIFT_TOOLCHAIN_PATH="$(swiftly use --print-location)" +``` + +```fish +set -gx SWIFT_TOOLCHAIN_PATH (swiftly use --print-location) +``` + +Then run `swift build` + ## License See LICENSE file - MIT From 92677e2851b164486742d74c30e8aa3765dacee6 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 2 Nov 2025 22:46:18 +0800 Subject: [PATCH 2/3] Add OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH config --- Package.swift | 26 ++++++++++++++------------ README.md | 22 ++++++++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Package.swift b/Package.swift index 3ee2d27..a0a4575 100644 --- a/Package.swift +++ b/Package.swift @@ -17,16 +17,6 @@ func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { } } -func detectIncludePath() -> String { - if let path = Context.environment["SWIFT_TOOLCHAIN_PATH"] { - return path + "/usr/lib/swift" - } - let swiftBinPath = Context.environment["_"] ?? "/usr/bin/swift" - let swiftBinURL = URL(fileURLWithPath: swiftBinPath) - let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path - return SDKPath.appending("/usr/lib/swift") -} - #if os(macOS) // NOTE: #if os(macOS) check is not accurate if we are cross compiling for Linux platform. So we add an env key to specify it. let buildForDarwinPlatform = envEnable("OPENSWIFTUI_BUILD_FOR_DARWIN_PLATFORM", default: true) @@ -44,10 +34,22 @@ let isSPIBuild = envEnable("SPI_BUILD") let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode" let development = envEnable("OPENATTRIBUTEGRAPH_DEVELOPMENT", default: false) -let includePath = detectIncludePath() + +// From Swift toolchain being installed or from Swift SDK. +func detectLibSwiftPath() -> String { + guard let libSwiftPath = Context.environment["OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH"] else { + // Fallback when LIB_SWIFT_PATH is not set + let swiftBinPath = Context.environment["OPENATTRIBUTEGRAPH_BIN_SWIFT_PATH"] ?? Context.environment["_"] ?? "/usr/bin/swift" + let swiftBinURL = URL(fileURLWithPath: swiftBinPath) + let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path + return SDKPath.appending("/usr/lib/swift") + } + return libSwiftPath +} +let libSwiftPath = detectLibSwiftPath() var sharedCSettings: [CSetting] = [ - .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), + .unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)), .define("NDEBUG", .when(configuration: .release)), ] diff --git a/README.md b/README.md index 9bcbec2..d6c7f1d 100644 --- a/README.md +++ b/README.md @@ -50,19 +50,25 @@ 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. -### Usage with ```swiftly```` +### Set up LIB_SWIFT_PATH on non-Darwin platform -If you have installed [Swiftly](https://github.com/swiftlang/swiftly) for managing your installed swift toolchains (Linux) set the following variable to your shell: +If your swift binary path is located in your `/usr/bin/swift` (eg. installed by [swiftbox](https://github.com/stevapple/swiftbox)), no setup is required. -```bash -export SWIFT_TOOLCHAIN_PATH="$(swiftly use --print-location)" -``` +Otherwise set up it manully by exporting `LIB_SWIFT_PATH` environment variable. + +> The following command assume you already have [swiftly](https://github.com/swiftlang/swiftly) installed. -```fish -set -gx SWIFT_TOOLCHAIN_PATH (swiftly use --print-location) +```shell +export OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH="$(swiftly use --print-location)/usr/lib/swift" +# Or use the swift_static path +export OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH="$(swiftly use --print-location)/usr/lib/swift_static" ``` -Then run `swift build` +Alternatively, you can set the path using the Swift SDK location. For example: + +```shell +export OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH=~/.swiftpm/swift-sdks/swift-6.1.3-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.1.3-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/aarch64/usr/lib/swift_static +``` ## License From 05f519ccdd229b63c919965bb7fd19b7e199a4f1 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 2 Nov 2025 22:52:03 +0800 Subject: [PATCH 3/3] Update Package.resolved hash --- Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.resolved b/Package.resolved index 333c172..0d9e88e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "f0a7e4585ea57e5ac436c40b5e53baef22001edb75274a051d2606cc73d92795", + "originHash" : "24cd5d62b08d90c8d12d94ddb1d84e7d8da76f976a9b8642ccf50d81f29e8bb0", "pins" : [ { "identity" : "darwinprivateframeworks",