Skip to content

Commit 4d634f2

Browse files
authored
Merge pull request #680 from ahoppen/ahoppen/no-toolchain-rpath
Don’t include the toolchain rpath when installing swift-format
2 parents 67df696 + 7b6dc0e commit 4d634f2

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Package.swift

+20-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414
import Foundation
1515
import PackageDescription
1616

17+
// MARK: - Parse build arguments
18+
19+
func hasEnvironmentVariable(_ name: String) -> Bool {
20+
return ProcessInfo.processInfo.environment[name] != nil
21+
}
22+
23+
// When building the toolchain on the CI, don't add the CI's runpath for the
24+
// final build before installing.
25+
let installAction = hasEnvironmentVariable("SOURCEKIT_LSP_CI_INSTALL")
26+
27+
28+
// MARK: - Compute custom build settings
29+
30+
var swiftformatLinkSettings: [LinkerSetting] = []
31+
if installAction {
32+
swiftformatLinkSettings += [.unsafeFlags(["-no-toolchain-stdlib-rpath"], .when(platforms: [.linux, .android]))]
33+
}
34+
1735
let package = Package(
1836
name: "swift-format",
1937
platforms: [
@@ -106,7 +124,8 @@ let package = Package(
106124
.product(name: "ArgumentParser", package: "swift-argument-parser"),
107125
.product(name: "SwiftSyntax", package: "swift-syntax"),
108126
.product(name: "SwiftParser", package: "swift-syntax"),
109-
]
127+
],
128+
linkerSettings: swiftformatLinkSettings
110129
),
111130

112131
.testTarget(

build-script-helper.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ def get_swiftpm_options(
147147
return args
148148

149149

150-
def get_swiftpm_environment_variables():
150+
def get_swiftpm_environment_variables(action: str):
151151
env = dict(os.environ)
152152
env["SWIFTCI_USE_LOCAL_DEPS"] = "1"
153+
if action == "install":
154+
env["SOURCEKIT_LSP_CI_INSTALL"] = "1"
153155
return env
154156

155157

@@ -194,7 +196,7 @@ def invoke_swiftpm(
194196

195197
def build(args: argparse.Namespace) -> None:
196198
print("** Building swift-format **")
197-
env = get_swiftpm_environment_variables()
199+
env = get_swiftpm_environment_variables(args.action)
198200
invoke_swiftpm(
199201
package_path=args.package_path,
200202
swift_exec=args.swift_exec,
@@ -212,7 +214,7 @@ def build(args: argparse.Namespace) -> None:
212214

213215
def test(args: argparse.Namespace) -> None:
214216
print("** Testing swift-format **")
215-
env = get_swiftpm_environment_variables()
217+
env = get_swiftpm_environment_variables(args.action)
216218
invoke_swiftpm(
217219
package_path=args.package_path,
218220
swift_exec=args.swift_exec,
@@ -233,7 +235,7 @@ def install(args: argparse.Namespace) -> None:
233235

234236
print("** Installing swift-format **")
235237

236-
env = get_swiftpm_environment_variables()
238+
env = get_swiftpm_environment_variables(args.action)
237239
swiftpm_args = get_swiftpm_options(
238240
swift_exec=args.swift_exec,
239241
package_path=args.package_path,

0 commit comments

Comments
 (0)