Skip to content

Rely on libSwiftScan for dependency scanning actions. #427

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 20 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0ed598f
[Explicit Module Builds] Switch the dependency scanning action to use…
artemcm Dec 10, 2020
d26b4ff
[Explicit Module Builds] Remove Placeholder Dependency Resolution
artemcm Jan 5, 2021
eaa0bb4
[Explicit Module Builds] When generating scanner invocations, escape …
artemcm Jan 7, 2021
d139f3c
Remove the _CSwiftDriver target in favour of CSwiftScan
artemcm Jan 7, 2021
b20b845
Revert "[Explicit Module Builds] Remove Placeholder Dependency Resolu…
artemcm Jan 7, 2021
45da834
[Explicit Module Builds] Make sure to dispose/free memory of batch sc…
artemcm Jan 7, 2021
ad6fc11
[Explicit Module Builds] Add libSwiftScan parallel scanning query test.
artemcm Jan 8, 2021
10f68ac
[Explicit Module Builds] Avoid re-visiting Swift modules in the depen…
artemcm Jan 11, 2021
cc50326
Args resolver: createFileList does not need the option to quote paths…
artemcm Jan 11, 2021
9284886
[Explicit Module Builds] Add option to invoke the command-line execut…
artemcm Jan 11, 2021
446667a
[Dependency Scanning] Use a synchronous dispatch queue for accesses t…
artemcm Jan 14, 2021
5229662
Do not add extra option to quote paths when resolving arguments for f…
artemcm Jan 14, 2021
5198ed1
[Dependency Scanning] Do not dlopen the scanning library when not used.
artemcm Jan 14, 2021
df867f9
[Dependency Scanning] Adapt to the TextualVirtualPath interface when …
artemcm Jan 25, 2021
1ce0c50
[Explicit Module Build] Correctly discern libSwiftScan location in th…
artemcm Jan 26, 2021
134cf51
Add diagnostic output to dependency scanning test.
artemcm Jan 26, 2021
7b0a9c4
Dependency Scanning test: correctly reflect that the expected number …
artemcm Jan 26, 2021
33be2f1
Use target-platform-specific shared library file extension. (.so exce…
artemcm Jan 26, 2021
c931c60
Compute the host triple using `-print-target-info` and use it to reso…
artemcm Jan 26, 2021
5848895
[Dependency Scanning] Fallback to calling the `swift-frontend` for de…
artemcm Feb 5, 2021
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ if(CMAKE_VERSION VERSION_LESS 3.16)
set(CMAKE_LINK_LIBRARY_FLAG "-l")
endif()

# ensure Swift compiler can find _CSwiftDriver
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-I$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/Sources/_CSwiftDriver/include>)
# ensure Swift compiler can find _CSwiftScan
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-I$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/Sources/CSwiftScan/include>)

set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

Expand Down
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ let package = Package(
targets: ["SwiftDriverExecution"]),
],
targets: [
.target(name: "_CSwiftDriver"),

/// C modules wrapper for _InternalLibSwiftScan.
.target(name: "CSwiftScan"),

/// The driver library.
.target(
name: "SwiftDriver",
dependencies: ["SwiftOptions", "SwiftToolsSupport-auto", "Yams", "_CSwiftDriver"]),
dependencies: ["SwiftOptions", "SwiftToolsSupport-auto",
"CSwiftScan", "Yams"]),

