Skip to content

Commit 8c36500

Browse files
authored
Merge pull request #62093 from DougGregor/compiler-plugin-support-layout
2 parents 0bc9450 + 52b64e5 commit 8c36500

18 files changed

+106
-25
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,12 @@ function(add_swift_host_tool executable)
911911
endif()
912912
endif()
913913
914+
if(SWIFT_SWIFT_PARSER)
915+
set_property(
916+
TARGET ${executable}
917+
APPEND PROPERTY INSTALL_RPATH "@executable_path/../lib")
918+
endif()
919+
914920
if(ASHT_THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
915921
string(CONCAT lto_codegen_only_link_options
916922
"$<"

lib/ASTGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ if (SWIFT_SWIFT_PARSER)
6868
$<TARGET_OBJECTS:SwiftSyntax::SwiftCompilerSupport>
6969

7070
swiftAST
71+
swift_CompilerPluginSupport
7172
)
7273

7374
target_include_directories(swiftASTGen PUBLIC

lib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ list(APPEND LLVM_COMMON_DEPENDS swift-syntax-generated-headers)
1717
list(APPEND LLVM_COMMON_DEPENDS swift-ast-generated-headers)
1818
list(APPEND LLVM_COMMON_DEPENDS swift-parse-syntax-generated-headers)
1919

20+
add_subdirectory(CompilerPluginSupport)
2021
add_subdirectory(APIDigester)
2122
add_subdirectory(AST)
2223
add_subdirectory(ASTGen)
@@ -57,4 +58,3 @@ add_subdirectory(SymbolGraphGen)
5758
add_subdirectory(Syntax)
5859
add_subdirectory(SyntaxParse)
5960
add_subdirectory(Threading)
60-
add_subdirectory(CompilerPluginSupport)

lib/CompilerPluginSupport/CMakeLists.txt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,36 @@ if(SWIFT_SWIFT_PARSER)
2626
set(DEPLOYMENT_VERSION ${SWIFT_ANDROID_API_LEVEL})
2727
endif()
2828

29+
# Determine the Swift module path
30+
set(module_triple ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_MODULE})
31+
set(module_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
32+
set(module_base "${module_dir}/${module_name}.swiftmodule")
33+
set(module_file "${module_base}/${module_triple}.swiftmodule")
34+
set(module_interface_file "${module_base}/${module_triple}.swiftinterface")
35+
set(module_doc_file "${module_base}/${module_triple}.swiftdoc")
36+
2937
get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}"
3038
MACCATALYST_BUILD_FLAVOR ""
3139
DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}")
3240

41+
# Add a custom target to create the module directory and remove any old
42+
# compiled module file.
43+
add_custom_command_target(
44+
create_module_dirs_dependency_target
45+
COMMAND "${CMAKE_COMMAND}" -E make_directory ${module_base}
46+
COMMAND "${CMAKE_COMMAND}" -E rm -f "${module_file}"
47+
OUTPUT ${module_base}
48+
COMMENT "Generating module directory for ${module_name}")
49+
add_dependencies(${library_name} ${create_module_dirs_dependency_target})
50+
51+
# Build the module with library evolution enabled and install into the
52+
# appropriate locations.
3353
target_compile_options("${library_name}" PRIVATE
3454
$<$<COMPILE_LANGUAGE:Swift>:
3555
-module-name;${module_name};
3656
-enable-library-evolution;
37-
-emit-module-interface;
57+
-emit-module-interface-path;
58+
"${module_interface_file}" ;
3859
-target;${target}>)
3960

4061
target_link_libraries("${library_name}"
@@ -56,4 +77,9 @@ if(SWIFT_SWIFT_PARSER)
5677
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
5778
COMPONENT compiler)
5879

80+
swift_install_in_component(DIRECTORY "${module_base}"
81+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift"
82+
COMPONENT compiler)
83+
84+
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${library_name})
5985
endif()

test/Driver/driver-compile.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545

4646
// RUN: %swiftc_driver -driver-print-jobs -c -target x86_64-apple-macosx10.9 %s %S/../Inputs/empty.swift -module-name main -driver-filelist-threshold=0 2>&1 | %FileCheck -check-prefix=FILELIST %s
4747

48-
// RUN: %empty-directory(%t)/DISTINCTIVE-PATH/usr/bin/
48+
// RUN: %empty-directory(%t/DISTINCTIVE-PATH/usr/bin/)
49+
// RUN: %empty-directory(%t/DISTINCTIVE-PATH/usr/lib/)
4950
// RUN: %hardlink-or-copy(from: %swift_frontend_plain, to: %t/DISTINCTIVE-PATH/usr/bin/swiftc)
51+
// RUN: %copy-plugin-support-library(%t/DISTINCTIVE-PATH/usr/lib/)
5052
// RUN: ln -s "swiftc" %t/DISTINCTIVE-PATH/usr/bin/swift-update
5153
// RUN: %t/DISTINCTIVE-PATH/usr/bin/swiftc -driver-print-jobs -c -update-code -target x86_64-apple-macosx10.9 %s 2>&1 > %t.upd.txt
5254
// RUN: %FileCheck -check-prefix UPDATE-CODE %s < %t.upd.txt

