From f475800f7b34285a89c2c4b10c89d4d34f21edbe Mon Sep 17 00:00:00 2001 From: star9029 Date: Sun, 19 Jan 2025 19:54:25 +0800 Subject: [PATCH] Improve CI (#46) --- .github/workflows/cmake.yml | 12 ++++++------ .github/workflows/xmake.yml | 39 ++++++++++++++++++++++++++----------- cmake/toolchain.cmake | 9 ++++++--- xmake.lua | 11 ++++++----- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b5a7edac..9ad23f58 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -11,6 +11,7 @@ on: - '.gitignore' - 'LICENSE' - 'README.md' + - '.github/workflows/xmake.yml' jobs: build: @@ -41,10 +42,9 @@ jobs: sudo update-alternatives --set gcc /usr/bin/gcc-14 sudo update-alternatives --set g++ /usr/bin/g++-14 - wget -O - https://apt.llvm.org/llvm.sh | sudo bash - sudo apt install -y llvm-18 llvm-18-tools clang-18 libclang-rt-18-dev lld-18 - sudo ln -s /usr/bin/llvm-ar-18 /usr/bin/llvm-ar - sudo ln -s /usr/bin/llvm-ranlib-18 /usr/bin/llvm-ranlib + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 20 all sudo apt install -y cmake ninja-build @@ -67,13 +67,13 @@ jobs: if: matrix.os == 'windows-2022' uses: ilammy/msvc-dev-cmd@v1 - - name: Build clice + - name: Build clice (debug) if: matrix.os == 'ubuntu-24.04' run: | cmake --preset debug cmake --build --preset debug - - name: Build clice + - name: Build clice (release) if: matrix.os == 'windows-2022' run: | cmake --preset release diff --git a/.github/workflows/xmake.yml b/.github/workflows/xmake.yml index de73f211..fed0a3c7 100644 --- a/.github/workflows/xmake.yml +++ b/.github/workflows/xmake.yml @@ -11,12 +11,14 @@ on: - '.gitignore' - 'LICENSE' - 'README.md' + - '.github/workflows/cmake.yml' jobs: build: strategy: matrix: os: [ubuntu-24.04, windows-2022] + build_type: [release, debug] runs-on: ${{ matrix.os }} @@ -41,24 +43,39 @@ jobs: sudo update-alternatives --set gcc /usr/bin/gcc-14 sudo update-alternatives --set g++ /usr/bin/g++-14 - wget -O - https://apt.llvm.org/llvm.sh | sudo bash - sudo apt install -y llvm-18 llvm-18-tools clang-18 libclang-rt-18-dev lld-18 - sudo ln -s /usr/bin/llvm-ar-18 /usr/bin/llvm-ar - sudo ln -s /usr/bin/llvm-ranlib-18 /usr/bin/llvm-ranlib + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 20 all - sudo apt install -y cmake ninja-build - - - name: Setup xmake - uses: xmake-io/github-action-setup-xmake@v1 - with: - xmake-version: '2.9.7' + sudo apt install -y cmake ninja-build - name: Checkout repository uses: actions/checkout@v4 + - name: Setup xmake + uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: branch@master + actions-cache-folder: '.xmake-cache' + actions-cache-key: ${{ matrix.os }} + package-cache: true + package-cache-key: ${{ matrix.os }} + build-cache: true + build-cache-key: ${{ matrix.os }}-${{ matrix.build_type }} + + - name: Xmake configure + if: matrix.os == 'ubuntu-24.04' + run: | + xmake config --yes --mode=${{ matrix.build_type }} --toolchain=clang-20 + + - name: Xmake configure + if: matrix.os == 'windows-2022' + run: | + xmake config --yes --toolchain=clang + - name: Build clice run: | - xmake --yes --diagnosis + xmake --verbose --diagnosis - name: Run tests run: xmake test --verbose diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake index c49616de..ca398a6c 100644 --- a/cmake/toolchain.cmake +++ b/cmake/toolchain.cmake @@ -1,8 +1,11 @@ if(WIN32) set(CMAKE_SYSTEM_NAME Windows) + + set(CMAKE_C_COMPILER clang) + set(CMAKE_CXX_COMPILER clang++) else() set(CMAKE_SYSTEM_NAME Linux) -endif() -set(CMAKE_C_COMPILER clang) -set(CMAKE_CXX_COMPILER clang++) + set(CMAKE_C_COMPILER clang-20) + set(CMAKE_CXX_COMPILER clang++-20) +endif() diff --git a/xmake.lua b/xmake.lua index 8d19cbbc..0fd51a65 100644 --- a/xmake.lua +++ b/xmake.lua @@ -11,6 +11,11 @@ if has_config("dev") then set_policy("compatibility.version", "3.0") if is_plat("windows") then set_runtimes("MD") + if is_mode("debug") then + print("Clice does not support build in debug mode with pre-compiled llvm binary on windows.\n" + .."See https://github.com/clice-project/clice/issues/42 for more information.") + os.raise() + end elseif is_plat("linux") and is_mode("debug") then set_policy("build.sanitizer.address", true) end @@ -101,8 +106,6 @@ target("unit_tests") rule("clice_build_config") on_load(function (target) - target:set("toolchains", "clang") - target:add("cxflags", "-fno-rtti", {tools = {"clang", "gcc"}}) target:add("cxflags", "/GR-", {tools = {"clang_cl", "cl"}}) target:set("exceptions", "no-cxx") @@ -119,9 +122,7 @@ package("llvm") if is_mode("release") then add_urls("https://github.com/clice-project/llvm-binary/releases/download/$(version)/x64-windows-msvc-release.7z") add_versions("20.0.0", "ba3fcd482340b8f892f02b9fc2a233a3ba0e0931fdf4e84a3e2a2ec47283d096") - else - os.raise("Clice does not support build in debug mode with pre-compiled llvm binary on windows.\n" - .."See https://github.com/clice-project/clice/issues/42 for more information.") + else end elseif is_plat("linux") then if is_mode("debug") then