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", diff --git a/Package.swift b/Package.swift index 32129fd..a0a4575 100644 --- a/Package.swift +++ b/Package.swift @@ -35,13 +35,21 @@ 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") +// 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 e1abf2b..d6c7f1d 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,26 @@ 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. +### Set up LIB_SWIFT_PATH on non-Darwin platform + +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. + +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. + +```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" +``` + +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 See LICENSE file - MIT