From a05f02cf273fa12c091d67cf42bb7a86691175ed Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 29 Dec 2022 17:48:53 -0800 Subject: [PATCH 1/2] build: make `libllbuild` static Rather than emitting `libllbuild` as a dynamic library, expose it as a static library. This is used by a single user (`llbuildSwift`), and thus allows for simplification of the distribution. We no longer export libllbuild as the clients are using llbuildSwift. Because the module is not imported as `@_implementationOnly`, we need to expose the include path for `libllbuild` to clients of `llbuildSwift`. --- CMakeLists.txt | 2 +- cmake/modules/Utility.cmake | 6 ++++-- products/libllbuild/CMakeLists.txt | 6 +----- products/llbuildSwift/CMakeLists.txt | 3 +-- tests/Examples/buildsystem-capi.llbuild | 2 +- tests/lit.cfg | 5 +++++ tests/lit.site.cfg.in | 12 ++++++++++++ 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 766e38e7..e7c0e158 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ else() endif() endif() -set(THREADS_PREFER_PTHREAD_FLAG TRUE) +set(THREADS_PREFER_PTHREAD_FLAG FALSE) find_package(Threads REQUIRED) find_package(SQLite3 REQUIRED) diff --git a/cmake/modules/Utility.cmake b/cmake/modules/Utility.cmake index df381927..c1754c4a 100644 --- a/cmake/modules/Utility.cmake +++ b/cmake/modules/Utility.cmake @@ -10,7 +10,7 @@ endfunction() macro(add_llbuild_library name) cmake_parse_arguments(ARG - "SHARED" "OUTPUT_NAME" "" + "SHARED;STATIC" "OUTPUT_NAME" "" ${ARGN}) set(ALL_FILES ${ARG_UNPARSED_ARGUMENTS}) @@ -42,8 +42,10 @@ macro(add_llbuild_library name) endif() endif(MSVC_IDE OR XCODE) - if (ARG_SHARED) + if(ARG_SHARED) add_library(${name} SHARED ${ALL_FILES}) + elseif(ARG_STATIC) + add_library(${name} STATIC ${ALL_FILES}) else() add_library(${name} ${ALL_FILES}) endif() diff --git a/products/libllbuild/CMakeLists.txt b/products/libllbuild/CMakeLists.txt index e8eb2ec2..6ab94250 100644 --- a/products/libllbuild/CMakeLists.txt +++ b/products/libllbuild/CMakeLists.txt @@ -9,10 +9,8 @@ set(SOURCES add_llbuild_library(libllbuild ${SOURCES} - SHARED + STATIC OUTPUT_NAME llbuild) -target_compile_definitions(libllbuild PRIVATE - _WINDLL) set_property(TARGET libllbuild PROPERTY MACOSX_RPATH ON) @@ -24,8 +22,6 @@ target_link_libraries(libllbuild PRIVATE llvmSupport SQLite::SQLite3) -set_property(GLOBAL APPEND PROPERTY LLBuild_EXPORTS libllbuild) - if(CMAKE_SYSTEM_NAME STREQUAL Windows) set_target_properties(libllbuild PROPERTIES LINK_FLAGS "/INCREMENTAL:NO") endif() diff --git a/products/llbuildSwift/CMakeLists.txt b/products/llbuildSwift/CMakeLists.txt index aabc3f2e..4005d7bc 100644 --- a/products/llbuildSwift/CMakeLists.txt +++ b/products/llbuildSwift/CMakeLists.txt @@ -70,8 +70,7 @@ else() endif() set_target_properties(llbuildSwift PROPERTIES Swift_MODULE_NAME llbuildSwift - INTERFACE_LINK_LIBRARIES libllbuild - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR};${PROJECT_SOURCE_DIR}/products/libllbuild/include") install(TARGETS llbuildSwift ARCHIVE DESTINATION lib/swift/pm/llbuild COMPONENT libllbuildSwift diff --git a/tests/Examples/buildsystem-capi.llbuild b/tests/Examples/buildsystem-capi.llbuild index 40ec6e3e..a2184a48 100644 --- a/tests/Examples/buildsystem-capi.llbuild +++ b/tests/Examples/buildsystem-capi.llbuild @@ -1,6 +1,6 @@ # Check that the BuildSystem C API example builds and runs correctly. # -# RUN: %clang -o %t.exe %{srcroot}/examples/c-api/buildsystem/main.c -I %{srcroot}/products/libllbuild/include -lllbuild -L %{llbuild-lib-dir} -Werror +# RUN: %clangxx -o %t.exe -x c++ %{srcroot}/examples/c-api/buildsystem/main.c -I %{srcroot}/products/libllbuild/include -lllbuild -lllbuildBuildSystem -lllbuildCore -lllbuildBasic -lllvmSupport -lLLVMDemangle -L %{llbuild-lib-dir} -Werror -Xlinker %{sqlite} %{curses} %{threads} %{dl} # RUN: env DYLD_LIBRARY_PATH=%{llbuild-lib-dir} LD_LIBRARY_PATH=%{llbuild-lib-dir} %t.exe %s > %t.out # RUN: %{FileCheck} %s --input-file %t.out # diff --git a/tests/lit.cfg b/tests/lit.cfg index 6a4a5a2c..6f6f8c11 100644 --- a/tests/lit.cfg +++ b/tests/lit.cfg @@ -128,6 +128,10 @@ config.substitutions.append( ('%{llbuild-lib-dir}', llbuild_lib_dir) ) config.substitutions.append( ('%{llbuild-output-dir}', llbuild_output_dir) ) config.substitutions.append( ('%{llbuild-tools-dir}', llbuild_tools_dir) ) config.substitutions.append( ('%{srcroot}', llbuild_src_root) ) +config.substitutions.append( ('%{sqlite}', config.sqlite_library) ) +config.substitutions.append( ('%{curses}', config.curses_library) ) +config.substitutions.append( ('%{threads}', config.threads_library) ) +config.substitutions.append( ('%{dl}', config.dl_library) ) if config.osx_sysroot: config.substitutions.append( ('%{swiftc-platform-flags}', "-sdk " + config.osx_sysroot) ) @@ -138,6 +142,7 @@ config.substitutions.append( ('%{build-dir}', llbuild_obj_root) ) config.substitutions.append( ('%{env}', lit.util.which('env')) ) config.substitutions.append( ('%{sort}', lit.util.which('sort')) ) config.substitutions.append( ('%{sh-invoke}', os.environ.get("PREFIX", "") + '/bin/sh') ) +config.substitutions.append( ('%clangxx', inferSwiftBinary('clang++')) ) config.substitutions.append( ('%clang', inferSwiftBinary('clang')) ) ### diff --git a/tests/lit.site.cfg.in b/tests/lit.site.cfg.in index e9da8b72..b0dcf605 100644 --- a/tests/lit.site.cfg.in +++ b/tests/lit.site.cfg.in @@ -1,6 +1,7 @@ # -*- Python -*- import os +import sys ## Autogenerated by llbuild configuration. # Do not edit! @@ -16,6 +17,17 @@ config.filecheck_path = "@FILECHECK_EXECUTABLE@" config.swiftc_path = "@CMAKE_Swift_COMPILER@" config.osx_sysroot = "@CMAKE_OSX_SYSROOT@" +config.sqlite_library = "@SQLite3_LIBRARY@" +if sys.platform == 'Windows': + config.curses_library = '' +else: + config.curses_library = '-lcurses' +config.threads_library = "@CMAKE_THREAD_LIBS_INIT@" +if "@CMAKE_DL_LIBS@": + config.dl_library = "-l@CMAKE_DL_LIBS@" +else: + config.dl_library = '' + # Support substitution of the tools_dir with user parameters. This is # used when we can't determine the tool dir at configuration time. try: From a2bfbc1b1d22dacc069e9e5eaaafb2b7f0385cd8 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 13 Feb 2023 14:41:26 -0800 Subject: [PATCH 2/2] examples: repair the example on Linux --- examples/c-api/buildsystem/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/c-api/buildsystem/main.c b/examples/c-api/buildsystem/main.c index a93cd419..02d291d4 100644 --- a/examples/c-api/buildsystem/main.c +++ b/examples/c-api/buildsystem/main.c @@ -32,10 +32,12 @@ static void usage() { exit(0); } +#if !defined(__linux__) static const char* basename(const char* path) { const char* result = strrchr(path, '/'); return result ? result : path; } +#endif #if defined(_WIN32) static wchar_t* convertToMultiByte(const char* s) {