/// The execution library.
.target(
Expand Down
2 changes: 1 addition & 1 deletion Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_subdirectory(_CSwiftDriver)
add_subdirectory(CSwiftScan)
add_subdirectory(SwiftOptions)
add_subdirectory(SwiftDriver)
add_subdirectory(SwiftDriverExecution)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_library(CSwiftDriver STATIC
_CSwiftDriverImpl.c)
add_library(CSwiftScan STATIC
CSwiftScanImpl.c)
3 changes: 3 additions & 0 deletions Sources/CSwiftScan/CSwiftScanImpl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file is here to prevent the package manager from warning about a
// target with no sources.
#include "include/swiftscan_header.h"
4 changes: 4 additions & 0 deletions Sources/CSwiftScan/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CSwiftScan {
header "swiftscan_header.h"
export *
}
208 changes: 208 additions & 0 deletions Sources/CSwiftScan/include/swiftscan_header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
//===-- swiftscan_header.h - C API for Swift Dependency Scanning --*- C -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_C_DEPENDENCY_SCAN_H
#define SWIFT_C_DEPENDENCY_SCAN_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#define SWIFTSCAN_VERSION_MAJOR 0
#define SWIFTSCAN_VERSION_MINOR 1

//=== Public Scanner Data Types -------------------------------------------===//

typedef struct {
const void *data;
size_t length;
} swiftscan_string_ref_t;

typedef struct {
swiftscan_string_ref_t *strings;
size_t count;
} swiftscan_string_set_t;

typedef enum {
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0,
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1,
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2,
SWIFTSCAN_DEPENDENCY_INFO_CLANG = 3
} swiftscan_dependency_info_kind_t;

typedef struct swiftscan_module_details_s *swiftscan_module_details_t;
typedef struct swiftscan_dependency_info_s *swiftscan_dependency_info_t;
typedef struct swiftscan_dependency_graph_s *swiftscan_dependency_graph_t;
typedef struct swiftscan_import_set_s *swiftscan_import_set_t;
typedef struct {
swiftscan_dependency_info_t *modules;
size_t count;
} swiftscan_dependency_set_t;

//=== Batch Scan Input Specification --------------------------------------===//

typedef struct swiftscan_batch_scan_entry_s *swiftscan_batch_scan_entry_t;
typedef struct {
swiftscan_batch_scan_entry_t *modules;
size_t count;
} swiftscan_batch_scan_input_t;
typedef struct {
swiftscan_dependency_graph_t *results;
size_t count;
} swiftscan_batch_scan_result_t;

//=== Scanner Invocation Specification ------------------------------------===//

typedef struct swiftscan_scan_invocation_s *swiftscan_scan_invocation_t;
typedef void *swiftscan_scanner_t;

//=== libSwiftScan Functions ------------------------------------------------===//

typedef struct {

//=== Dependency Result Functions -----------------------------------------===//
swiftscan_string_ref_t
(*swiftscan_dependency_graph_get_main_module_name)(swiftscan_dependency_graph_t);
swiftscan_dependency_set_t *
(*swiftscan_dependency_graph_get_dependencies)(swiftscan_dependency_graph_t);

//=== Dependency Module Info Functions ------------------------------------===//
swiftscan_string_ref_t
(*swiftscan_module_info_get_module_name)(swiftscan_dependency_info_t);
swiftscan_string_ref_t
(*swiftscan_module_info_get_module_path)(swiftscan_dependency_info_t);
swiftscan_string_set_t *
(*swiftscan_module_info_get_source_files)(swiftscan_dependency_info_t);
swiftscan_string_set_t *
(*swiftscan_module_info_get_direct_dependencies)(swiftscan_dependency_info_t);
swiftscan_module_details_t
(*swiftscan_module_info_get_details)(swiftscan_dependency_info_t);

//=== Dependency Module Info Details Functions ----------------------------===//
swiftscan_dependency_info_kind_t
(*swiftscan_module_detail_get_kind)(swiftscan_module_details_t);

//=== Swift Textual Module Details query APIs -----------------------------===//
swiftscan_string_ref_t
(*swiftscan_swift_textual_detail_get_module_interface_path)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_swift_textual_detail_get_compiled_module_candidates)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_swift_textual_detail_get_bridging_header_path)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_swift_textual_detail_get_bridging_source_files)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_swift_textual_detail_get_bridging_module_dependencies)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_swift_textual_detail_get_command_line)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_swift_textual_detail_get_extra_pcm_args)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_swift_textual_detail_get_context_hash)(swiftscan_module_details_t);
bool
(*swiftscan_swift_textual_detail_get_is_framework)(swiftscan_module_details_t);

//=== Swift Binary Module Details query APIs ------------------------------===//
swiftscan_string_ref_t
(*swiftscan_swift_binary_detail_get_compiled_module_path)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_swift_binary_detail_get_module_doc_path)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_swift_binary_detail_get_module_source_info_path)(swiftscan_module_details_t);

//=== Swift Placeholder Module Details query APIs -------------------------===//
swiftscan_string_ref_t
(*swiftscan_swift_placeholder_detail_get_compiled_module_path)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_swift_placeholder_detail_get_module_doc_path)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_swift_placeholder_detail_get_module_source_info_path)(swiftscan_module_details_t);

