Skip to content

Explicitly add rpath for lib_InternalSwiftSyntaxParser.dylib #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Foundation

/// If we are in a controlled CI environment, we can use internal compiler flags
/// to speed up the build or improve it.
let swiftSyntaxSwiftSettings: [SwiftSetting]
let swiftSyntaxSwiftSettings: [SwiftSetting]
if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil {
let groupFile = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
Expand All @@ -19,7 +19,20 @@ if ProcessInfo.processInfo.environment["SWIFT_BUILD_SCRIPT_ENVIRONMENT"] != nil
"-enforce-exclusivity=unchecked",
])]
} else {
swiftSyntaxSwiftSettings = []
swiftSyntaxSwiftSettings = []
}

/// If the `lib_InternalSwiftSyntaxParser.dylib` is not in the standard search
/// paths (which is the standard case on macOS),
/// `SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH` can be used to add a rpath at which
/// the parser lib should be searched.
let swiftSyntaxParserLinkerSettings: [LinkerSetting]
if let parserLibSearchPath = ProcessInfo.processInfo.environment["SWIFT_SYNTAX_PARSER_LIB_SEARCH_PATH"] {
swiftSyntaxParserLinkerSettings = [.unsafeFlags([
"-Xlinker", "-rpath", "-Xlinker", parserLibSearchPath
])]
} else {
swiftSyntaxParserLinkerSettings = []
}

let package = Package(
Expand Down Expand Up @@ -72,9 +85,14 @@ let package = Package(
"TokenSyntax.swift.gyb",
]
),
.target(name: "SwiftSyntaxParser", dependencies: ["SwiftSyntax"], exclude: [
"NodeDeclarationHash.swift.gyb"
]),
.target(
name: "SwiftSyntaxParser",
dependencies: ["SwiftSyntax"],
exclude: [
"NodeDeclarationHash.swift.gyb"
],
linkerSettings: swiftSyntaxParserLinkerSettings
),
.target(
name: "lit-test-helper",
dependencies: ["SwiftSyntax", "SwiftSyntaxParser"]
Expand Down
3 changes: 3 additions & 0 deletions build-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def __init__(
if verbose:
self.swiftpm_call.extend(["--verbose"])
self.verbose = verbose
self.toolchain = toolchain

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


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


Expand Down