Skip to content
Open
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
2 changes: 1 addition & 1 deletion include/swift/Option/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
set(LLVM_TARGET_DEFINITIONS Options.td)
swift_tablegen(Options.inc -gen-opt-parser-defs)
swift_add_public_tablegen_target(SwiftOptions)
swift_add_public_tablegen_target(SwiftOptionDefinitions)
2 changes: 1 addition & 1 deletion lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(swiftDriver_targetDefines)
add_swift_host_library(swiftDriver STATIC
${swiftDriver_sources})
add_dependencies(swiftDriver
SwiftOptions)
SwiftOptionDefinitions)
target_link_libraries(swiftDriver PRIVATE
swiftAST
swiftBasic
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_swift_host_library(swiftFrontend STATIC
Serialization.cpp
SerializedDiagnosticConsumer.cpp)
add_dependencies(swiftFrontend
SwiftOptions)
SwiftOptionDefinitions)
target_link_libraries(swiftFrontend PRIVATE
swiftAPIDigester
swiftAST
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_swift_host_library(swiftFrontendTool STATIC
LoadedModuleTrace.cpp
TBD.cpp)
add_dependencies(swiftFrontendTool
SwiftOptions)
SwiftOptionDefinitions)
target_link_libraries(swiftFrontendTool INTERFACE
clangAPINotes
clangBasic)
Expand Down
2 changes: 1 addition & 1 deletion lib/Option/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_swift_host_library(swiftOption STATIC
Options.cpp
SanitizerOptions.cpp)
add_dependencies(swiftOption
SwiftOptions)
SwiftOptionDefinitions)
target_link_libraries(swiftOption PRIVATE
swiftBasic)

Expand Down
14 changes: 9 additions & 5 deletions lib/Tooling/libSwiftScan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ add_swift_host_library(libSwiftScan SHARED
SwiftCaching.cpp
HAS_SWIFT_MODULES)

add_library(libSwiftScanDependencies INTERFACE)
target_link_libraries(libSwiftScanDependencies INTERFACE
swiftDependencyScan
swiftDriverTool
swiftStaticMirror
swiftRemoteInspection
swiftCompilerModules)

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
# Workaround for a linker crash related to autolinking: rdar://77839981
set_property(TARGET libSwiftScan APPEND_STRING PROPERTY
Expand All @@ -21,11 +29,7 @@ add_dependencies(libSwiftScan
swiftDependencyScan)

target_link_libraries(libSwiftScan PRIVATE
swiftDependencyScan
swiftDriverTool
swiftStaticMirror
swiftRemoteInspection
swiftCompilerModules)
libSwiftScanDependencies)

