diff --git a/CMakeLists.txt b/CMakeLists.txt index 00f40cf7..ed60c850 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,18 @@ cmake_minimum_required(VERSION 3.26...3.29) project(SwiftBuild LANGUAGES C CXX Swift) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +set(CMAKE_INSTALL_RPATH "$,@loader_path/..,$ORIGIN>") +set(CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH YES) + +set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) +set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) + +option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) + set(CMAKE_C_VISIBILITY hidden) set(CMAKE_CXX_VISIBILITY hidden) set(CMAKE_CXX_STANDARD 17) @@ -35,7 +47,33 @@ add_compile_options("$<$:SHELL:-package-name SwiftBuild> # rdar://137809703 # "$<$:SHELL:-enable-upcoming-feature RegionBasedIsolation>" "$<$:SHELL:-enable-upcoming-feature ExistentialAny>" - "$<$:SHELL:-enable-upcoming-feature InternalImportsByDefault>") + "$<$:SHELL:-enable-upcoming-feature InternalImportsByDefault>" + "$<$:SHELL:-no-toolchain-stdlib-rpath>" + # Turn off autolinking within this project to reduce linker overhead. + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBLibc>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBAndroidPlatform>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBApplePlatform>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBBuildService>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCLibc>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBGenericUnixPlatform>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBTaskConstruction>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBUtil>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBUniversalPlatform>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBWindowsPlatform>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SwiftBuild>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBWebAssemblyPlatform>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCSupport>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBMacro>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBProjectModel>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBTaskExecution>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBServiceCore>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBQNXPlatform>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBProtocol>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBLLBuild>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCore>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCAS>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBBuildSystem>" + "$<$:SHELL:-Xfrontend -disable-autolink-library -Xfrontend SWBCore>") # Prefer the static initialization for the plugins. add_compile_definitions(USE_STATIC_PLUGIN_INITIALIZATION) @@ -50,3 +88,4 @@ find_package(Threads) find_package(SQLite3) add_subdirectory(Sources) +add_subdirectory(cmake/modules) diff --git a/Package.swift b/Package.swift index dcee18be..baef8b0a 100644 --- a/Package.swift +++ b/Package.swift @@ -135,6 +135,7 @@ let package = Package( swiftSettings: swiftSettings(languageMode: .v5)), .target( name: "SWBCSupport", + exclude: ["empty.swift"], publicHeadersPath: ".", cSettings: [ .define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])), diff --git a/Sources/SWBAndroidPlatform/CMakeLists.txt b/Sources/SWBAndroidPlatform/CMakeLists.txt index e2f2faae..9cf4c2c4 100644 --- a/Sources/SWBAndroidPlatform/CMakeLists.txt +++ b/Sources/SWBAndroidPlatform/CMakeLists.txt @@ -28,7 +28,7 @@ file(CONFIGURE ]] ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF) -add_library(SWBAndroidPlatform STATIC +add_library(SWBAndroidPlatform AndroidSDK.swift Plugin.swift) target_link_libraries(SWBAndroidPlatform PUBLIC @@ -37,3 +37,11 @@ target_link_libraries(SWBAndroidPlatform PUBLIC SWBUtil) target_sources(SWBAndroidPlatform PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBAndroidPlatform PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBAndroidPlatform) + +install(TARGETS SWBAndroidPlatform + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBApplePlatform/CMakeLists.txt b/Sources/SWBApplePlatform/CMakeLists.txt index c636817e..fb516d7b 100644 --- a/Sources/SWBApplePlatform/CMakeLists.txt +++ b/Sources/SWBApplePlatform/CMakeLists.txt @@ -28,7 +28,7 @@ file(CONFIGURE ]] ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF) -add_library(SWBApplePlatform STATIC +add_library(SWBApplePlatform AppIntentsMetadataCompiler.swift AppIntentsMetadataTaskProducer.swift AppIntentsSSUTrainingCompiler.swift @@ -75,3 +75,11 @@ target_link_libraries(SWBApplePlatform PUBLIC SWBTaskConstruction) target_sources(SWBApplePlatform PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBApplePlatform PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBApplePlatform) + +install(TARGETS SWBApplePlatform + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBBuildService/CMakeLists.txt b/Sources/SWBBuildService/CMakeLists.txt index 00971369..ac623f70 100644 --- a/Sources/SWBBuildService/CMakeLists.txt +++ b/Sources/SWBBuildService/CMakeLists.txt @@ -37,3 +37,11 @@ target_link_libraries(SWBBuildService PUBLIC SWBWebAssemblyPlatform SWBWindowsPlatform $<$>:SwiftSystem::SystemPackage>) + +set_target_properties(SWBBuildService PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildService) + +install(TARGETS SWBBuildService + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBBuildServiceBundle/CMakeLists.txt b/Sources/SWBBuildServiceBundle/CMakeLists.txt index dcae6b91..f4a03757 100644 --- a/Sources/SWBBuildServiceBundle/CMakeLists.txt +++ b/Sources/SWBBuildServiceBundle/CMakeLists.txt @@ -20,3 +20,5 @@ target_link_libraries(SWBBuildServiceBundle PRIVATE SWBCore) install(TARGETS SWBBuildServiceBundle) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildServiceBundle) diff --git a/Sources/SWBBuildSystem/CMakeLists.txt b/Sources/SWBBuildSystem/CMakeLists.txt index 7bef4f58..9095c4fd 100644 --- a/Sources/SWBBuildSystem/CMakeLists.txt +++ b/Sources/SWBBuildSystem/CMakeLists.txt @@ -22,3 +22,11 @@ target_link_libraries(SWBBuildSystem PUBLIC SWBCore SWBTaskConstruction SWBTaskExecution) + +set_target_properties(SWBBuildSystem PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBBuildSystem) + +install(TARGETS SWBBuildSystem + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBCAS/CMakeLists.txt b/Sources/SWBCAS/CMakeLists.txt index b35d440e..a2909820 100644 --- a/Sources/SWBCAS/CMakeLists.txt +++ b/Sources/SWBCAS/CMakeLists.txt @@ -19,3 +19,11 @@ set_target_properties(SWBCAS PROPERTIES target_link_libraries(SWBCAS PUBLIC SWBUtil SWBCSupport) + +set_target_properties(SWBCAS PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCAS) + +install(TARGETS SWBCAS + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBCLibc/CMakeLists.txt b/Sources/SWBCLibc/CMakeLists.txt index a5d690b0..26c4f41b 100644 --- a/Sources/SWBCLibc/CMakeLists.txt +++ b/Sources/SWBCLibc/CMakeLists.txt @@ -12,3 +12,11 @@ add_library(SWBCLibc libc.c) target_include_directories(SWBCLibc INTERFACE include) + +target_include_directories(SWBCLibc PUBLIC + ${CMAKE_CURRENT_BINARY_DIR}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCLibc) + +install(TARGETS SWBCLibc + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBCSupport/CLibRemarksHelper.h b/Sources/SWBCSupport/CLibRemarksHelper.h index d22bb643..7f2104b8 100644 --- a/Sources/SWBCSupport/CLibRemarksHelper.h +++ b/Sources/SWBCSupport/CLibRemarksHelper.h @@ -15,8 +15,10 @@ #include +#include "CSupportDefines.h" + // Swift has no way of checking if a weak_import symbol is available. // This function checks if LLVMRemarkVersion from libRemarks.dylib is available, which should be enough to assert the whole library is available as well. -bool isLibRemarksAvailable(void); +CSUPPORT_EXPORT bool isLibRemarksAvailable(void); #endif /* CLibRemarksHelper_h */ diff --git a/Sources/SWBCSupport/CLibclang.h b/Sources/SWBCSupport/CLibclang.h index 04701ae2..438c4c45 100644 --- a/Sources/SWBCSupport/CLibclang.h +++ b/Sources/SWBCSupport/CLibclang.h @@ -19,6 +19,8 @@ #include #include +#include "CSupportDefines.h" + #ifdef __cplusplus extern "C" { #endif @@ -85,85 +87,85 @@ typedef enum { /// Open an interface to libclang, from a given path. /// /// \returns nullptr on error. -libclang_t libclang_open(const char* path); +CSUPPORT_EXPORT libclang_t libclang_open(const char* path); /// Intentionally leak libclang interface. -void libclang_leak(libclang_t lib); +CSUPPORT_EXPORT void libclang_leak(libclang_t lib); /// Close an open libclang interface. -void libclang_close(libclang_t lib); +CSUPPORT_EXPORT void libclang_close(libclang_t lib); /// Get the clang version string. -void libclang_get_clang_version(libclang_t lib, void (^callback)(const char*)); +CSUPPORT_EXPORT void libclang_get_clang_version(libclang_t lib, void (^callback)(const char*)); /// Whether the libclang has the minimal set of required API. -bool libclang_has_required_api(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_required_api(libclang_t lib); /// Whether the libclang has dependency scanning support. -bool libclang_has_scanner(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_scanner(libclang_t lib); /// Whether libclang supports reporting structured scanning diagnostics. -bool libclang_has_structured_scanner_diagnostics(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_structured_scanner_diagnostics(libclang_t lib); /// Create a new scanner instance with optional CAS databases. -libclang_scanner_t libclang_scanner_create(libclang_t lib, libclang_casdatabases_t, libclang_casoptions_t); +CSUPPORT_EXPORT libclang_scanner_t libclang_scanner_create(libclang_t lib, libclang_casdatabases_t, libclang_casoptions_t); /// Dispose of a scanner. -void libclang_scanner_dispose(libclang_scanner_t scanner); +CSUPPORT_EXPORT void libclang_scanner_dispose(libclang_scanner_t scanner); /// Whether the libclang has CAS support. -bool libclang_has_cas(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_cas(libclang_t lib); /// Whether the libclang has CAS plugin support. -bool libclang_has_cas_plugin_feature(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_cas_plugin_feature(libclang_t lib); /// Whether the libclang has CAS pruning support. -bool libclang_has_cas_pruning_feature(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_cas_pruning_feature(libclang_t lib); /// Whether the libclang has CAS up-to-date checking support. -bool libclang_has_cas_up_to_date_checks_feature(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_cas_up_to_date_checks_feature(libclang_t lib); /// Whether the libclang has current working directory optimization support. -bool libclang_has_current_working_directory_optimization(libclang_t lib); +CSUPPORT_EXPORT bool libclang_has_current_working_directory_optimization(libclang_t lib); /// Create the CAS options object. -libclang_casoptions_t libclang_casoptions_create(libclang_t lib); +CSUPPORT_EXPORT libclang_casoptions_t libclang_casoptions_create(libclang_t lib); /// Dispose of the CAS options object. -void libclang_casoptions_dispose(libclang_casoptions_t); +CSUPPORT_EXPORT void libclang_casoptions_dispose(libclang_casoptions_t); /// Set the on-disk path to be used for the CAS database instances. -void libclang_casoptions_setondiskpath(libclang_casoptions_t, const char *path); +CSUPPORT_EXPORT void libclang_casoptions_setondiskpath(libclang_casoptions_t, const char *path); /// Set the plugin library path to be used for the CAS database instances. -void libclang_casoptions_setpluginpath(libclang_casoptions_t, const char *path); +CSUPPORT_EXPORT void libclang_casoptions_setpluginpath(libclang_casoptions_t, const char *path); /// Set a value for a named option that the CAS plugin supports. -void libclang_casoptions_setpluginoption(libclang_casoptions_t, const char *name, const char *value); +CSUPPORT_EXPORT void libclang_casoptions_setpluginoption(libclang_casoptions_t, const char *name, const char *value); /// Create the CAS database instances. -libclang_casdatabases_t libclang_casdatabases_create(libclang_casoptions_t, void (^error_callback)(const char *)); +CSUPPORT_EXPORT libclang_casdatabases_t libclang_casdatabases_create(libclang_casoptions_t, void (^error_callback)(const char *)); /// Dispose of the CAS databases instances. -void libclang_casdatabases_dispose(libclang_casdatabases_t); +CSUPPORT_EXPORT void libclang_casdatabases_dispose(libclang_casdatabases_t); /// Get the local storage size of the CAS/cache data in bytes. /// /// \returns the local storage size, or -1 if the implementation does not support /// reporting such size, or -2 if an error occurred. -int64_t libclang_casdatabases_get_ondisk_size(libclang_casdatabases_t, void (^error_callback)(const char *)); +CSUPPORT_EXPORT int64_t libclang_casdatabases_get_ondisk_size(libclang_casdatabases_t, void (^error_callback)(const char *)); /// Set the size for limiting disk storage growth. /// /// \param size_limit the maximum size limit in bytes. 0 means no limit. Negative values are invalid. /// \returns true if there was an error, false otherwise. -bool libclang_casdatabases_set_ondisk_size_limit(libclang_casdatabases_t, int64_t size_limit, void (^error_callback)(const char *)); +CSUPPORT_EXPORT bool libclang_casdatabases_set_ondisk_size_limit(libclang_casdatabases_t, int64_t size_limit, void (^error_callback)(const char *)); /// Prune local storage to reduce its size according to the desired size limit. /// Pruning can happen concurrently with other operations. /// /// \returns true if there was an error, false otherwise. -bool libclang_casdatabases_prune_ondisk_data(libclang_casdatabases_t, void (^error_callback)(const char *)); +CSUPPORT_EXPORT bool libclang_casdatabases_prune_ondisk_data(libclang_casdatabases_t, void (^error_callback)(const char *)); /// A callback to get the name of a given output. /// @@ -193,7 +195,7 @@ typedef size_t (^module_lookup_output_t)( /// \param callback - A block to invoke for each discovered dependency. /// \param error_callback - A block to invoke on an error. /// \returns True on success, false if the scanner failed. -bool libclang_scanner_scan_dependencies( +CSUPPORT_EXPORT bool libclang_scanner_scan_dependencies( libclang_scanner_t scanner, int argc, char *const *argv, const char *workingDirectory, __attribute__((noescape)) module_lookup_output_t module_lookup_output, __attribute__((noescape)) void (^modules_callback)(clang_module_dependency_set_t, bool), @@ -210,13 +212,13 @@ bool libclang_scanner_scan_dependencies( /// \param envp - A null terminated array of KEY=VALUE pairs (`envp`-style). /// \returns True on success, false on failure (including if the libclang cannot /// support). -bool libclang_driver_get_actions(libclang_t wrapped_lib, - int argc, - char* const* argv, - char* const* envp, - const char* working_directory, - void (^callback)(int argc, const char** argv), - void (^error_callback)(const char*)); +CSUPPORT_EXPORT bool libclang_driver_get_actions(libclang_t wrapped_lib, + int argc, + char* const* argv, + char* const* envp, + const char* working_directory, + void (^callback)(int argc, const char** argv), + void (^error_callback)(const char*)); struct libclang_diagnostic_t_ { char *file_name; @@ -255,31 +257,31 @@ struct libclang_diagnostic_set_t_ { libclang_diagnostic_t *diagnostics; }; -libclang_diagnostic_set_t libclang_read_diagnostics(libclang_t wrapped_lib, - const char* path, - const char** error_string); +CSUPPORT_EXPORT libclang_diagnostic_set_t libclang_read_diagnostics(libclang_t wrapped_lib, + const char* path, + const char** error_string); -void libclang_diagnostic_set_dispose(libclang_diagnostic_set_t diagnostic_set); +CSUPPORT_EXPORT void libclang_diagnostic_set_dispose(libclang_diagnostic_set_t diagnostic_set); -void libclang_cas_load_object_async(libclang_casdatabases_t, const char *casid, void (^callback)(libclang_cas_casobject_t, const char *error)); -void libclang_cas_casobject_dispose(libclang_cas_casobject_t); +CSUPPORT_EXPORT void libclang_cas_load_object_async(libclang_casdatabases_t, const char *casid, void (^callback)(libclang_cas_casobject_t, const char *error)); +CSUPPORT_EXPORT void libclang_cas_casobject_dispose(libclang_cas_casobject_t); -bool libclang_cas_casobject_is_materialized(libclang_casdatabases_t, const char *casid, void (^error_callback)(const char *)); +CSUPPORT_EXPORT bool libclang_cas_casobject_is_materialized(libclang_casdatabases_t, const char *casid, void (^error_callback)(const char *)); -libclang_cas_cached_compilation_t libclang_cas_get_cached_compilation(libclang_casdatabases_t, const char *cache_key, bool globally, void (^error_callback)(const char *)); -void libclang_cas_get_cached_compilation_async(libclang_casdatabases_t, const char *cache_key, bool globally, void (^callback)(libclang_cas_cached_compilation_t, const char *error)); +CSUPPORT_EXPORT libclang_cas_cached_compilation_t libclang_cas_get_cached_compilation(libclang_casdatabases_t, const char *cache_key, bool globally, void (^error_callback)(const char *)); +CSUPPORT_EXPORT void libclang_cas_get_cached_compilation_async(libclang_casdatabases_t, const char *cache_key, bool globally, void (^callback)(libclang_cas_cached_compilation_t, const char *error)); -void libclang_cas_cached_compilation_dispose(libclang_cas_cached_compilation_t); +CSUPPORT_EXPORT void libclang_cas_cached_compilation_dispose(libclang_cas_cached_compilation_t); -size_t libclang_cas_cached_compilation_get_num_outputs(libclang_cas_cached_compilation_t); -void libclang_cas_cached_compilation_get_output_name(libclang_cas_cached_compilation_t, size_t output_idx, void (^callback)(const char*)); -void libclang_cas_cached_compilation_get_output_casid(libclang_cas_cached_compilation_t, size_t output_idx, void (^callback)(const char*)); -bool libclang_cas_cached_compilation_is_output_materialized(libclang_cas_cached_compilation_t, size_t output_idx); -void libclang_cas_cached_compilation_make_global_async(libclang_cas_cached_compilation_t, void (^callback)(const char *error)); +CSUPPORT_EXPORT size_t libclang_cas_cached_compilation_get_num_outputs(libclang_cas_cached_compilation_t); +CSUPPORT_EXPORT void libclang_cas_cached_compilation_get_output_name(libclang_cas_cached_compilation_t, size_t output_idx, void (^callback)(const char*)); +CSUPPORT_EXPORT void libclang_cas_cached_compilation_get_output_casid(libclang_cas_cached_compilation_t, size_t output_idx, void (^callback)(const char*)); +CSUPPORT_EXPORT bool libclang_cas_cached_compilation_is_output_materialized(libclang_cas_cached_compilation_t, size_t output_idx); +CSUPPORT_EXPORT void libclang_cas_cached_compilation_make_global_async(libclang_cas_cached_compilation_t, void (^callback)(const char *error)); /// Synchronous call. /// \returns True on success, false on failure. -bool libclang_cas_replay_compilation(libclang_cas_cached_compilation_t, int argc, char *const *argv, const char *workingDirectory, void (^callback)(const char* diagnostic_text, const char *error)); +CSUPPORT_EXPORT bool libclang_cas_replay_compilation(libclang_cas_cached_compilation_t, int argc, char *const *argv, const char *workingDirectory, void (^callback)(const char* diagnostic_text, const char *error)); #ifdef __cplusplus } diff --git a/Sources/SWBCSupport/CMakeLists.txt b/Sources/SWBCSupport/CMakeLists.txt index 07903eae..c5c09de2 100644 --- a/Sources/SWBCSupport/CMakeLists.txt +++ b/Sources/SWBCSupport/CMakeLists.txt @@ -8,16 +8,30 @@ See http://swift.org/LICENSE.txt for license information See http://swift.org/CONTRIBUTORS.txt for Swift project authors ]] -add_library(SWBCSupport STATIC +add_library(SWBCSupport CLibclang.cpp - CLibRemarksHelper.c) + CLibRemarksHelper.c + empty.swift) +# Use swiftc as the linker so we pick up search paths for the blocks runtime, +# and enable C++ interop so it delegates to clang++. +set_target_properties(SWBCSupport PROPERTIES + LINKER_LANGUAGE Swift) +set_target_properties(SWBCSupport PROPERTIES + Swift_MODULE_NAME __SWBCSupport_Empty) +target_link_options(SWBCSupport PRIVATE + -cxx-interoperability-mode=default) target_compile_definitions(SWBCSupport PRIVATE $<$:_CRT_SECURE_NO_WARNINGS> $<$:_CRT_NONSTDC_NO_WARNINGS>) target_compile_options(SWBCSupport PRIVATE - -fblocks) + "$<$:SHELL:-fblocks>") target_include_directories(SWBCSupport PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) # TODO(compnerd) wire this up with `find_package` target_link_libraries(SWBCSupport PRIVATE $<$>:BlocksRuntime>) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCSupport) + +install(TARGETS SWBCSupport + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBCSupport/CSupportDefines.h b/Sources/SWBCSupport/CSupportDefines.h new file mode 100644 index 00000000..49da425f --- /dev/null +++ b/Sources/SWBCSupport/CSupportDefines.h @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift open source project +// +// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#ifdef _WIN32 +#define CSUPPORT_EXPORT __declspec(dllexport) +#else +#define CSUPPORT_EXPORT +#endif diff --git a/Sources/SWBCSupport/empty.swift b/Sources/SWBCSupport/empty.swift new file mode 100644 index 00000000..8898982c --- /dev/null +++ b/Sources/SWBCSupport/empty.swift @@ -0,0 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift open source project +// +// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +// This file is intentionally left blank. When built with CMake, +// SWBCSupport sets the link language to Swift w/ C++ interop +// to find libblocksruntime, and requires at least one Swift +// source file to avoid downstream issues. diff --git a/Sources/SWBCore/CMakeLists.txt b/Sources/SWBCore/CMakeLists.txt index 467c8aa8..10a5077a 100644 --- a/Sources/SWBCore/CMakeLists.txt +++ b/Sources/SWBCore/CMakeLists.txt @@ -207,3 +207,11 @@ target_link_libraries(SWBCore PUBLIC SwiftDriver) target_sources(SWBCore PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBCore PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBCore) + +install(TARGETS SWBCore + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBGenericUnixPlatform/CMakeLists.txt b/Sources/SWBGenericUnixPlatform/CMakeLists.txt index 8e5213b8..4a7550cf 100644 --- a/Sources/SWBGenericUnixPlatform/CMakeLists.txt +++ b/Sources/SWBGenericUnixPlatform/CMakeLists.txt @@ -28,10 +28,18 @@ file(CONFIGURE ]] ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF) -add_library(SWBGenericUnixPlatform STATIC +add_library(SWBGenericUnixPlatform Plugin.swift) target_link_libraries(SWBGenericUnixPlatform PUBLIC SWBCore SWBUtil) target_sources(SWBGenericUnixPlatform PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBGenericUnixPlatform PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBGenericUnixPlatform) + +install(TARGETS SWBGenericUnixPlatform + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBLLBuild/CMakeLists.txt b/Sources/SWBLLBuild/CMakeLists.txt index 3f36654b..353db118 100644 --- a/Sources/SWBLLBuild/CMakeLists.txt +++ b/Sources/SWBLLBuild/CMakeLists.txt @@ -14,5 +14,12 @@ set_target_properties(SWBLLBuild PROPERTIES Swift_LANGUAGE_VERSION 6) target_link_libraries(SWBLLBuild PUBLIC SWBUtil - $<$>:libllbuild> $<$>:llbuildSwift>) + +set_target_properties(SWBLLBuild PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBLLBuild) + +install(TARGETS SWBLLBuild + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBLibc/CMakeLists.txt b/Sources/SWBLibc/CMakeLists.txt index 8e5daf61..3e9917c6 100644 --- a/Sources/SWBLibc/CMakeLists.txt +++ b/Sources/SWBLibc/CMakeLists.txt @@ -19,3 +19,11 @@ target_link_libraries(SWBLibc PUBLIC # without this explicit configuration. target_include_directories(SWBLibc PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + +set_target_properties(SWBLibc PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBLibc) + +install(TARGETS SWBLibc + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBMacro/CMakeLists.txt b/Sources/SWBMacro/CMakeLists.txt index 4abeddf1..aaa68d49 100644 --- a/Sources/SWBMacro/CMakeLists.txt +++ b/Sources/SWBMacro/CMakeLists.txt @@ -31,5 +31,10 @@ target_link_libraries(SWBMacro PUBLIC SwiftDriver TSCBasic) -target_include_directories(SWBMacro PUBLIC - ${CMAKE_CURRENT_BINARY_DIR}) +set_target_properties(SWBMacro PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBMacro) + +install(TARGETS SWBMacro + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBProjectModel/CMakeLists.txt b/Sources/SWBProjectModel/CMakeLists.txt index 3a98c919..721ae581 100644 --- a/Sources/SWBProjectModel/CMakeLists.txt +++ b/Sources/SWBProjectModel/CMakeLists.txt @@ -20,3 +20,11 @@ set_target_properties(SWBProjectModel PROPERTIES Swift_LANGUAGE_VERSION 6) target_link_libraries(SWBProjectModel PUBLIC SWBProtocol) + +set_target_properties(SWBProjectModel PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBProjectModel) + +install(TARGETS SWBProjectModel + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBProtocol/CMakeLists.txt b/Sources/SWBProtocol/CMakeLists.txt index d00c636b..9208d4b2 100644 --- a/Sources/SWBProtocol/CMakeLists.txt +++ b/Sources/SWBProtocol/CMakeLists.txt @@ -48,3 +48,11 @@ set_target_properties(SWBProtocol PROPERTIES Swift_LANGUAGE_VERSION 6) target_link_libraries(SWBProtocol PUBLIC SWBUtil) + +set_target_properties(SWBProtocol PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBProtocol) + +install(TARGETS SWBProtocol + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBQNXPlatform/CMakeLists.txt b/Sources/SWBQNXPlatform/CMakeLists.txt index b458f8ce..23249e86 100644 --- a/Sources/SWBQNXPlatform/CMakeLists.txt +++ b/Sources/SWBQNXPlatform/CMakeLists.txt @@ -28,7 +28,7 @@ file(CONFIGURE ]] ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF) -add_library(SWBQNXPlatform STATIC +add_library(SWBQNXPlatform Plugin.swift QNXSDP.swift) target_link_libraries(SWBQNXPlatform PUBLIC @@ -37,3 +37,11 @@ target_link_libraries(SWBQNXPlatform PUBLIC SWBUtil) target_sources(SWBQNXPlatform PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBQNXPlatform PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBQNXPlatform) + +install(TARGETS SWBQNXPlatform + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBServiceCore/CMakeLists.txt b/Sources/SWBServiceCore/CMakeLists.txt index 673eec1e..9d39ed50 100644 --- a/Sources/SWBServiceCore/CMakeLists.txt +++ b/Sources/SWBServiceCore/CMakeLists.txt @@ -18,3 +18,11 @@ set_target_properties(SWBServiceCore PROPERTIES Swift_LANGUAGE_VERSION 6) target_link_libraries(SWBServiceCore PUBLIC SWBProtocol) + +set_target_properties(SWBServiceCore PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBServiceCore) + +install(TARGETS SWBServiceCore + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBTaskConstruction/CMakeLists.txt b/Sources/SWBTaskConstruction/CMakeLists.txt index 7657836a..b792f9dc 100644 --- a/Sources/SWBTaskConstruction/CMakeLists.txt +++ b/Sources/SWBTaskConstruction/CMakeLists.txt @@ -63,3 +63,11 @@ set_target_properties(SWBTaskConstruction PROPERTIES target_link_libraries(SWBTaskConstruction PUBLIC SWBCore SWBUtil) + +set_target_properties(SWBTaskConstruction PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBTaskConstruction) + +install(TARGETS SWBTaskConstruction + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBTaskExecution/CMakeLists.txt b/Sources/SWBTaskExecution/CMakeLists.txt index c5bab209..6c7cba03 100644 --- a/Sources/SWBTaskExecution/CMakeLists.txt +++ b/Sources/SWBTaskExecution/CMakeLists.txt @@ -82,3 +82,11 @@ target_link_libraries(SWBTaskExecution PUBLIC SWBLLBuild SWBTaskConstruction SWBUtil) + +set_target_properties(SWBTaskExecution PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBTaskExecution) + +install(TARGETS SWBTaskExecution + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBUniversalPlatform/CMakeLists.txt b/Sources/SWBUniversalPlatform/CMakeLists.txt index f331ab96..7b0fffd7 100644 --- a/Sources/SWBUniversalPlatform/CMakeLists.txt +++ b/Sources/SWBUniversalPlatform/CMakeLists.txt @@ -28,7 +28,7 @@ file(CONFIGURE ]] ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF) -add_library(SWBUniversalPlatform STATIC +add_library(SWBUniversalPlatform CopyPlistFile.swift CopyStringsFile.swift CppTool.swift @@ -48,3 +48,11 @@ target_link_libraries(SWBUniversalPlatform PUBLIC ArgumentParser) target_sources(SWBUniversalPlatform PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBUniversalPlatform PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBUniversalPlatform) + +install(TARGETS SWBUniversalPlatform + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBUtil/CMakeLists.txt b/Sources/SWBUtil/CMakeLists.txt index 0be8ed58..eae57b98 100644 --- a/Sources/SWBUtil/CMakeLists.txt +++ b/Sources/SWBUtil/CMakeLists.txt @@ -111,3 +111,11 @@ target_link_libraries(SWBUtil PUBLIC SWBLibc ArgumentParser $<$>:SwiftSystem::SystemPackage>) + +set_target_properties(SWBUtil PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBUtil) + +install(TARGETS SWBUtil + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBWebAssemblyPlatform/CMakeLists.txt b/Sources/SWBWebAssemblyPlatform/CMakeLists.txt index 8953a5aa..0c12e39a 100644 --- a/Sources/SWBWebAssemblyPlatform/CMakeLists.txt +++ b/Sources/SWBWebAssemblyPlatform/CMakeLists.txt @@ -28,7 +28,7 @@ file(CONFIGURE ]] ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF) -add_library(SWBWebAssemblyPlatform STATIC +add_library(SWBWebAssemblyPlatform Plugin.swift) target_link_libraries(SWBWebAssemblyPlatform PUBLIC SWBCore @@ -36,3 +36,11 @@ target_link_libraries(SWBWebAssemblyPlatform PUBLIC SWBUtil) target_sources(SWBWebAssemblyPlatform PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBWebAssemblyPlatform PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBWebAssemblyPlatform) + +install(TARGETS SWBWebAssemblyPlatform + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SWBWindowsPlatform/CMakeLists.txt b/Sources/SWBWindowsPlatform/CMakeLists.txt index 79e016d4..8f40d3c5 100644 --- a/Sources/SWBWindowsPlatform/CMakeLists.txt +++ b/Sources/SWBWindowsPlatform/CMakeLists.txt @@ -28,7 +28,7 @@ file(CONFIGURE ]] ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF) -add_library(SWBWindowsPlatform STATIC +add_library(SWBWindowsPlatform KnownFolders.swift Plugin.swift VSInstallation.swift) @@ -38,3 +38,11 @@ target_link_libraries(SWBWindowsPlatform PUBLIC SWBUtil) target_sources(SWBWindowsPlatform PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift") + +set_target_properties(SWBWindowsPlatform PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SWBWindowsPlatform) + +install(TARGETS SWBWindowsPlatform + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/Sources/SwiftBuild/CMakeLists.txt b/Sources/SwiftBuild/CMakeLists.txt index 8d1343bc..45970977 100644 --- a/Sources/SwiftBuild/CMakeLists.txt +++ b/Sources/SwiftBuild/CMakeLists.txt @@ -66,3 +66,11 @@ target_link_libraries(SwiftBuild PUBLIC SWBProtocol SWBUtil SWBProjectModel) + +set_target_properties(SwiftBuild PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +set_property(GLOBAL APPEND PROPERTY SWIFTBUILD_EXPORTS SwiftBuild) + +install(TARGETS SwiftBuild + ARCHIVE DESTINATION "${SwiftBuild_INSTALL_LIBDIR}") diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt new file mode 100644 index 00000000..1f05107b --- /dev/null +++ b/cmake/modules/CMakeLists.txt @@ -0,0 +1,9 @@ +set(SWIFTBUILD_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftBuildExports.cmake) + +configure_file(SwiftBuildConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/SwiftBuildConfig.cmake) + +get_property(SWIFTBUILD_EXPORTS GLOBAL PROPERTY SWIFTBUILD_EXPORTS) +export(TARGETS ${SWIFTBUILD_EXPORTS} + NAMESPACE SwiftBuild:: + FILE ${SWIFTBUILD_EXPORTS_FILE}) diff --git a/cmake/modules/SwiftBuildConfig.cmake.in b/cmake/modules/SwiftBuildConfig.cmake.in new file mode 100644 index 00000000..74cb8f0f --- /dev/null +++ b/cmake/modules/SwiftBuildConfig.cmake.in @@ -0,0 +1,3 @@ +if(NOT TARGET SwiftBuild::SwiftBuild) + include(@SWIFTBUILD_EXPORTS_FILE@) +endif()