From 8242a7825672a1053e9d1883f324539536636eaa Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 May 2020 16:00:17 -0700 Subject: [PATCH 1/7] [Build] Add support for building and importing the new Swift driver Add bootstrap and build support for building the new Swift driver and importing it (as a library) into SwiftPM. This is an incomplete stepping stone toward integrating the new driver. --- CMakeLists.txt | 2 ++ Sources/Build/BuildPlan.swift | 3 +++ Sources/Build/CMakeLists.txt | 3 ++- Utilities/bootstrap | 40 +++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 405b3c5606f..014b0019dc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,4 +42,6 @@ endif() find_package(dispatch QUIET) find_package(Foundation QUIET) +find_package(SwiftDriver CONFIG REQUIRED) + add_subdirectory(Sources) diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index 8cb750b0fee..d0e56db1629 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -16,6 +16,9 @@ import PackageLoading import Foundation import SPMBuildCore +// FIXME: JUST TO MAKE SURE WE CAN +import SwiftDriver + extension BuildParameters { /// Returns the directory to be used for module cache. public var moduleCache: AbsolutePath { diff --git a/Sources/Build/CMakeLists.txt b/Sources/Build/CMakeLists.txt index 373b1bc0fec..51290a0d3a7 100644 --- a/Sources/Build/CMakeLists.txt +++ b/Sources/Build/CMakeLists.txt @@ -17,7 +17,8 @@ target_link_libraries(Build PUBLIC TSCBasic PackageGraph LLBuildManifest - SPMBuildCore) + SPMBuildCore + SwiftDriver) # NOTE(compnerd) workaround for CMake not setting up include flags yet set_target_properties(Build PROPERTIES diff --git a/Utilities/bootstrap b/Utilities/bootstrap index 01eda47dcd8..a7cb6c00e5e 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -150,6 +150,8 @@ def parse_global_args(args): args.build_dir = os.path.abspath(args.build_dir) args.project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) args.tsc_source_dir = os.path.join(args.project_root, "swift-tools-support-core") + args.yams_source_dir = os.path.join(args.project_root, "..", "yams") + args.swift_driver_source_dir = os.path.join(args.project_root, "..", "swift-driver") args.source_root = os.path.join(args.project_root, "Sources") if platform.system() == 'Darwin': @@ -275,6 +277,8 @@ def build(args): build_llbuild(args) build_tsc(args) + build_yams(args) + build_swift_driver(args) build_swiftpm_with_cmake(args) build_swiftpm_with_swiftpm(args) @@ -294,6 +298,12 @@ def test(args): # Test TSC. call_swiftpm(args, cmd, args.tsc_source_dir) + # Test Yams. + call_swiftpm(args, cmd, args.yams_source_dir) + + # Test swift-driver. + call_swiftpm(args, cmd, args.swift_driver_source_dir) + # Test SwiftPM. call_swiftpm(args, cmd) @@ -440,6 +450,32 @@ def build_tsc(args): build_with_cmake(args, cmake_flags, args.tsc_source_dir, args.tsc_build_dir) +def build_yams(args): + note("Building Yams") + args.yams_build_dir = os.path.join(args.target_dir, "yams") + + cmake_flags = [] + if platform.system() == 'Darwin': + cmake_flags.append("-DCMAKE_C_FLAGS=-target x86_64-apple-macosx%s" % g_macos_deployment_target) + cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) + + build_with_cmake(args, cmake_flags, args.yams_source_dir, args.yams_build_dir) + +def build_swift_driver(args): + note("Building SwiftDriver") + args.swift_driver_build_dir = os.path.join(args.target_dir, "swift-driver") + + cmake_flags = [ + get_llbuild_cmake_arg(args), + "-DTSC_DIR=" + os.path.join(args.tsc_build_dir, "cmake/modules"), + "-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"), + ] + if platform.system() == 'Darwin': + cmake_flags.append("-DCMAKE_C_FLAGS=-target x86_64-apple-macosx%s" % g_macos_deployment_target) + cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) + + build_with_cmake(args, cmake_flags, args.swift_driver_source_dir, args.swift_driver_build_dir) + def build_swiftpm_with_cmake(args): """Builds SwiftPM using CMake.""" note("Building SwiftPM (with CMake)") @@ -447,6 +483,8 @@ def build_swiftpm_with_cmake(args): cmake_flags = [ get_llbuild_cmake_arg(args), "-DTSC_DIR=" + os.path.join(args.tsc_build_dir, "cmake/modules"), + "-DYams_DIR=" + os.path.join(args.yams_build_dir, "cmake/modules"), + "-DSwiftDriver_DIR=" + os.path.join(args.swift_driver_build_dir, "cmake/modules"), ] if platform.system() == 'Darwin': @@ -539,6 +577,8 @@ def get_swiftpm_env_cmd(args): os.path.join(args.bootstrap_dir, "lib"), os.path.join(args.tsc_build_dir, "lib"), os.path.join(args.llbuild_build_dir, "lib"), + os.path.join(args.yams_build_dir, "lib"), + os.path.join(args.swift_driver_build_dir, "lib"), ]) if platform.system() == 'Darwin': From 705c1fff374dbb5070ff570ba685771faa4a788b Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 May 2020 22:14:23 -0700 Subject: [PATCH 2/7] Fix bootstrap and build involving the new Swift driver. Add missing dependencies, rpaths, etc. to get SwiftPM bootstrapping with the new Swift driver. There is no actual integration of SwiftDriver beyond the import. --- CMakeLists.txt | 1 + Package.swift | 4 +++- Sources/Build/BuildPlan.swift | 4 +++- Sources/Build/CMakeLists.txt | 2 ++ Utilities/bootstrap | 16 ++++++++++++---- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 014b0019dc2..250a4f21ed8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ endif() find_package(dispatch QUIET) find_package(Foundation QUIET) +find_package(Yams CONFIG REQUIRED) find_package(SwiftDriver CONFIG REQUIRED) add_subdirectory(Sources) diff --git a/Package.swift b/Package.swift index c21b858538e..5244b1fb9f4 100644 --- a/Package.swift +++ b/Package.swift @@ -127,7 +127,7 @@ let package = Package( .target( /** Builds Modules and Products */ name: "Build", - dependencies: ["SwiftToolsSupport-auto", "SPMBuildCore", "PackageGraph", "LLBuildManifest"]), + dependencies: ["SwiftToolsSupport-auto", "SPMBuildCore", "PackageGraph", "LLBuildManifest", "SwiftDriver"]), .target( /** Support for building using Xcode's build system */ name: "XCBuildSupport", @@ -253,9 +253,11 @@ if ProcessInfo.processInfo.environment["SWIFTPM_LLBUILD_FWK"] == nil { if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { package.dependencies += [ .package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("master")), + .package(url: "https://github.com/apple/swift-driver.git", .branch("master")), ] } else { package.dependencies += [ .package(path: "./swift-tools-support-core"), + .package(path: "../swift-driver"), ] } diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index d0e56db1629..0928c06920a 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -19,6 +19,8 @@ import SPMBuildCore // FIXME: JUST TO MAKE SURE WE CAN import SwiftDriver +public typealias FileSystem = TSCBasic.FileSystem + extension BuildParameters { /// Returns the directory to be used for module cache. public var moduleCache: AbsolutePath { @@ -1720,7 +1722,7 @@ public class BuildPlan { // Check that it supports macOS. guard let library = info.libraries.first(where: { - $0.platform == "macos" && $0.architectures.contains(Triple.Arch.x86_64.rawValue) + $0.platform == "macos" && $0.architectures.contains(SPMBuildCore.Triple.Arch.x86_64.rawValue) }) else { diagnostics.emit(error: """ artifact '\(target.name)' does not support the target platform and architecture \ diff --git a/Sources/Build/CMakeLists.txt b/Sources/Build/CMakeLists.txt index 51290a0d3a7..ae63391e41a 100644 --- a/Sources/Build/CMakeLists.txt +++ b/Sources/Build/CMakeLists.txt @@ -18,6 +18,8 @@ target_link_libraries(Build PUBLIC PackageGraph LLBuildManifest SPMBuildCore + CYaml + Yams SwiftDriver) # NOTE(compnerd) workaround for CMake not setting up include flags yet diff --git a/Utilities/bootstrap b/Utilities/bootstrap index a7cb6c00e5e..8160c46cc98 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -476,6 +476,13 @@ def build_swift_driver(args): build_with_cmake(args, cmake_flags, args.swift_driver_source_dir, args.swift_driver_build_dir) +def add_rpath_for_cmake_build(args, rpath): + "Adds the given rpath to the CMake-built swift-build" + swift_build = os.path.join(args.bootstrap_dir, "bin/swift-build") + add_rpath_cmd = ["install_name_tool", "-add_rpath", rpath, swift_build] + note(' '.join(add_rpath_cmd)) + subprocess.call(add_rpath_cmd, stderr=subprocess.PIPE) + def build_swiftpm_with_cmake(args): """Builds SwiftPM using CMake.""" note("Building SwiftPM (with CMake)") @@ -494,10 +501,11 @@ def build_swiftpm_with_cmake(args): build_with_cmake(args, cmake_flags, args.project_root, args.bootstrap_dir) if args.llbuild_link_framework: - swift_build = os.path.join(args.bootstrap_dir, "bin/swift-build") - add_rpath_cmd = ["install_name_tool", "-add_rpath", args.llbuild_build_dir, swift_build] - note(' '.join(add_rpath_cmd)) - subprocess.call(add_rpath_cmd, stderr=subprocess.PIPE) + add_rpath_for_cmake_build(args, args.llbuild_build_dir) + + add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "Sources", "Yams")) + add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "Sources", "CYaml")) + add_rpath_for_cmake_build(args, os.path.join(args.swift_driver_build_dir, "lib")) def build_swiftpm_with_swiftpm(args): """Builds SwiftPM using the version of SwiftPM built with CMake.""" From 1f1e909013bd2886ac86acd8ed8d5e219a953e82 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 May 2020 23:29:38 -0700 Subject: [PATCH 3/7] [Swift driver] Add support for the integrated Swift driver Add the command-line flag `--use-integrated-swift-driver` to use the integrated Swift driver to create jobs rather than shelling out to the driver executable. --- Sources/Build/BuildPlan.swift | 39 ++++++++++-- Sources/Build/ManifestBuilder.swift | 67 ++++++++++++++++++++- Sources/Commands/Options.swift | 4 ++ Sources/Commands/SwiftTool.swift | 5 ++ Sources/LLBuildManifest/BuildManifest.swift | 1 + Sources/SPMBuildCore/BuildParameters.swift | 6 ++ 6 files changed, 115 insertions(+), 7 deletions(-) diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index 0928c06920a..79cde67dbb7 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -16,11 +16,6 @@ import PackageLoading import Foundation import SPMBuildCore -// FIXME: JUST TO MAKE SURE WE CAN -import SwiftDriver - -public typealias FileSystem = TSCBasic.FileSystem - extension BuildParameters { /// Returns the directory to be used for module cache. public var moduleCache: AbsolutePath { @@ -677,6 +672,38 @@ public final class SwiftTargetBuildDescription { return args } + public func emitCommandLine() -> [String] { + var result: [String] = [] + result.append(buildParameters.toolchain.swiftCompiler.pathString) + + result.append("-module-name") + result.append(target.c99name) +// result.append("-incremental") + result.append("-emit-dependencies") + result.append("-emit-module") + result.append("-emit-module-path") + result.append(moduleOutputPath.pathString) + + result.append("-output-file-map") + // FIXME: Eliminate side effect. + result.append(try! writeOutputFileMap().pathString) + if target.type == .library || target.type == .test { + result.append("-parse-as-library") + } + // FIXME: WMO + + result.append("-c") + for source in target.sources.paths { + result.append(source.pathString) + } + + result.append("-I") + result.append(buildParameters.buildPath.pathString) + + result += compileArguments() + return result + } + /// Command-line for emitting just the Swift module. public func emitModuleCommandLine() -> [String] { assert(buildParameters.emitSwiftModuleSeparately) @@ -1722,7 +1749,7 @@ public class BuildPlan { // Check that it supports macOS. guard let library = info.libraries.first(where: { - $0.platform == "macos" && $0.architectures.contains(SPMBuildCore.Triple.Arch.x86_64.rawValue) + $0.platform == "macos" && $0.architectures.contains(Triple.Arch.x86_64.rawValue) }) else { diagnostics.emit(error: """ artifact '\(target.name)' does not support the target platform and architecture \ diff --git a/Sources/Build/ManifestBuilder.swift b/Sources/Build/ManifestBuilder.swift index 4bcb172e8cd..e09ded35689 100644 --- a/Sources/Build/ManifestBuilder.swift +++ b/Sources/Build/ManifestBuilder.swift @@ -17,6 +17,8 @@ import PackageModel import PackageGraph import SPMBuildCore +import SwiftDriver + public class LLBuildManifestBuilder { public enum TargetKind { case main @@ -177,7 +179,9 @@ extension LLBuildManifestBuilder { let moduleNode = Node.file(target.moduleOutputPath) let cmdOutputs = objectNodes + [moduleNode] - if buildParameters.emitSwiftModuleSeparately { + if buildParameters.useIntegratedSwiftDriver { + addSwiftCmdsViaIntegratedDriver(target, inputs: inputs, objectNodes: objectNodes, moduleNode: moduleNode) + } else if buildParameters.emitSwiftModuleSeparately { addSwiftCmdsEmitSwiftModuleSeparately(target, inputs: inputs, objectNodes: objectNodes, moduleNode: moduleNode) } else { addCmdWithBuiltinSwiftTool(target, inputs: inputs, cmdOutputs: cmdOutputs) @@ -187,6 +191,49 @@ extension LLBuildManifestBuilder { addModuleWrapCmd(target) } + private func addSwiftCmdsViaIntegratedDriver( + _ target: SwiftTargetBuildDescription, + inputs: [Node], + objectNodes: [Node], + moduleNode: Node + ) { + do { + var driver = try Driver(args: target.emitCommandLine()) + let jobs = try driver.planBuild() + let resolver = try ArgsResolver() + + for job in jobs { + let datool = try resolver.resolve(.path(job.tool)) + let commandLine = try job.commandLine.map{ try resolver.resolve($0) } + let arguments = [datool] + commandLine + + let jobInputs = job.inputs.map { $0.resolveToNode() } + let jobOutputs = job.outputs.map { $0.resolveToNode() } + + let displayName: String + if !job.displayInputs.isEmpty { + displayName = job.displayInputs[0].file.name + } else if !job.inputs.isEmpty { + displayName = job.inputs[0].file.name + } else if !job.outputs.isEmpty { + displayName = job.outputs[0].file.name + } else { + displayName = "???" + } + + manifest.addShellCmd( + name: target.moduleOutputPath.pathString, + description: "Compile \(target.target.name) - \(displayName)", + inputs: inputs + jobInputs, + outputs: jobOutputs, + args: arguments + ) + } + } catch { + fatalError("\(error)") + } + } + private func addSwiftCmdsEmitSwiftModuleSeparately( _ target: SwiftTargetBuildDescription, inputs: [Node], @@ -592,3 +639,21 @@ extension LLBuildManifestBuilder { plan.buildParameters.buildPath.appending(component: path.basename) } } + +extension TypedVirtualPath { + func resolveToNode() -> Node { + switch file { + case .relative(let path): + return Node.file(localFileSystem.currentWorkingDirectory!.appending(path)) + + case .absolute(let path): + return Node.file(path) + + case .temporary(let path): + return Node.virtual(path.pathString) + + case .standardInput, .standardOutput: + fatalError("Cannot handle standard input or output") + } + } +} diff --git a/Sources/Commands/Options.swift b/Sources/Commands/Options.swift index c2b40c6e3df..93a3f8eef00 100644 --- a/Sources/Commands/Options.swift +++ b/Sources/Commands/Options.swift @@ -93,6 +93,10 @@ public class ToolOptions { /// Emit the Swift module separately from the object files. public var emitSwiftModuleSeparately: Bool = false + /// Whether to use the integrated Swift driver rather than shelling out + /// to a separate process. + public var useIntegratedSwiftDriver: Bool = false + /// The build system to use. public var buildSystem: BuildSystemKind = .native diff --git a/Sources/Commands/SwiftTool.swift b/Sources/Commands/SwiftTool.swift index f3ef3ba6c36..8a1c8f1edc8 100644 --- a/Sources/Commands/SwiftTool.swift +++ b/Sources/Commands/SwiftTool.swift @@ -450,6 +450,10 @@ public class SwiftTool { option: parser.add(option: "--emit-swift-module-separately", kind: Bool.self, usage: nil), to: { $0.emitSwiftModuleSeparately = $1 }) + binder.bind( + option: parser.add(option: "--use-integrated-swift-driver", kind: Bool.self, usage: nil), + to: { $0.useIntegratedSwiftDriver = $1 }) + binder.bind( option: parser.add(option: "--build-system", kind: BuildSystemKind.self, usage: nil), to: { $0.buildSystem = $1 }) @@ -791,6 +795,7 @@ public class SwiftTool { enableParseableModuleInterfaces: options.shouldEnableParseableModuleInterfaces, enableTestDiscovery: options.enableTestDiscovery, emitSwiftModuleSeparately: options.emitSwiftModuleSeparately, + useIntegratedSwiftDriver: options.useIntegratedSwiftDriver, isXcodeBuildSystemEnabled: options.buildSystem == .xcode ) }) diff --git a/Sources/LLBuildManifest/BuildManifest.swift b/Sources/LLBuildManifest/BuildManifest.swift index 381a0178ed3..a5afc9c7ea0 100644 --- a/Sources/LLBuildManifest/BuildManifest.swift +++ b/Sources/LLBuildManifest/BuildManifest.swift @@ -155,6 +155,7 @@ public struct BuildManifest { isLibrary: isLibrary, WMO: WMO ) + commands[name] = Command(name: name, tool: tool) } } diff --git a/Sources/SPMBuildCore/BuildParameters.swift b/Sources/SPMBuildCore/BuildParameters.swift index 073149e0c04..289c634ba65 100644 --- a/Sources/SPMBuildCore/BuildParameters.swift +++ b/Sources/SPMBuildCore/BuildParameters.swift @@ -85,6 +85,10 @@ public struct BuildParameters: Encodable { /// module to finish building. public var emitSwiftModuleSeparately: Bool + /// Whether to use the integrated Swift driver rather than shelling out + /// to a separate process. + public var useIntegratedSwiftDriver: Bool + /// Whether to create dylibs for dynamic library products. public var shouldCreateDylibForDynamicProducts: Bool @@ -130,6 +134,7 @@ public struct BuildParameters: Encodable { enableParseableModuleInterfaces: Bool = false, enableTestDiscovery: Bool = false, emitSwiftModuleSeparately: Bool = false, + useIntegratedSwiftDriver: Bool = false, isXcodeBuildSystemEnabled: Bool = false ) { self.dataPath = dataPath @@ -149,6 +154,7 @@ public struct BuildParameters: Encodable { self.enableParseableModuleInterfaces = enableParseableModuleInterfaces self.enableTestDiscovery = enableTestDiscovery self.emitSwiftModuleSeparately = emitSwiftModuleSeparately + self.useIntegratedSwiftDriver = useIntegratedSwiftDriver self.isXcodeBuildSystemEnabled = isXcodeBuildSystemEnabled } From 6061214f5df374cf83ff1cd32d83ed89f842dcba Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Sat, 9 May 2020 22:29:33 -0700 Subject: [PATCH 4/7] [Integrated Swift driver] Provide unique command names and better descriptions Unique command names allow us to successfully bootstrap using the integrated Swift driver. Using the Swift driver's job kind to provide more detailed descriptions for the various shell commands generated by the Swift driver, improving the output. --- Sources/Build/BuildPlan.swift | 2 +- Sources/Build/ManifestBuilder.swift | 65 ++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/Sources/Build/BuildPlan.swift b/Sources/Build/BuildPlan.swift index 79cde67dbb7..aa12714bf17 100644 --- a/Sources/Build/BuildPlan.swift +++ b/Sources/Build/BuildPlan.swift @@ -678,7 +678,7 @@ public final class SwiftTargetBuildDescription { result.append("-module-name") result.append(target.c99name) -// result.append("-incremental") + result.append("-incremental") result.append("-emit-dependencies") result.append("-emit-module") result.append("-emit-module-path") diff --git a/Sources/Build/ManifestBuilder.swift b/Sources/Build/ManifestBuilder.swift index e09ded35689..b2d99d91d95 100644 --- a/Sources/Build/ManifestBuilder.swift +++ b/Sources/Build/ManifestBuilder.swift @@ -198,6 +198,8 @@ extension LLBuildManifestBuilder { moduleNode: Node ) { do { + // Use the integrated Swift driver to compute the set of frontend + // jobs needed to build this Swift target. var driver = try Driver(args: target.emitCommandLine()) let jobs = try driver.planBuild() let resolver = try ArgsResolver() @@ -210,20 +212,59 @@ extension LLBuildManifestBuilder { let jobInputs = job.inputs.map { $0.resolveToNode() } let jobOutputs = job.outputs.map { $0.resolveToNode() } - let displayName: String - if !job.displayInputs.isEmpty { - displayName = job.displayInputs[0].file.name - } else if !job.inputs.isEmpty { - displayName = job.inputs[0].file.name - } else if !job.outputs.isEmpty { - displayName = job.outputs[0].file.name - } else { - displayName = "???" + // Compute a description for this particular job. The output + // is intended to match that of the built-in Swift compiler + // tool so that the use of the integrated driver is mostly + // an implementation detail. + let moduleName = target.target.c99name + let description: String + switch job.kind { + case .compile: + description = "Compiling \(moduleName) \(job.displayInputs.first!.file.name)" + + case .mergeModule: + description = "Merging module \(moduleName)" + + case .link: + description = "Linking \(moduleName)" + + case .generateDSYM: + description = "Generating dSYM for module \(moduleName)" + + case .autolinkExtract: + description = "Extracting autolink information for module \(moduleName)" + + case .emitModule: + description = "Emitting module for \(moduleName)" + + case .generatePCH: + description = "Compiling bridging header \(job.displayInputs.first!.file.name)" + + case .generatePCM: + description = "Compiling Clang module \(job.displayInputs.first!.file.name)" + + case .interpret: + description = "Interpreting \(job.displayInputs.first!.file.name)" + + case .repl: + description = "Executing Swift REPL" + + case .verifyDebugInfo: + description = "Verifying debug information for module \(moduleName)" + + case .printTargetInfo: + description = "Gathering target information for module \(moduleName)" + + case .versionRequest: + description = "Getting Swift version information" + + case .help: + description = "Swift help" } manifest.addShellCmd( - name: target.moduleOutputPath.pathString, - description: "Compile \(target.target.name) - \(displayName)", + name: jobOutputs.first!.name, + description: description, inputs: inputs + jobInputs, outputs: jobOutputs, args: arguments @@ -641,6 +682,8 @@ extension LLBuildManifestBuilder { } extension TypedVirtualPath { + /// Resolve a typed virtual path provided by the Swift driver to + /// a node in the build graph. func resolveToNode() -> Node { switch file { case .relative(let path): From 9329793fea3f25b1f139c977c31ab6143ca8c493 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 12 May 2020 15:03:03 -0700 Subject: [PATCH 5/7] [bootstrap] Don't test Yams or SwiftDriver as part of bootstrap --- Utilities/bootstrap | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Utilities/bootstrap b/Utilities/bootstrap index 8160c46cc98..9383d10136e 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -298,12 +298,6 @@ def test(args): # Test TSC. call_swiftpm(args, cmd, args.tsc_source_dir) - # Test Yams. - call_swiftpm(args, cmd, args.yams_source_dir) - - # Test swift-driver. - call_swiftpm(args, cmd, args.swift_driver_source_dir) - # Test SwiftPM. call_swiftpm(args, cmd) From e836957b62fafdf0e7ab594d323444a2322e03bf Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 12 May 2020 16:02:51 -0700 Subject: [PATCH 6/7] [Bootstrap] Fix Linux bootstrap with integrated Swift driver --- Utilities/bootstrap | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Utilities/bootstrap b/Utilities/bootstrap index 9383d10136e..0b3da96f5d2 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -452,6 +452,11 @@ def build_yams(args): if platform.system() == 'Darwin': cmake_flags.append("-DCMAKE_C_FLAGS=-target x86_64-apple-macosx%s" % g_macos_deployment_target) cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target) + else: + cmake_flags += [ + get_dispatch_cmake_arg(args), + get_foundation_cmake_arg(args), + ] build_with_cmake(args, cmake_flags, args.yams_source_dir, args.yams_build_dir) @@ -497,9 +502,9 @@ def build_swiftpm_with_cmake(args): if args.llbuild_link_framework: add_rpath_for_cmake_build(args, args.llbuild_build_dir) - add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "Sources", "Yams")) - add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "Sources", "CYaml")) - add_rpath_for_cmake_build(args, os.path.join(args.swift_driver_build_dir, "lib")) + if platform.system() == "Darwin": + add_rpath_for_cmake_build(args, os.path.join(args.yams_build_dir, "lib")) + add_rpath_for_cmake_build(args, os.path.join(args.swift_driver_build_dir, "lib")) def build_swiftpm_with_swiftpm(args): """Builds SwiftPM using the version of SwiftPM built with CMake.""" From c818cdb7d9cbef9d8bff6e0d96cbce9bd77b6bd7 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 12 May 2020 17:19:14 -0700 Subject: [PATCH 7/7] [Integrated Swift driver] Use the tools from SwiftPM's toolchain. The Swift driver's toolchain and SwiftPM's toolchain might have slightly different paths in them. For now, map to SwiftPM's toolchain. There should be a more direct way to rectify these. --- Sources/Build/ManifestBuilder.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/Build/ManifestBuilder.swift b/Sources/Build/ManifestBuilder.swift index b2d99d91d95..505e0c9ec0a 100644 --- a/Sources/Build/ManifestBuilder.swift +++ b/Sources/Build/ManifestBuilder.swift @@ -205,7 +205,19 @@ extension LLBuildManifestBuilder { let resolver = try ArgsResolver() for job in jobs { - let datool = try resolver.resolve(.path(job.tool)) + // Figure out which tool we are using. + // FIXME: This feels like a hack. + var datool: String + switch job.kind { + case .compile, .mergeModule, .emitModule, .generatePCH, + .generatePCM, .interpret, .repl, .printTargetInfo, + .versionRequest: + datool = buildParameters.toolchain.swiftCompiler.pathString + + case .autolinkExtract, .generateDSYM, .help, .link, .verifyDebugInfo: + datool = try resolver.resolve(.path(job.tool)) + } + let commandLine = try job.commandLine.map{ try resolver.resolve($0) } let arguments = [datool] + commandLine