Skip to content

Commit 21426f2

Browse files
mmllrKyle-Ye
andauthored
Add OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH support (#193)
Co-authored-by: Kyle <[email protected]>
1 parent 6300d9e commit 21426f2

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

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: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,21 @@ let isSPIBuild = envEnable("SPI_BUILD")
3535
let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
3636
let development = envEnable("OPENATTRIBUTEGRAPH_DEVELOPMENT", default: false)
3737

38-
let swiftBinPath = Context.environment["_"] ?? "/usr/bin/swift"
39-
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
40-
let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
41-
let includePath = SDKPath.appending("/usr/lib/swift")
38+
// From Swift toolchain being installed or from Swift SDK.
39+
func detectLibSwiftPath() -> String {
40+
guard let libSwiftPath = Context.environment["OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH"] else {
41+
// Fallback when LIB_SWIFT_PATH is not set
42+
let swiftBinPath = Context.environment["OPENATTRIBUTEGRAPH_BIN_SWIFT_PATH"] ?? Context.environment["_"] ?? "/usr/bin/swift"
43+
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
44+
let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
45+
return SDKPath.appending("/usr/lib/swift")
46+
}
47+
return libSwiftPath
48+
}
49+
let libSwiftPath = detectLibSwiftPath()
4250

4351
var sharedCSettings: [CSetting] = [
44-
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
52+
.unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)),
4553
.define("NDEBUG", .when(configuration: .release)),
4654
]
4755

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies: [
3838
```
3939

4040
> [!NOTE]
41+
>
4142
> - You may need to configure the Swift toolchain header for proper integration of OpenAttributeGraph
4243
> - By default, OpenAttributeGraphShims will use the private AttributeGraph as its implementation on Apple platforms
4344
@@ -49,6 +50,26 @@ For a simpler setup, you can use the prebuilt XCFramework available on the [rele
4950

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

53+
### Set up LIB_SWIFT_PATH on non-Darwin platform
54+
55+
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.
56+
57+
Otherwise set up it manully by exporting `LIB_SWIFT_PATH` environment variable.
58+
59+
> The following command assume you already have [swiftly](https://github.com/swiftlang/swiftly) installed.
60+
61+
```shell
62+
export OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH="$(swiftly use --print-location)/usr/lib/swift"
63+
# Or use the swift_static path
64+
export OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH="$(swiftly use --print-location)/usr/lib/swift_static"
65+
```
66+
67+
Alternatively, you can set the path using the Swift SDK location. For example:
68+
69+
```shell
70+
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
71+
```
72+
5273
## License
5374

5475
See LICENSE file - MIT

0 commit comments

Comments
 (0)