diff --git a/CMakeLists.txt b/CMakeLists.txt index b20dbbcdd..3f5265716 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,12 @@ set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) set(CMAKE_Swift_LANGUAGE_VERSION 5) set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) +# Generate build-ids +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" + AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_link_options("LINKER:--build-id=sha1") +endif() + # ensure Swift compiler can find _CSwiftScan add_compile_options($<$:-I$${CMAKE_CURRENT_SOURCE_DIR}/Sources/CSwiftScan/include>) diff --git a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift index 617021560..c0308b58d 100644 --- a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift +++ b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift @@ -106,6 +106,19 @@ extension GenericUnixToolchain { commandLine.appendFlag("-pie") } + // On some platforms we want to enable --build-id + if targetTriple.os == .linux + || targetTriple.os == .freeBSD + || targetTriple.os == .openbsd + || parsedOptions.hasArgument(.buildId) { + commandLine.appendFlag("-Xlinker") + if let buildId = parsedOptions.getLastArgument(.buildId)?.asSingle { + commandLine.appendFlag("--build-id=\(buildId)") + } else { + commandLine.appendFlag("--build-id") + } + } + let staticStdlib = parsedOptions.hasFlag(positive: .staticStdlib, negative: .noStaticStdlib, default: false) diff --git a/Sources/SwiftOptions/Options.swift b/Sources/SwiftOptions/Options.swift index 2e874dfb8..3768e4096 100644 --- a/Sources/SwiftOptions/Options.swift +++ b/Sources/SwiftOptions/Options.swift @@ -60,6 +60,8 @@ extension Option { public static let bridgingHeaderDirectoryForPrint: Option = Option("-bridging-header-directory-for-print", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "", helpText: "Directory for bridging header to be printed in compatibility header") public static let bridgingHeaderPchKey: Option = Option("-bridging-header-pch-key", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Cache Key for bridging header pch") public static let bsdk: Option = Option("-bsdk", .joinedOrSeparate, attributes: [.noDriver, .argumentIsPath], helpText: "path to the baseline SDK to import frameworks") + public static let buildIdEQ: Option = Option("-build-id=", .joined, alias: Option.buildId) + public static let buildId: Option = Option("-build-id", .joinedOrSeparate, metaVar: "", helpText: "Specify the build ID argument passed to linker") public static let buildModuleFromParseableInterface: Option = Option("-build-module-from-parseable-interface", .flag, alias: Option.compileModuleFromInterface, attributes: [.helpHidden, .frontend, .noDriver], group: .modes) public static let bypassBatchModeChecks: Option = Option("-bypass-batch-mode-checks", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Bypass checks for batch-mode errors.") public static let bypassResilience: Option = Option("-bypass-resilience-checks", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Ignore all checks for module resilience.") @@ -929,6 +931,8 @@ extension Option { Option.bridgingHeaderDirectoryForPrint, Option.bridgingHeaderPchKey, Option.bsdk, + Option.buildIdEQ, + Option.buildId, Option.buildModuleFromParseableInterface, Option.bypassBatchModeChecks, Option.bypassResilience,