diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 85434b95..1aa6f972 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -16,11 +16,18 @@ jobs: build: strategy: matrix: - os: [ubuntu-24.04] + os: [ubuntu-24.04, windows-2022] runs-on: ${{ matrix.os }} steps: + - name: Setup llvm & ninja + if: matrix.os == 'windows-2022' + uses: MinoruSekine/setup-scoop@v4.0.1 + with: + buckets: main + apps: llvm ninja + - name: Setup llvm & libstdc++ & cmake & ninja if: matrix.os == 'ubuntu-24.04' run: | @@ -40,7 +47,7 @@ jobs: sudo ln -s /usr/bin/llvm-ranlib-18 /usr/bin/llvm-ranlib sudo apt install -y cmake ninja-build - + - name: Checkout repository uses: actions/checkout@v4 @@ -50,10 +57,21 @@ jobs: mkdir -p ./.llvm curl -L "https://github.com/clice-project/llvm-binary/releases/download/20.0.0/x86_64-linux-gnu-release.tar.xz" | tar -xJ -C ./.llvm + - name: Setup llvm binary + if: matrix.os == 'windows-2022' + run: | + curl -O -L "https://github.com/clice-project/llvm-binary/releases/download/20.0.0/x64-windows-msvc-release.7z" + 7z x x64-windows-msvc-release.7z "-o.llvm" + + - name: Setup msvc sysroot for cmake + if: matrix.os == 'windows-2022' + uses: ilammy/msvc-dev-cmd@v1 + - name: Build clice run: | - cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCLICE_ENABLE_TEST=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DLLVM_INSTALL_PATH="./.llvm" - cmake --build build - + cmake --preset release + cmake --build --preset release + - name: Run tests - run: ./build/bin/unit_tests --test-dir="./tests" --resource-dir="./.llvm/lib/clang/20" + run: | + ./build/bin/unit_tests --test-dir="./tests" --resource-dir="./.llvm/lib/clang/20" diff --git a/.github/workflows/xmake.yml b/.github/workflows/xmake.yml index bcec1701..de73f211 100644 --- a/.github/workflows/xmake.yml +++ b/.github/workflows/xmake.yml @@ -59,6 +59,6 @@ jobs: - name: Build clice run: | xmake --yes --diagnosis - + - name: Run tests run: xmake test --verbose diff --git a/CMakeLists.txt b/CMakeLists.txt index 7517ce32..15a25583 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,57 @@ cmake_minimum_required(VERSION 3.20) project(CLICE_PROJECT) -include(FetchContent) - set(CMAKE_CXX_STANDARD 23) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) if(NOT DEFINED LLVM_INSTALL_PATH OR LLVM_INSTALL_PATH STREQUAL "") - message(FATAL_ERROR "Error: The variable LLVM_INSTALL_PATH is not set. Please specify it with -LLVM_INSTALL_PATH=.") + message(FATAL_ERROR "Error: The variable LLVM_INSTALL_PATH is not set. Please specify it with -DLLVM_INSTALL_PATH=.") endif() set(CMAKE_PREFIX_PATH "${LLVM_INSTALL_PATH}") -find_package(LLVM REQUIRED CONFIG) -find_package(Clang REQUIRED CONFIG) +# https://github.com/llvm/llvm-project/issues/86250 +if(NOT WIN32) + find_package(LLVM REQUIRED CONFIG) + find_package(Clang REQUIRED CONFIG) +endif() message(STATUS "Found LLVM ${LLVM_INCLUDE_DIRS}") +if(CLICE_DEV) + include(FetchContent) + + FetchContent_Declare( + tomlplusplus + GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git + ) + FetchContent_Declare( + libuv + GIT_REPOSITORY https://github.com/libuv/libuv.git + GIT_TAG v1.x + ) + FetchContent_MakeAvailable(tomlplusplus libuv) + + if(WIN32) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") + endif() +else() + find_package(tomlplusplus REQUIRED CONFIG) + find_package(libuv REQUIRED CONFIG) +endif() + if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions -g -O0 -fsanitize=address -Wno-deprecated-declarations") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fuse-ld=lld -fsanitize=address") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld -fsanitize=address") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions -O3 -Wno-deprecated-declarations") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fuse-ld=lld") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld") + if(WIN32) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fuse-ld=lld-link") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld-link") + else() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld") + endif() endif() if(WIN32) @@ -50,36 +78,31 @@ target_precompile_headers(clice-core PRIVATE # set llvm include and lib path target_include_directories(clice-core PUBLIC "${LLVM_INSTALL_PATH}/include") target_link_directories(clice-core PUBLIC "${LLVM_INSTALL_PATH}/lib") -target_link_libraries(clice-core PUBLIC - LLVMSupport - clangAST - clangASTMatchers - clangBasic - clangDependencyScanning - clangDriver - clangFormat - clangFrontend - clangIndex - clangLex - clangSema - clangSerialization - clangTooling - clangToolingCore - clangToolingInclusions - clangToolingInclusionsStdlib - clangToolingSyntax -) -FetchContent_Declare( - tomlplusplus - GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git -) -FetchContent_Declare( - libuv - GIT_REPOSITORY https://github.com/libuv/libuv.git - GIT_TAG v1.x -) -FetchContent_MakeAvailable(tomlplusplus libuv) +if(NOT WIN32) + target_link_libraries(clice-core PUBLIC + LLVMSupport + clangAST + clangASTMatchers + clangBasic + clangDependencyScanning + clangDriver + clangFormat + clangFrontend + clangIndex + clangLex + clangSema + clangSerialization + clangTooling + clangToolingCore + clangToolingInclusions + clangToolingInclusionsStdlib + clangToolingSyntax + ) +else() + file(GLOB LLVM_LIBRARIES "${LLVM_INSTALL_PATH}/lib/*.lib") + target_link_libraries(clice-core PUBLIC ${LLVM_LIBRARIES} version ntdll) +endif() target_include_directories(clice-core PUBLIC "${CMAKE_SOURCE_DIR}/include") target_link_libraries(clice-core PUBLIC uv tomlplusplus::tomlplusplus) @@ -106,5 +129,3 @@ if(CLICE_ENABLE_TEST) target_link_libraries(unit_tests PRIVATE gtest_main clice-core) endif() - - diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..98f205d6 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,39 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "config-base", + "hidden": true, + "displayName": "base Configuration", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "toolchainFile": "${sourceDir}/cmake/toolchain.cmake", + "cacheVariables": { + "CLICE_DEV": "ON", + "CLICE_ENABLE_TEST": "ON", + "LLVM_INSTALL_PATH": "./.llvm" + } + }, + { + "name": "release", + "displayName": "Config Release", + "description": "Sets release build type", + "inherits": "config-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ], + "buildPresets": [ + { + "name": "release", + "configurePreset": "release" + } + ] +} \ No newline at end of file diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake new file mode 100644 index 00000000..c49616de --- /dev/null +++ b/cmake/toolchain.cmake @@ -0,0 +1,8 @@ +if(WIN32) + set(CMAKE_SYSTEM_NAME Windows) +else() + set(CMAKE_SYSTEM_NAME Linux) +endif() + +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) diff --git a/xmake.lua b/xmake.lua index 8780f2fd..a4a099d9 100644 --- a/xmake.lua +++ b/xmake.lua @@ -20,8 +20,7 @@ if has_config("dev") then end end -add_requires("toml++", "libuv") -add_requires("llvm") +add_requires("llvm", "libuv") add_rules("mode.release", "mode.debug") set_languages("c++23") @@ -77,7 +76,7 @@ rule("clice_build_config") if target:is_plat("windows") then target:add("ldflags", "-fuse-ld=lld-link") elseif target:is_plat("linux") then - -- gnu ld will cause link order + -- gnu ld need to fix link order target:add("ldflags", "-fuse-ld=lld") end end) @@ -86,11 +85,11 @@ package("llvm") if is_plat("windows") then add_urls("https://github.com/clice-project/llvm-binary/releases/download/$(version)/x64-windows-msvc-release.7z") - add_versions("20.0.0", "6dc78ca012fa5cc365394b72371b7aaff24a5b1a92fc204ea634f9d360bef694") + add_versions("20.0.0", "ba3fcd482340b8f892f02b9fc2a233a3ba0e0931fdf4e84a3e2a2ec47283d096") elseif is_plat("linux") then add_urls("https://github.com/clice-project/llvm-binary/releases/download/$(version)/x86_64-linux-gnu-release.tar.xz") - add_versions("20.0.0", "4c8a52ee3ac8ae34e4fa4ae49a6488f6ff8454386ef0e5617dc90a09e8032f74") + add_versions("20.0.0", "76de8585494955090c79976d8e71bd719f68fc6dc8d06687284cff19266e4c11") end if is_plat("windows") then