Skip to content

Commit 8e7b75e

Browse files
committed
wip
1 parent 20876e6 commit 8e7b75e

File tree

10 files changed

+47
-35
lines changed

10 files changed

+47
-35
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ include(macCatalystUtils)
44
function(force_add_dependencies TARGET)
55
foreach(DEPENDENCY ${ARGN})
66
string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY})
7-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
8-
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
7+
set(depfile "${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift")
8+
add_custom_command(OUTPUT ${depfile}
9+
COMMAND ${CMAKE_COMMAND} -E touch ${depfile}
910
DEPENDS ${DEPENDENCY}
1011
)
11-
target_sources(${TARGET} PRIVATE
12-
${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
13-
)
12+
target_sources(${TARGET} PRIVATE ${depfile})
1413
endforeach()
1514
endfunction()
1615

@@ -255,7 +254,7 @@ function(add_pure_swift_host_library name)
255254
>)
256255
else()
257256
# Emit a swiftmodule in the current directory.
258-
set(module_dir "${CMAKE_CURRENT_BINARY_DIR}")
257+
set(module_dir "${CMAKE_CURRENT_BINARY_DIR}/modules")
259258
set(module_file "${module_dir}/${name}.swiftmodule")
260259
endif()
261260

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,12 +1012,12 @@ function(add_swift_host_tool executable)
10121012
set_property(
10131013
TARGET ${executable}
10141014
APPEND PROPERTY INSTALL_RPATH
1015-
"@executable_path/../${extra_relative_rpath}lib")
1015+
"@executable_path/../${extra_relative_rpath}lib/swift/host/compiler")
10161016
else()
10171017
set_property(
10181018
TARGET ${executable}
10191019
APPEND PROPERTY INSTALL_RPATH
1020-
"$ORIGIN/../${extra_relative_rpath}lib")
1020+
"$ORIGIN/../${extra_relative_rpath}lib/swift/host/compiler")
10211021
endif()
10221022
endif()
10231023

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ function(add_swift_unittest test_dirname)
133133
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
134134
set_property(
135135
TARGET ${test_dirname}
136-
APPEND PROPERTY INSTALL_RPATH "@executable_path/${relative_lib_path}/swift/host")
136+
APPEND PROPERTY INSTALL_RPATH "@executable_path/${relative_lib_path}/swift/host/compiler")
137137
elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
138138
set_property(
139139
TARGET ${test_dirname}
140-
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/${relative_lib_path}/swift/host")
140+
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/${relative_lib_path}/swift/host/compiler")
141141
endif()
142142
endif()
143143
endfunction()

include/swift/AST/PluginRegistry.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CompilerPlugin {
3232

3333
std::mutex mtx;
3434

35-
/// Opaque value of the protocol capability of the pluugin. This is a
35+
/// Opaque value of the protocol capability of the plugin. This is a
3636
/// value from ASTGen.
3737
const void *capability = nullptr;
3838

@@ -101,12 +101,13 @@ class InProcessPlugins : public CompilerPlugin {
101101
/// PluginServer
102102
llvm::sys::DynamicLibrary server;
103103

104-
/// Entry point in the in-process plugin server. It received the request
105-
/// string and populate the response string. deallocating the populated
106-
/// `repsonseDataPtr` is caller's responsibility.
104+
/// Entry point in the in-process plugin server. It receives the request
105+
/// string and populate the response string. The return value indicates there
106+
/// was an error. If true the returned string contains the error message.
107+
/// 'free'ing the populated `responseDataPtr` is caller's responsibility.
107108
using HandleMessageFunction = bool (*)(const char *requestData,
108109
size_t requestLength,
109-
const char **repsonseDataPtr,
110+
const char **responseDataPtr,
110111
size_t *responseDataLengthPtr);
111112
HandleMessageFunction handleMessageFn;
112113

@@ -119,9 +120,10 @@ class InProcessPlugins : public CompilerPlugin {
119120
handleMessageFn(handleMessageFn) {}
120121

121122
public:
122-
/// Create and instance by loading the in-process plugin server at
123-
/// 'serverPath' and return it.
124-
static llvm::Expected<InProcessPlugins *> create(const char *serverPath);
123+
/// Create an instance by loading the in-process plugin server at 'serverPath'
124+
/// and return it.
125+
static llvm::Expected<std::unique_ptr<InProcessPlugins>>
126+
create(const char *serverPath);
125127

126128
/// Send a message to the plugin.
127129
llvm::Error sendMessage(llvm::StringRef message) override;

lib/AST/PluginRegistry.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ PluginRegistry::PluginRegistry() {
4545
}
4646

4747
CompilerPlugin::~CompilerPlugin() {
48-
// Let ASTGen to cleanup things.
48+
// Let ASTGen do cleanup things.
4949
if (this->cleanup)
5050
this->cleanup();
5151
}
5252

53-
llvm::Expected<InProcessPlugins *>
53+
llvm::Expected<std::unique_ptr<InProcessPlugins>>
5454
InProcessPlugins::create(const char *serverPath) {
5555
std::string err;
5656
auto server = llvm::sys::DynamicLibrary::getLibrary(serverPath, &err);
@@ -64,8 +64,8 @@ InProcessPlugins::create(const char *serverPath) {
6464
return llvm::createStringError(llvm::inconvertibleErrorCode(),
6565
"entry point not found in '%s'", serverPath);
6666
}
67-
return new InProcessPlugins(serverPath, server,
68-
reinterpret_cast<HandleMessageFunction>(funcPtr));
67+
return std::unique_ptr<InProcessPlugins>(new InProcessPlugins(
68+
serverPath, server, reinterpret_cast<HandleMessageFunction>(funcPtr)));
6969
}
7070

7171
llvm::Error InProcessPlugins::sendMessage(llvm::StringRef message) {
@@ -103,9 +103,8 @@ llvm::Error InProcessPlugins::sendMessage(llvm::StringRef message) {
103103
llvm::Expected<std::string> InProcessPlugins::waitForNextMessage() {
104104
assert(!receivedResponse.empty() &&
105105
"waitForNextMessage() called without response data.");
106-
auto message = receivedResponse;
107-
receivedResponse = "";
108-
return message;
106+
SWIFT_DEFER { receivedResponse = ""; };
107+
return std::move(receivedResponse);
109108
}
110109

111110
llvm::Expected<CompilerPlugin *>
@@ -122,7 +121,7 @@ PluginRegistry::getInProcessPlugins(llvm::StringRef serverPath) {
122121
"; " + err.message());
123122
});
124123
}
125-
inProcessPlugins = std::unique_ptr<InProcessPlugins>(server.get());
124+
inProcessPlugins = std::move(server.get());
126125
} else if (inProcessPlugins->getPath() != serverPath) {
127126
return llvm::createStringError(
128127
llvm::inconvertibleErrorCode(),

lib/ASTGen/Sources/ASTGen/PluginHost.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ extension String {
384384
var basename: String {
385385
guard
386386
let lastSlash = lastIndex(where: {
387-
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || os(Android) || os(Linux)
387+
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || os(visionOS) || os(Android) || os(Linux)
388388
["/"].contains($0)
389389
#else
390390
["/", "\\"].contains($0)

lib/CompilerSwiftSyntax/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ includeSwiftSyntax()
2727

2828
# Make unified swift-syntax shared library.
2929
add_pure_swift_host_library(swiftSyntaxUnified SHARED)
30-
set_target_properties(swiftSyntaxUnified PROPERTIES LINKER_LANGUAGE Swift)
3130

3231
macro(target_link_libraries_whole_archive target)
3332
set_property(TARGET ${target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
@@ -62,3 +61,11 @@ target_link_libraries_whole_archive(swiftSyntaxUnified
6261
_CompilerSwiftDiagnostics
6362
_CompilerSwiftIDEUtils
6463
)
64+
65+
set_property(TARGET swiftSyntaxUnified PROPERTY
66+
LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}/compiler"
67+
)
68+
swift_install_in_component(TARGETS swiftSyntaxUnified
69+
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/compiler" COMPONENT compiler
70+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/compiler" COMPONENT compiler
71+
RUNTIME DESTINATION "bin" COMPONENT compiler)

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
156156
if(SWIFT_BUILD_SWIFT_SYNTAX)
157157
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
158158
# Add rpath to the host Swift libraries.
159-
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
159+
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host/compiler")
160160
list(APPEND RPATH_LIST "@loader_path/${relative_hostlib_path}")
161161
elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD")
162162
# Add rpath to the host Swift libraries.
163-
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
163+
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host/compiler")
164164
list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}")
165165
else()
166166
target_link_directories(${target} PRIVATE

tools/libSwiftScan/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ endif()
4646

4747
if(SWIFT_BUILD_SWIFT_SYNTAX)
4848
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
49-
# Ensure that we can find the shaered swiftsyntax libraries.
49+
# Ensure that we can find the shared swift-syntax libraries.
5050
set_property(
5151
TARGET libSwiftScan
52-
APPEND PROPERTY INSTALL_RPATH "@loader_path")
52+
APPEND PROPERTY INSTALL_RPATH "@loader_path/swift/host/compiler")
5353
set_property(
5454
TARGET libSwiftScan
55-
APPEND PROPERTY INSTALL_RPATH "@loader_path/../..")
55+
APPEND PROPERTY INSTALL_RPATH "@loader_path/compiler")
5656
elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
5757
set_property(
5858
TARGET libSwiftScan
59-
APPEND PROPERTY INSTALL_RPATH "$ORIGIN")
59+
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/swift/host/compiler")
6060
set_property(
6161
TARGET libSwiftScan
62-
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/../..")
62+
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/compiler")
6363
endif()
6464
endif()
6565

tools/swift-plugin-server/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
2929

3030
set_property(TARGET ${name}
3131
PROPERTY BUILD_WITH_INSTALL_RPATH YES)
32+
33+
swift_install_in_component(TARGETS SwiftInProcPluginServer
34+
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" COMPONENT compiler
35+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" COMPONENT compiler
36+
RUNTIME DESTINATION "bin" COMPONENT compiler)
3237
endif()

0 commit comments

Comments
 (0)