Skip to content

Commit 5c78967

Browse files
committed
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.
1 parent 6300d9e commit 5c78967

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Package.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ 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+
2030
#if os(macOS)
2131
// 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.
2232
let buildForDarwinPlatform = envEnable("OPENSWIFTUI_BUILD_FOR_DARWIN_PLATFORM", default: true)
@@ -34,11 +44,7 @@ let isSPIBuild = envEnable("SPI_BUILD")
3444

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

4349
var sharedCSettings: [CSetting] = [
4450
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),

README.md

Lines changed: 15 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,20 @@ 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+
### Usage with ```swiftly````
54+
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:
56+
57+
```bash
58+
export SWIFT_TOOLCHAIN_PATH="$(swiftly use --print-location)"
59+
```
60+
61+
```fish
62+
set -gx SWIFT_TOOLCHAIN_PATH (swiftly use --print-location)
63+
```
64+
65+
Then run `swift build`
66+
5267
## License
5368

5469
See LICENSE file - MIT

0 commit comments

Comments
 (0)