test/Driver/linker-clang_rt.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
// RUN: rm -rf %t
88
// RUN: %empty-directory(%t/bin)
9+
// RUN: %empty-directory(%t/lib)
910
// RUN: %hardlink-or-copy(from: %swift_frontend_plain, to: %t/bin/swiftc)
11+
// RUN: %copy-plugin-support-library(%t/lib/)
1012
// RUN: %empty-directory(%t/lib/swift/clang/lib/darwin/)
1113

1214
// RUN: %t/bin/swiftc -driver-print-jobs -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix CHECK-NO-RUNTIME %s

test/Driver/options-repl-darwin.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// the Swift driver really thinks it's been moved.
66

77
// RUN: %empty-directory(%t/usr/bin/)
8+
// RUN: %empty-directory(%t/usr/lib/)
89
// RUN: %hardlink-or-copy(from: %swift_driver_plain, to: %t/usr/bin/swift)
10+
// RUN: %copy-plugin-support-library(%t/usr/lib/)
911

1012
// RUN: %t/usr/bin/swift -repl -### | %FileCheck -check-prefix=INTEGRATED %s
1113
// RUN: %t/usr/bin/swift -### | %FileCheck -check-prefix=INTEGRATED %s
@@ -16,7 +18,9 @@
1618
// RUN: %t/usr/bin/swift -### | %FileCheck -check-prefix=LLDB %s
1719

1820
// RUN: %empty-directory(%t/Toolchains/Test.xctoolchain/usr/bin)
21+
// RUN: %empty-directory(%t/Toolchains/Test.xctoolchain/usr/lib)
1922
// RUN: mv %t/usr/bin/swift %t/Toolchains/Test.xctoolchain/usr/bin/swift
23+
// RUN: %copy-plugin-support-library(%t/Toolchains/Test.xctoolchain/usr/lib/)
2024
// RUN: %t/Toolchains/Test.xctoolchain/usr/bin/swift -repl -### | %FileCheck -check-prefix=LLDB %s
2125

2226
// Clean up the test executable because hard links are expensive.

test/Driver/options-repl.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
// RUN: %empty-directory(%t)
99
// RUN: mkdir -p %t/usr/bin
10+
// RUN: mkdir -p %t/usr/lib
11+
// RUN: %copy-plugin-support-library(%t/usr/lib/)
1012
// RUN: %hardlink-or-copy(from: %swift_frontend_plain, to: %t/usr/bin/swift)
1113

1214
// RUN: %t/usr/bin/swift -sdk "" -deprecated-integrated-repl -### | %FileCheck -check-prefix=INTEGRATED %s

test/Driver/subcommands.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
// RUN: rm -rf %t.dir
55
// RUN: mkdir -p %t.dir/usr/bin
6+
// RUN: mkdir -p %t.dir/usr/lib
67
// RUN: %hardlink-or-copy(from: %swift_frontend_plain, to: %t.dir/usr/bin/swift)
8+
// RUN: %copy-plugin-support-library(%t.dir/usr/lib/)
79

810
// RUN: %t.dir/usr/bin/swift -### 2>&1 | %FileCheck -check-prefix=CHECK-SWIFT-INVOKES-REPL %s
911
// RUN: %t.dir/usr/bin/swift repl -### 2>&1 | %FileCheck -check-prefix=CHECK-SWIFT-INVOKES-REPL %s

test/Driver/windows-link-job.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %empty-directory(%t/DISTINCTIVE-WINDOWS-PATH/usr/bin)
2+
// RUN: %empty-directory(%t/DISTINCTIVE-WINDOWS-PATH/usr/lib)
23
// RUN: %hardlink-or-copy(from: %swift_frontend_plain, to: %t/DISTINCTIVE-WINDOWS-PATH/usr/bin/swiftc)
4+
// RUN: %copy-plugin-support-library(%t/DISTINCTIVE-WINDOWS-PATH/usr/lib/)
35
// RUN: env PATH= %t/DISTINCTIVE-WINDOWS-PATH/usr/bin/swiftc -target x86_64-unknown-windows-msvc -### -module-name link -emit-library %s 2>&1 | %FileCheck %s
46

57
// swift-frontend cannot be copied to another location with bootstrapping because

0 commit comments

Comments
 (0)