From 7ae260c0bc50da1cd6580fc89af8ef94af9e6153 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 12 Nov 2023 11:53:52 +0100 Subject: [PATCH] Replace deprecated asan mode by sanitizers options --- .github/workflows/linux-build.yml | 17 ++++++---- tests/xmake.lua | 14 +++----- xmake.lua | 53 ++++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index f7265d7..39af9aa 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -23,8 +23,13 @@ jobs: matrix: os: [ubuntu-latest] arch: [x86_64] - mode: [asan, tsan, ubsan, debug, release] kind: [static, shared] + confs: + - { mode: debug, artifact: true } + - { mode: debug, config: --asan=y, artifact: false } + - { mode: debug, config: --lsan=y, artifact: false } + - { mode: debug, config: --tsan=y, artifact: false } + - { mode: releasedbg, artifact: true } runs-on: ${{ matrix.os }} if: "!contains(github.event.head_commit.message, 'ci skip')" @@ -67,11 +72,11 @@ jobs: uses: actions/cache@v3 with: path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages - key: Linux-${{ matrix.arch }}-${{ matrix.mode }}-${{ steps.dep_hash.outputs.hash }}-W${{ steps.cache_key.outputs.key }} + key: Linux-${{ matrix.arch }}-${{ matrix.confs.mode }}-${{ steps.dep_hash.outputs.hash }}-W${{ steps.cache_key.outputs.key }} # Setup compilation mode and install project dependencies - name: Configure xmake and install dependencies - run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --kind=${{ matrix.kind }} --ccache=n --examples=y --tests=y --unitybuild=y --yes + run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.confs.mode }} --kind=${{ matrix.kind }} --ccache=n --examples=y --tests=y --unitybuild=y --yes # Build library and tests - name: Build library @@ -83,12 +88,12 @@ jobs: # Install the result files - name: Install NZSL - if: ${{ matrix.mode }} == 'debug' || ${{ matrix.mode }} == 'release' + if: ${{ matrix.confs.artifact }} run: xmake install -vo package # Upload artifacts - uses: actions/upload-artifact@v3 - if: ${{ matrix.mode }} == 'debug' || ${{ matrix.mode }} == 'release' + if: ${{ matrix.confs.artifact }} with: - name: nzsl-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.kind }}-${{ matrix.mode }} + name: nzsl-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.kind }}-${{ matrix.confs.mode }} path: package diff --git a/tests/xmake.lua b/tests/xmake.lua index 7b62799..4084e53 100644 --- a/tests/xmake.lua +++ b/tests/xmake.lua @@ -1,22 +1,17 @@ -option("tests") - set_default(false) - set_showmenu(true) - set_description("Build unit tests") - -option_end() +option("tests", { description = "Build unit tests", default = false }) if has_config("tests") then - if is_mode("asan") then + if has_config("asan") then add_defines("CATCH_CONFIG_NO_WINDOWS_SEH") add_defines("CATCH_CONFIG_NO_POSIX_SIGNALS") end add_requires("catch2 3", "spirv-tools", "tiny-process-library") - add_requires("glslang", { configs = { rtti = is_mode("ubsan") } }) -- ubsan requires rtti + add_requires("glslang", { configs = { rtti = has_config("ubsan") } }) -- ubsan requires rtti add_includedirs("src") - target("UnitTests") + target("UnitTests", function () set_kind("binary") set_group("Tests") add_headerfiles("src/**.hpp") @@ -32,4 +27,5 @@ if has_config("tests") then else remove_files("src/Tests/NzslcTests.cpp") end + end) end diff --git a/xmake.lua b/xmake.lua index 9006986..db3a24b 100644 --- a/xmake.lua +++ b/xmake.lua @@ -8,6 +8,21 @@ option("fs_watcher", { default = true, description = "Compiles with filesystem w option("unitybuild", { default = false, description = "Build the library using unity build"}) option("with_nzslc", { default = true, description = "Builds the standalone command-line compiler (nzslc)"}) +-- Sanitizers +local sanitizers = { + asan = "address", + lsan = "leak", + tsan = "thread", +} + +for opt, policy in table.orderpairs(sanitizers) do + option(opt, { description = "Enable " .. opt, default = false }) + + if has_config(opt) then + set_policy("build.sanitizer." .. policy, true) + end +end + ----------------------- Dependencies ----------------------- add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo") @@ -24,7 +39,7 @@ end ----------------------- Global config ----------------------- -add_rules("mode.asan", "mode.tsan", "mode.ubsan", "mode.coverage", "mode.debug", "mode.releasedbg", "mode.release") +add_rules("mode.coverage", "mode.debug", "mode.releasedbg", "mode.release") add_rules("plugin.vsxmake.autoupdate") add_includedirs("include", "src") @@ -44,12 +59,28 @@ if is_plat("mingw", "linux") then end if is_plat("windows") then - add_defines("_CRT_SECURE_NO_WARNINGS") - add_cxxflags("/bigobj", "/permissive-", "/Zc:__cplusplus", "/Zc:externConstexpr", "/Zc:inline", "/Zc:lambda", "/Zc:preprocessor", "/Zc:referenceBinding", "/Zc:strictStrings", "/Zc:throwingNew") - add_cxflags("/w44062") -- Enable warning: switch case not handled - add_cxflags("/wd4251") -- Disable warning: class needs to have dll-interface to be used by clients of class blah blah blah - add_cxflags("/wd4275") -- Disable warning: DLL-interface class 'class_1' used as base for DLL-interface blah -elseif is_plat("mingw") then + -- MSVC + add_cxxflags("/bigobj", "/permissive-", "/Zc:__cplusplus", "/Zc:externConstexpr", "/Zc:inline", "/Zc:lambda", "/Zc:preprocessor", "/Zc:referenceBinding", "/Zc:strictStrings", "/Zc:throwingNew", {tools = "cl"}) + add_defines("_CRT_SECURE_NO_WARNINGS", "_ENABLE_EXTENDED_ALIGNED_STORAGE") + + -- Enable the following additional warnings: + add_cxflags("/we4062", {tools = "cl"}) -- Switch case not handled (warning as error) + add_cxflags("/we4426", {tools = "cl"}) -- Optimization flags changed after including header, may be due to #pragma optimize() (warning as error) + add_cxflags("/we5038", {tools = "cl"}) -- Data member will be initialized after data member (warning as error) + + -- Disable the following warnings: + add_cxflags("/wd4251", {tools = "cl"}) -- class needs to have dll-interface to be used by clients of class blah blah blah + add_cxflags("/wd4275", {tools = "cl"}) -- DLL-interface class 'class_1' used as base for DLL-interface blah +else + -- GCC-compatible (GCC, Clang, ...) + add_cxflags("-Wtrampolines") + add_cxflags("-Werror=inconsistent-missing-override", {tools = "clang"}) + add_cxflags("-Werror=reorder") + add_cxflags("-Werror=suggest-override", {tools = "gcc"}) + add_cxflags("-Werror=switch") +end + +if is_plat("mingw") then add_cxflags("-Wa,-mbig-obj") add_ldflags("-Wa,-mbig-obj") -- Always enable at least -Os optimization with MinGW to fix "string table overflow" error @@ -68,8 +99,6 @@ end if is_mode("debug") then add_rules("debug_suffix") -elseif is_mode("asan", "tsan", "ubsan") then - set_optimize("none") -- by default xmake will optimize asan builds elseif is_mode("coverage") then if not is_plat("windows") then add_links("gcov") @@ -85,7 +114,7 @@ end ----------------------- Targets ----------------------- -target("nzsl") +target("nzsl", function () set_kind("$(kind)") set_group("Libraries") add_defines("NZSL_BUILD") @@ -107,9 +136,10 @@ target("nzsl") target:add("defines", "NZSL_STATIC", { public = true }) end end) +end) if has_config("with_nzslc") then - target("nzslc") + target("nzslc", function () set_kind("binary") set_group("Executables") add_headerfiles("src/(ShaderCompiler/**.hpp)") @@ -117,6 +147,7 @@ if has_config("with_nzslc") then add_files("src/ShaderCompiler/**.cpp") add_deps("nzsl") add_packages("cxxopts", "fmt", "frozen", "nlohmann_json") + end) end includes("xmake/**.lua")