//=== Clang Module Details query APIs -------------------------------------===//
swiftscan_string_ref_t
(*swiftscan_clang_detail_get_module_map_path)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_clang_detail_get_context_hash)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_clang_detail_get_command_line)(swiftscan_module_details_t);

//=== Batch Scan Input Functions ------------------------------------------===//
swiftscan_batch_scan_input_t *
(*swiftscan_batch_scan_input_create)(void);
void
(*swiftscan_batch_scan_input_set_modules)(swiftscan_batch_scan_input_t *, int, swiftscan_batch_scan_entry_t *);

//=== Batch Scan Entry Functions ------------------------------------------===//
swiftscan_batch_scan_entry_t
(*swiftscan_batch_scan_entry_create)(void);
void
(*swiftscan_batch_scan_entry_set_module_name)(swiftscan_batch_scan_entry_t, const char *);
void
(*swiftscan_batch_scan_entry_set_arguments)(swiftscan_batch_scan_entry_t, const char *);
void
(*swiftscan_batch_scan_entry_set_is_swift)(swiftscan_batch_scan_entry_t, bool);
swiftscan_string_ref_t
(*swiftscan_batch_scan_entry_get_module_name)(swiftscan_batch_scan_entry_t);
swiftscan_string_ref_t
(*swiftscan_batch_scan_entry_get_arguments)(swiftscan_batch_scan_entry_t);
bool
(*swiftscan_batch_scan_entry_get_is_swift)(swiftscan_batch_scan_entry_t);

//=== Prescan Result Functions --------------------------------------------===//
swiftscan_string_set_t *
(*swiftscan_import_set_get_imports)(swiftscan_import_set_t);

//=== Scanner Invocation Functions ----------------------------------------===//
swiftscan_scan_invocation_t
(*swiftscan_scan_invocation_create)();
void
(*swiftscan_scan_invocation_set_working_directory)(swiftscan_scan_invocation_t, const char *);
void
(*swiftscan_scan_invocation_set_argv)(swiftscan_scan_invocation_t, int, const char **);
swiftscan_string_ref_t
(*swiftscan_scan_invocation_get_working_directory)(swiftscan_scan_invocation_t);
int
(*swiftscan_scan_invocation_get_argc)(swiftscan_scan_invocation_t);
swiftscan_string_set_t *
(*swiftscan_scan_invocation_get_argv)(swiftscan_scan_invocation_t);

//=== Cleanup Functions ---------------------------------------------------===//
void
(*swiftscan_dependency_graph_dispose)(swiftscan_dependency_graph_t);
void
(*swiftscan_import_set_dispose)(swiftscan_import_set_t);
void
(*swiftscan_batch_scan_entry_dispose)(swiftscan_batch_scan_entry_t);
void
(*swiftscan_batch_scan_input_dispose)(swiftscan_batch_scan_input_t *);
void
(*swiftscan_batch_scan_result_dispose)(swiftscan_batch_scan_result_t *);
void
(*swiftscan_scan_invocation_dispose)(swiftscan_scan_invocation_t);

//=== Scanner Functions ---------------------------------------------------===//
swiftscan_scanner_t (*swiftscan_scanner_create)(void);
void (*swiftscan_scanner_dispose)(swiftscan_scanner_t);

swiftscan_dependency_graph_t
(*swiftscan_dependency_graph_create)(swiftscan_scanner_t, swiftscan_scan_invocation_t);

swiftscan_batch_scan_result_t *
(*swiftscan_batch_scan_result_create)(swiftscan_scanner_t,
swiftscan_batch_scan_input_t *,
swiftscan_scan_invocation_t);

swiftscan_import_set_t
(*swiftscan_import_set_create)(swiftscan_scanner_t, swiftscan_scan_invocation_t);
} swiftscan_functions_t;

