Skip to content

Commit aa38592

Browse files
authored
Merge pull request #371 from ahoppen/pr/add-parser-lib-rpath
Explicitly add rpath for lib_InternalSwiftSyntaxParser.dylib
2 parents 103d677 + 4f33e36 commit aa38592

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Package.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Foundation
55

66
/// If we are in a controlled CI environment, we can use internal compiler flags
77
/// to speed up the build or improve it.
8-
let swiftSyntaxSwiftSettings: [SwiftSetting]
8+
let swiftSyntaxSwiftSettings: [SwiftSetting]
99
if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil {
1010
let groupFile = URL(fileURLWithPath: #file)
1111
.deletingLastPathComponent()
@@ -19,7 +19,20 @@ if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil
1919
"-enforce-exclusivity=unchecked",
2020
])]
2121
} else {
22-
swiftSyntaxSwiftSettings = []
22+
swiftSyntaxSwiftSettings = []
23+
}
24+
25+
/// If the `lib_InternalSwiftSyntaxParser.dylib` is not in the standard search
26+
/// paths (which is the standard case on macOS),
27+
/// `SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH` can be used to add a rpath at which
28+
/// the parser lib should be searched.
29+
let swiftSyntaxParserLinkerSettings: [LinkerSetting]
30+
if let parserLibSearchPath = ProcessInfo.processInfo.environment["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] {
31+
swiftSyntaxParserLinkerSettings = [.unsafeFlags([
32+
"-Xlinker", "-rpath", "-Xlinker", parserLibSearchPath
33+
])]
34+
} else {
35+
swiftSyntaxParserLinkerSettings = []
2336
}
2437

2538
let package = Package(
@@ -72,9 +85,14 @@ let package = Package(
7285
"TokenSyntax.swift.gyb",
7386
]
7487
),
75-
.target(name: "SwiftSyntaxParser", dependencies: ["SwiftSyntax"], exclude: [
76-
"NodeDeclarationHash.swift.gyb"
77-
]),
88+
.target(
89+
name: "SwiftSyntaxParser",
90+
dependencies: ["SwiftSyntax"],
91+
exclude: [
92+
"NodeDeclarationHash.swift.gyb"
93+
],
94+
linkerSettings: swiftSyntaxParserLinkerSettings
95+
),
7896
.target(
7997
name: "lit-test-helper",
8098
dependencies: ["SwiftSyntax", "SwiftSyntaxParser"]

build-script.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ def __init__(
364364
if verbose:
365365
self.swiftpm_call.extend(["--verbose"])
366366
self.verbose = verbose
367+
self.toolchain = toolchain
367368

368369
def build(self, product_name):
369370
print("** Building " + product_name + " **")
@@ -374,6 +375,7 @@ def build(self, product_name):
374375
env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1"
375376
# Tell other projects in the unified build to use local dependencies
376377
env["SWIFTCI_USE_LOCAL_DEPS"] = "1"
378+
env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = os.path.join(self.toolchain, "lib", "swift", "macosx")
377379
check_call(command, env=env, verbose=self.verbose)
378380

379381

@@ -572,6 +574,7 @@ def run_xctests(toolchain, build_dir, multiroot_data_file, release, verbose):
572574
env["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] = "1"
573575
# Tell other projects in the unified build to use local dependencies
574576
env["SWIFTCI_USE_LOCAL_DEPS"] = "1"
577+
env["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] = os.path.join(toolchain, "lib", "swift", "macosx")
575578
return call(swiftpm_call, env=env, verbose=verbose) == 0
576579

577580

0 commit comments

Comments
 (0)