From 9e55381788c4d891faafa3e1375a026ac8488eb1 Mon Sep 17 00:00:00 2001 From: star9029 Date: Sat, 6 Sep 2025 00:40:55 +0800 Subject: [PATCH] Improve build (#226) --- docs/en/dev/build.md | 7 ++----- docs/zh/dev/build.md | 7 ++----- src/Async/FileSystem.cpp | 8 ++++---- xmake.lua | 5 +++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/docs/en/dev/build.md b/docs/en/dev/build.md index a88be58c..07b0ecbf 100644 --- a/docs/en/dev/build.md +++ b/docs/en/dev/build.md @@ -143,10 +143,7 @@ Or, if you use xmake build the project and do not have uv installed, you can use $ pip install pytest pytest-asyncio $ xmake f -m debug && xmake build unit_tests -# The environment variable LLVM_INSTALL_DIR may vary in different commits and platforms, -# depending on the value of `set_versions` in the `package("llvm")` section of the xmake.lua -$ LLVM_INSTALL_DIR=./build/.packages/l/llvm/20.1.5/0181167384bb4acb9e781210294c358d/lib/clang/20/ \ - pytest -s --log-cli-level=INFO tests/integration \ +$ pytest -s --log-cli-level=INFO tests/integration \ --executable=./build/linux/x86_64/debug/clice \ - --resource-dir=$LLVM_INSTALL_DIR + --resource-dir=./build/linux/x86_64/debug/lib/clang/20/ ``` diff --git a/docs/zh/dev/build.md b/docs/zh/dev/build.md index 83cb5a5a..d2a4dc45 100644 --- a/docs/zh/dev/build.md +++ b/docs/zh/dev/build.md @@ -142,10 +142,7 @@ $ xmake test --verbose integration_tests/default $ pip install pytest pytest-asyncio $ xmake f -m debug && xmake build unit_tests -# 此处的 LLVM_INSTALL_DIR 在不同版本, 不同平台的 clice 中 sha 值可能不一样, -# 取决于对应的 xmake.lua 中 `package("llvm")` 一节 `set_versions` 的取值 -$ LLVM_INSTALL_DIR=./build/.packages/l/llvm/20.1.5/0181167384bb4acb9e781210294c358d/lib/clang/20/ \ - pytest -s --log-cli-level=INFO tests/integration \ +$ pytest -s --log-cli-level=INFO tests/integration \ --executable=./build/linux/x86_64/debug/clice \ - --resource-dir=$LLVM_INSTALL_DIR + --resource-dir=./build/linux/x86_64/debug/lib/clang/20/ ``` diff --git a/src/Async/FileSystem.cpp b/src/Async/FileSystem.cpp index f2a3561e..25539d88 100644 --- a/src/Async/FileSystem.cpp +++ b/src/Async/FileSystem.cpp @@ -140,7 +140,7 @@ Result open(std::string path, Mode mode) { // Adding /EHa won't help. // Related: // https://developercommunity.visualstudio.com/t/coroutine-compilation-resulting-in-error-c4737-una/1510427 -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) #pragma optimize("g", off) #endif Result read(const handle& handle, char* buffer, std::size_t size) { @@ -149,7 +149,7 @@ Result read(const handle& handle, char* buffer, std::size_t size) { .bufs = {uv_buf_init(buffer, size)}, }; } -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) #pragma optimize("g", on) #endif @@ -198,7 +198,7 @@ Result read(std::string path, Mode mode) { // Adding /EHa won't help. // Related: // https://developercommunity.visualstudio.com/t/coroutine-compilation-resulting-in-error-c4737-una/1510427 -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) #pragma optimize("g", off) #endif Result write(const handle& handle, char* buffer, std::size_t size) { @@ -207,7 +207,7 @@ Result write(const handle& handle, char* buffer, std::size_t size) { .bufs = {uv_buf_init(buffer, size)}, }; } -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) #pragma optimize("g", on) #endif diff --git a/xmake.lua b/xmake.lua index 26967e5e..a007a8bb 100644 --- a/xmake.lua +++ b/xmake.lua @@ -11,6 +11,7 @@ option("llvm", {default = nil, description = "Specify pre-compiled llvm binary d option("ci", {default = false}) if has_config("dev") then + set_policy("build.ccache", true) set_policy("compatibility.version", "3.0") if is_plat("windows") then set_runtimes("MD") @@ -98,7 +99,7 @@ target("clice") end) after_build(function (target) - local res_dir = path.join(target:targetdir(), "lib") + local res_dir = path.join(target:targetdir(), "lib/clang") if not os.exists(res_dir) then local llvm_dir = target:dep("clice-core"):pkg("llvm"):installdir() os.vcp(path.join(llvm_dir, "lib/clang"), res_dir) @@ -162,7 +163,7 @@ rule("clice_build_config") -- Fix MSVC Non-standard preprocessor caused error C1189 -- While compiling Command.cpp, MSVC won't expand Options macro correctly -- Output: D:\Desktop\code\clice\build\.packages\l\llvm\20.1.5\cc2aa9f1d09a4b71b6fa3bf0011f6387\include\clang/Driver/Options.inc(3590): error C2365: “clang::driver::options::OPT_”: redefinition; previous definition was 'enumerator' - target:add("cxflags", "/Zc:preprocessor", {tools = {"cl"}}) + target:add("cxflags", "cl::/Zc:preprocessor") target:set("exceptions", "no-cxx")