#endif // SWIFT_C_DEPENDENCY_SCAN_H
5 changes: 4 additions & 1 deletion Sources/SwiftDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ add_library(SwiftDriver
"ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift"
"ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift"

SwiftScan/DependencyGraphBuilder.swift
SwiftScan/SwiftScan.swift

Driver/CompilerMode.swift
Driver/DebugInfo.swift
Driver/Driver.swift
Expand Down Expand Up @@ -100,7 +103,7 @@ target_link_libraries(SwiftDriver PUBLIC
target_link_libraries(SwiftDriver PRIVATE
CYaml
Yams
CSwiftDriver)
CSwiftScan)

set_property(GLOBAL APPEND PROPERTY SWIFTDRIVER_EXPORTS SwiftDriver)

Expand Down
55 changes: 37 additions & 18 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import TSCBasic
import TSCUtility
import Foundation
import SwiftOptions
@_implementationOnly import _CSwiftDriver

/// The Swift driver.
public struct Driver {
Expand Down Expand Up @@ -125,6 +124,9 @@ public struct Driver {
/// The target triple.
@_spi(Testing) public var targetTriple: Triple { frontendTargetInfo.target.triple }

/// The host environment triple.
@_spi(Testing) public let hostTriple: Triple

/// The variant target triple.
var targetVariantTriple: Triple? {
frontendTargetInfo.targetVariant?.triple
Expand Down Expand Up @@ -386,6 +388,12 @@ public struct Driver {
executor: self.executor, fileSystem: fileSystem,
useStaticResourceDir: self.useStaticResourceDir)

// Compute the host machine's triple
self.hostTriple =
try Self.computeHostTriple(toolchain: self.toolchain,
executor: self.executor,
swiftCompilerPrefixArgs: self.swiftCompilerPrefixArgs)

// Classify and collect all of the input files.
let inputFiles = try Self.collectInputFiles(&self.parsedOptions)
self.inputFiles = inputFiles
Expand All @@ -396,23 +404,6 @@ public struct Driver {
return ($0, modTime)
})

// Create an instance of an inter-module dependency oracle, if the driver's
// client did not provide one. The clients are expected to provide an oracle
// when they wish to share module dependency information across targets.
if let dependencyOracle = interModuleDependencyOracle {
self.interModuleDependencyOracle = dependencyOracle
} else {
self.interModuleDependencyOracle = InterModuleDependencyOracle()

// This is a shim for backwards-compatibility with ModuleInfoMap-based API
// used by SwiftPM
if let externalArtifacts = externalBuildArtifacts {
if !externalArtifacts.1.isEmpty {
try self.interModuleDependencyOracle.mergeModules(from: externalArtifacts.1)
}
}
}

do {
let outputFileMap: OutputFileMap?
// Initialize an empty output file map, which will be populated when we start creating jobs.
Expand All @@ -434,6 +425,23 @@ public struct Driver {
}
}

// Create an instance of an inter-module dependency oracle, if the driver's
// client did not provide one. The clients are expected to provide an oracle
// when they wish to share module dependency information across targets.
if let dependencyOracle = interModuleDependencyOracle {
self.interModuleDependencyOracle = dependencyOracle
} else {
self.interModuleDependencyOracle = InterModuleDependencyOracle()

// This is a shim for backwards-compatibility with ModuleInfoMap-based API
// used by SwiftPM
if let externalArtifacts = externalBuildArtifacts {
if !externalArtifacts.1.isEmpty {
try self.interModuleDependencyOracle.mergeModules(from: externalArtifacts.1)
}
}
}

self.fileListThreshold = try Self.computeFileListThreshold(&self.parsedOptions, diagnosticsEngine: diagnosticsEngine)
self.shouldUseInputFileList = inputFiles.count > fileListThreshold
if shouldUseInputFileList {
Expand Down Expand Up @@ -2082,6 +2090,17 @@ extension Driver {
static let defaultToolchainType: Toolchain.Type = GenericUnixToolchain.self
#endif

static func computeHostTriple(toolchain: Toolchain,
executor: DriverExecutor,
swiftCompilerPrefixArgs: [String]) throws -> Triple {
return try executor.execute(
job: toolchain.printTargetInfoJob(target: nil, targetVariant: nil,
swiftCompilerPrefixArgs: swiftCompilerPrefixArgs),
capturingJSONOutputAs: FrontendTargetInfo.self,
forceResponseFiles: false,
recordedInputModificationDates: [:]).target.triple
}

static func computeToolchain(
_ parsedOptions: inout ParsedOptions,
diagnosticsEngine: DiagnosticsEngine,
Expand Down
Loading