set_target_properties(libSwiftScan
PROPERTIES
Expand Down
44 changes: 43 additions & 1 deletion tools/swift-ide-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# Early swift-driver is built adjacent to the compiler (swift build dir)
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(driver_package_configuration_dir "release")
else()
set(driver_package_configuration_dir "debug")
endif()

get_target_property(LIB_SCAN_SOURCE_DIR libSwiftScan SOURCE_DIR)

set(LIB_SCAN_EXPORTED_SYMBOL_FILE
${LIB_SCAN_SOURCE_DIR}/libSwiftScan.exports)

message(STATUS "libSwiftScan: ${LIB_SCAN_SOURCE_DIR}")
message(STATUS "swift-driver: ${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/cmake/modules/")
message(STATUS "swift-tools-support-core: ${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/dependencies/swift-tools-support-core/cmake/modules/")

set(SwiftDriver_DIR
"${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/cmake/modules/")
set(TSC_DIR "${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/dependencies/swift-tools-support-core/cmake/modules/")
Comment on lines +17 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we have SWIFT_EARLY_SWIFT_DRIVER_BUILD already so you could use that. But I'd also do a check here for if SwiftDriver_DIR and TSC_DIR are already set.

Have we thought much about using FetchContent for the early swift driver (similar to swift-syntax)? CC @compnerd @etcwilde

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, FetchContent or find_package should be what we use here instead of hard-coding these paths.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well technically we are doing a find_package, just setting SwiftDriver_DIR beforehand 😅. We currently set SWIFT_EARLY_SWIFT_DRIVER_BUILD, I'm not entirely clear why we're not just setting SwiftDriver_DIR though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_package(TSC CONFIG)
find_package(SwiftDriver CONFIG)


add_swift_host_tool(swift-ide-test
swift-ide-test.cpp
ModuleAPIDiff.cpp
Expand All @@ -6,14 +29,33 @@ add_swift_host_tool(swift-ide-test
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
HAS_SWIFT_MODULES
)

set_property(
TARGET swift-ide-test
APPEND PROPERTY INSTALL_RPATH "${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/lib/"
)
set_property(
TARGET swift-ide-test
APPEND PROPERTY INSTALL_RPATH "${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/${driver_package_configuration_dir}/dependencies/swift-tools-support-core/lib/"
)
Comment on lines +33 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely don't want an absolute INSTALL_RPATH. I would have also thought that this isn't needed regardless - the lib to be in the same place as swift-syntax, which is already on the rpath.


target_link_libraries(swift-ide-test
PRIVATE
swiftAST
swiftDriver
SwiftDriver
swiftFrontend
swiftIDE
swiftIDETool
swiftCompilerModules)
swiftCompilerModules
libSwiftScanDependencies)
target_sources(swift-ide-test
PRIVATE
$<TARGET_OBJECTS:libSwiftScan>)

# This is required because swift-driver in "integrated" mode depends on libSwiftScan symbols
# that have to be re-exported from the `libSwiftScan` library.
add_llvm_symbol_exports(swift-ide-test ${LIB_SCAN_EXPORTED_SYMBOL_FILE})

# If libxml2 is available, make it available for swift-ide-test.
if(LLVM_ENABLE_LIBXML2)
Expand Down
40 changes: 40 additions & 0 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4235,6 +4235,29 @@ static int doPrintUSRs(const CompilerInvocation &InitInvok,
return 0;
}

extern "C" {
typedef enum {
SWIFTDRIVER_TOOLING_DIAGNOSTIC_ERROR = 0,
SWIFTDRIVER_TOOLING_DIAGNOSTIC_WARNING = 1,
SWIFTDRIVER_TOOLING_DIAGNOSTIC_REMARK = 2,
SWIFTDRIVER_TOOLING_DIAGNOSTIC_NOTE = 3
} swiftdriver_tooling_diagnostic_kind;
bool swift_getSingleFrontendInvocationFromDriverArgumentsV3(
const char *, int, const char **, bool(int, const char **),
void(swiftdriver_tooling_diagnostic_kind, const char *), bool, bool);
}
bool displayFrontendArgs(int FrontendArgC, const char ** FrontendArgV) {
llvm::outs() << "SwiftDriver (new) Frontend Arguments BEGIN\n";
for (int i = 0; i < FrontendArgC; ++i) {
llvm::outs() << FrontendArgV[i] << "\n";
}
llvm::outs() << "SwiftDriver (new) Frontend Arguments END\n";
return false;
}
void handleDiagnostic(swiftdriver_tooling_diagnostic_kind diagKind, const char * diagMessage) {
return;
}

static int doTestCreateCompilerInvocation(StringRef DriverPath,
ArrayRef<const char *> Args,
bool ForceNoOutputs) {
Expand All @@ -4261,6 +4284,23 @@ static int doTestCreateCompilerInvocation(StringRef DriverPath,
return 1;
}

{
const char **argList = (const char**)malloc(sizeof(const char*) * Args.size());
for (size_t i = 0; i < Args.size(); ++i) {
argList[i] = Args[i];
}

bool NewHadError = swift_getSingleFrontendInvocationFromDriverArgumentsV3(
DriverPath.str().c_str(), Args.size(), argList, &displayFrontendArgs,
&handleDiagnostic,
/*compilerIntegratedTooling=*/true, ForceNoOutputs);
if (NewHadError) {
llvm::errs()
<< "error: unable to create a CompilerInvocation (new driver)\n";
return 1;
}
}

return 0;
}

Expand Down