Skip to content

Commit

Permalink
Replace deprecated asan mode by sanitizers options
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Nov 12, 2023
1 parent 92ef45c commit 7ae260c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 26 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down Expand Up @@ -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
Expand All @@ -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
14 changes: 5 additions & 9 deletions tests/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -32,4 +27,5 @@ if has_config("tests") then
else
remove_files("src/Tests/NzslcTests.cpp")
end
end)
end
53 changes: 42 additions & 11 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -85,7 +114,7 @@ end

----------------------- Targets -----------------------

target("nzsl")
target("nzsl", function ()
set_kind("$(kind)")
set_group("Libraries")
add_defines("NZSL_BUILD")
Expand All @@ -107,16 +136,18 @@ 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)")
add_headerfiles("src/(ShaderCompiler/**.inl)")
add_files("src/ShaderCompiler/**.cpp")
add_deps("nzsl")
add_packages("cxxopts", "fmt", "frozen", "nlohmann_json")
end)
end

includes("xmake/**.lua")
Expand Down

0 comments on commit 7ae260c

Please sign in to comment.