Skip to content

Commit a7a9630

Browse files
authored
Merge pull request swiftlang#604 from swiftlang/owenv/rpath-origin
Define an RPATH_ORIGIN variable for constructing valid cross-platform paths
2 parents 972a844 + a35b067 commit a7a9630

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ public final class BuiltinMacros {
992992
public static let SWIFT_AUTOLINK_EXTRACT_OUTPUT_PATH = BuiltinMacros.declarePathMacro("SWIFT_AUTOLINK_EXTRACT_OUTPUT_PATH")
993993
public static let PLATFORM_REQUIRES_SWIFT_AUTOLINK_EXTRACT = BuiltinMacros.declareBooleanMacro("PLATFORM_REQUIRES_SWIFT_AUTOLINK_EXTRACT")
994994
public static let PLATFORM_REQUIRES_SWIFT_MODULEWRAP = BuiltinMacros.declareBooleanMacro("PLATFORM_REQUIRES_SWIFT_MODULEWRAP")
995+
public static let RPATH_ORIGIN = BuiltinMacros.declareStringMacro("RPATH_ORIGIN")
995996
public static let SWIFT_ABI_CHECKER_BASELINE_DIR = BuiltinMacros.declareStringMacro("SWIFT_ABI_CHECKER_BASELINE_DIR")
996997
public static let SWIFT_ABI_CHECKER_EXCEPTIONS_FILE = BuiltinMacros.declareStringMacro("SWIFT_ABI_CHECKER_EXCEPTIONS_FILE")
997998
public static let SWIFT_ABI_GENERATION_TOOL_OUTPUT_DIR = BuiltinMacros.declareStringMacro("SWIFT_ABI_GENERATION_TOOL_OUTPUT_DIR")
@@ -2162,6 +2163,7 @@ public final class BuiltinMacros {
21622163
SWIFT_AUTOLINK_EXTRACT_OUTPUT_PATH,
21632164
PLATFORM_REQUIRES_SWIFT_AUTOLINK_EXTRACT,
21642165
PLATFORM_REQUIRES_SWIFT_MODULEWRAP,
2166+
RPATH_ORIGIN,
21652167
SWIFT_ABI_CHECKER_BASELINE_DIR,
21662168
SWIFT_ABI_CHECKER_EXCEPTIONS_FILE,
21672169
SWIFT_ABI_GENERATION_TOOL_OUTPUT_DIR,

Sources/SWBCore/Settings/Settings.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,9 @@ private class SettingsBuilder {
25452545
sdkTable.push(BuiltinMacros.DYNAMIC_LIBRARY_EXTENSION, literal: imageFormat.dynamicLibraryExtension)
25462546
sdkTable.push(BuiltinMacros.PLATFORM_REQUIRES_SWIFT_AUTOLINK_EXTRACT, literal: imageFormat.requiresSwiftAutolinkExtract)
25472547
sdkTable.push(BuiltinMacros.PLATFORM_REQUIRES_SWIFT_MODULEWRAP, literal: imageFormat.requiresSwiftModulewrap)
2548+
if let origin = imageFormat.rpathOrigin {
2549+
sdkTable.push(BuiltinMacros.RPATH_ORIGIN, literal: origin)
2550+
}
25482551
}
25492552

25502553
// Add additional SDK default settings.

Sources/SWBGenericUnixPlatform/Specs/Unix.xcspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
SWIFT_INDEX_STORE_ENABLE = YES;
3636
// Testability is needed to generate code to invoke discovered XCTest tests
3737
SWIFT_ENABLE_TESTABILITY = YES;
38+
EXECUTABLE_SUFFIX = ".$(EXECUTABLE_EXTENSION)";
39+
EXECUTABLE_EXTENSION = "so";
40+
LD_DYLIB_INSTALL_NAME = "$(EXECUTABLE_PATH)";
3841
};
3942
},
4043

Sources/SWBUtil/ProcessInfo.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ extension ImageFormat {
219219
return true
220220
}
221221
}
222+
223+
public var usesRpaths: Bool {
224+
switch self {
225+
case .macho, .elf:
226+
return true
227+
case .pe:
228+
return false
229+
}
230+
}
231+
232+
public var rpathOrigin: String? {
233+
switch self {
234+
case .macho:
235+
return "@loader_path"
236+
case .elf:
237+
return "$ORIGIN"
238+
default:
239+
return nil
240+
}
241+
}
222242
}
223243

224244
extension FixedWidthInteger {

Tests/SWBBuildSystemTests/BuildOperationTests.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,9 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
426426
"UnitTestRunner",
427427
type: .swiftpmTestRunner,
428428
buildConfigurations: [
429-
TestBuildConfiguration("Debug",
430-
buildSettings: [:]),
429+
TestBuildConfiguration("Debug", buildSettings: [
430+
"LD_RUNPATH_SEARCH_PATHS": "$(RPATH_ORIGIN)",
431+
]),
431432
],
432433
buildPhases: [
433434
TestSourcesBuildPhase(),
@@ -442,8 +443,8 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
442443
type: .unitTest,
443444
buildConfigurations: [
444445
TestBuildConfiguration("Debug", buildSettings: [
445-
"DYLIB_INSTALL_NAME_BASE": "$ORIGIN",
446-
"LD_RUNPATH_SEARCH_PATHS": "@loader_path/",
446+
"LD_RUNPATH_SEARCH_PATHS": "$(RPATH_ORIGIN)",
447+
"LD_DYLIB_INSTALL_NAME": "MyTests.so"
447448
])
448449
],
449450
buildPhases: [
@@ -461,8 +462,8 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
461462
type: .dynamicLibrary,
462463
buildConfigurations: [
463464
TestBuildConfiguration("Debug", buildSettings: [
464-
"DYLIB_INSTALL_NAME_BASE": "$ORIGIN",
465-
"LD_RUNPATH_SEARCH_PATHS": "@loader_path/",
465+
"LD_RUNPATH_SEARCH_PATHS": "$(RPATH_ORIGIN)",
466+
"LD_DYLIB_INSTALL_NAME": "liblibrary.so",
466467

467468
// FIXME: Find a way to make these default
468469
"EXECUTABLE_PREFIX": "lib",
@@ -516,11 +517,11 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
516517

517518
do {
518519
let executionResult = try await Process.getOutput(url: URL(fileURLWithPath: projectDir.join("build").join("Debug\(destination.builtProductsDirSuffix)").join(core.hostOperatingSystem.imageFormat.executableName(basename: "UnitTestRunner")).str), arguments: [], environment: environment)
519-
#expect(String(decoding: executionResult.stdout, as: UTF8.self).contains("Executed 1 test, with 0 failures"))
520+
#expect(String(decoding: executionResult.stdout, as: UTF8.self).contains("Executed 1 test"))
520521
}
521522
do {
522523
let executionResult = try await Process.getOutput(url: URL(fileURLWithPath: projectDir.join("build").join("Debug\(destination.builtProductsDirSuffix)").join(core.hostOperatingSystem.imageFormat.executableName(basename: "UnitTestRunner")).str), arguments: ["--testing-library", "swift-testing"], environment: environment)
523-
#expect(String(decoding: executionResult.stderr, as: UTF8.self).contains("Test run with 1 test in 1 suite passed"))
524+
#expect(String(decoding: executionResult.stderr, as: UTF8.self).contains("Test run with 1 test "))
524525
}
525526
}
526527
}

0 commit comments

Comments
 (0)