Skip to content

Commit bc39e19

Browse files
authored
Merge pull request #38374 from nkcsgexi/compiler-api
libSwiftScanner: add an API to invoke compiler in process
2 parents 64b3245 + d22b348 commit bc39e19

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ function(add_swift_host_library name)
464464
SHARED
465465
STATIC
466466
OBJECT
467-
PURE_SWIFT)
467+
PURE_SWIFT
468+
HAS_LIBSWIFT)
468469
set(single_parameter_options)
469470
set(multiple_parameter_options
470471
LLVM_LINK_COMPONENTS)
@@ -510,6 +511,12 @@ function(add_swift_host_library name)
510511
511512
add_library(${name} ${libkind} ${ASHL_SOURCES})
512513
514+
if (ASHL_HAS_LIBSWIFT AND SWIFT_TOOLS_ENABLE_LIBSWIFT)
515+
# Workaround for a linker crash related to autolinking: rdar://77839981
516+
set_property(TARGET ${name} APPEND_STRING PROPERTY
517+
LINK_FLAGS " -lobjc ")
518+
endif()
519+
513520
# Respect LLVM_COMMON_DEPENDS if it is set.
514521
#
515522
# LLVM_COMMON_DEPENDS if a global variable set in ./lib that provides targets

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ swiftscan_scanner_cache_load(swiftscan_scanner_t scanner,
359359
SWIFTSCAN_PUBLIC void
360360
swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
361361

362+
/// An entry point to invoke the compiler via a library call.
363+
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);
364+
362365
//===----------------------------------------------------------------------===//
363366

364367
SWIFTSCAN_END_DECLS

tools/libSwiftScan/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ set(LLVM_EXPORTED_SYMBOL_FILE
99

1010
add_swift_host_library(libSwiftScan SHARED
1111
libSwiftScan.cpp
12-
c-include-check.c)
12+
c-include-check.c
13+
HAS_LIBSWIFT)
1314

1415
add_dependencies(libSwiftScan
1516
clang
1617
swiftDependencyScan)
1718

1819
target_link_libraries(libSwiftScan PRIVATE
1920
swiftDependencyScan
20-
swiftDriverTool)
21+
swiftDriverTool
22+
libswift)
2123

2224
set_target_properties(libSwiftScan
2325
PROPERTIES

tools/libSwiftScan/libSwiftScan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "swift/Basic/LLVMInitialize.h"
18+
#include "swift/DriverTool/DriverTool.h"
1819
#include "swift/DependencyScan/DependencyScanImpl.h"
1920
#include "swift/DependencyScan/DependencyScanningTool.h"
2021
#include "swift/DependencyScan/StringUtils.h"
@@ -510,3 +511,7 @@ swiftscan_compiler_supported_features_query() {
510511
// TODO: We are yet to figure out how "Features" will be organized.
511512
return nullptr;
512513
}
514+
515+
int invoke_swift_compiler(int argc, const char **argv) {
516+
return swift::mainEntry(argc, argv);
517+
}

tools/libSwiftScan/libSwiftScan.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ swiftscan_compiler_supported_features_query
5757
swiftscan_scanner_cache_serialize
5858
swiftscan_scanner_cache_load
5959
swiftscan_scanner_cache_reset
60+
invoke_swift_compiler

0 commit comments

Comments
 (0)