Skip to content

Commit 8830bff

Browse files
committed
Add OPENATTRIBUTEGRAPH_LIB_SWIFT_PATH config
1 parent 5c78967 commit 8830bff

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

Package.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
1717
}
1818
}
1919

20-
func detectIncludePath() -> String {
21-
if let path = Context.environment["SWIFT_TOOLCHAIN_PATH"] {
22-
return path + "/usr/lib/swift"
23-
}
24-
let swiftBinPath = Context.environment["_"] ?? "/usr/bin/swift"
25-
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
26-
let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
27-
return SDKPath.appending("/usr/lib/swift")
28-
}
29-
3020
#if os(macOS)
3121
// 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.
3222
let buildForDarwinPlatform = envEnable("OPENSWIFTUI_BUILD_FOR_DARWIN_PLATFORM", default: true)
@@ -44,10 +34,22 @@ let isSPIBuild = envEnable("SPI_BUILD")
4434

4535
let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
4636
let development = envEnable("OPENATTRIBUTEGRAPH_DEVELOPMENT", default: false)
47-
let includePath = detectIncludePath()
37+
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()
4850

4951
var sharedCSettings: [CSetting] = [
50-
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
52+
.unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)),
5153
.define("NDEBUG", .when(configuration: .release)),
5254
]
5355

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,25 @@ For a simpler setup, you can use the prebuilt XCFramework available on the [rele
5050

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

53-
### Usage with ```swiftly````
53+
### Set up LIB_SWIFT_PATH on non-Darwin platform
5454

55-
If you have installed [Swiftly](https://github.com/swiftlang/swiftly) for managing your installed swift toolchains (Linux) set the following variable to your shell:
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 since the swift bin location be detected by `_` environment automatically.
5656

57-
```bash
58-
export SWIFT_TOOLCHAIN_PATH="$(swiftly use --print-location)"
59-
```
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.
6060
61-
```fish
62-
set -gx SWIFT_TOOLCHAIN_PATH (swiftly use --print-location)
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"
6365
```
6466

65-
Then run `swift build`
67+
Alternatively, you can set the path directly to 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+
```
6672

6773
## License
6874

0 commit comments

Comments
 (0)