diff --git a/.github/workflows/linux-build-sanitizer.yml b/.github/workflows/linux-build-sanitizer.yml index d1e5dd0ab..529d9c7da 100644 --- a/.github/workflows/linux-build-sanitizer.yml +++ b/.github/workflows/linux-build-sanitizer.yml @@ -21,7 +21,6 @@ jobs: matrix: os: [ubuntu-20.04] arch: [x86_64] - mode: [asan] runs-on: ${{ matrix.os }} if: "!contains(github.event.head_commit.message, 'ci skip')" @@ -76,7 +75,11 @@ jobs: # Setup compilation mode and install project dependencies - name: Configure xmake and install dependencies - run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --toolchain=hfuzz-clang --verbose --yes + run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=fuzz --verbose --yes + + # Configure xmake with honggfuzz to build the engine + - name: Configure xmake with honggfuzz + run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=fuzz --verbose --toolchain=hfuzz-clang # Build the engine - name: Build Nazara diff --git a/xmake.lua b/xmake.lua index de027a1c3..81ebfa908 100644 --- a/xmake.lua +++ b/xmake.lua @@ -124,21 +124,25 @@ add_rules("mode.asan", "mode.debug", "mode.releasedbg") add_rules("plugin.vsxmake.autoupdate") add_rules("build_rendererplugins") -if is_plat("windows") then - set_allowedmodes("debug", "releasedbg", "asan") -else - set_allowedmodes("debug", "releasedbg", "asan", "coverage") - add_rules("mode.coverage") -end - set_allowedplats("windows", "mingw", "linux", "macosx") set_allowedarchs("windows|x64", "mingw|x86_64", "linux|x86_64", "macosx|x86_64") set_defaultmode("debug") +if is_plat("windows") then + set_allowedmodes("debug", "releasedbg", "asan") +else + set_allowedmodes("debug", "releasedbg", "asan", "coverage", "fuzz") + add_rules("mode.coverage") + add_rules("mode.fuzz") +end + if is_mode("debug") then add_rules("debug_suffix") elseif is_mode("asan") then set_optimize("none") -- by default xmake will optimize asan builds +elseif is_mode("fuzz") then + -- we don't want packages to require compilation with fuzz toolchain + set_policy("package.inherit_external_configs", false) elseif is_mode("coverage") then if not is_plat("windows") then add_links("gcov") @@ -242,81 +246,3 @@ includes("tools/xmake.lua") includes("tests/xmake.lua") includes("plugins/*/xmake.lua") includes("examples/*/xmake.lua") - --- Adds -d as a debug suffix -rule("debug_suffix") - on_load(function (target) - if target:kind() ~= "binary" then - target:set("basename", target:basename() .. "-d") - end - end) - --- Builds renderer plugins if linked to NazaraRenderer -rule("build_rendererplugins") - on_load(function (target) - local deps = table.wrap(target:get("deps")) - - if target:kind() == "binary" and (table.contains(deps, "NazaraRenderer") or table.contains(deps, "NazaraGraphics")) then - for name, _ in pairs(modules) do - local depName = "Nazara" .. name - if name:match("^.+Renderer$") and not table.contains(deps, depName) then -- don't overwrite dependency - target:add("deps", depName, {inherit = false}) - end - end - end - end) - --- Turns resources into includables headers -rule("embed_resources") - before_build(function (target, opt) - import("core.base.option") - if xmake.version():ge("2.5.9") then - import("utils.progress") - elseif not import("utils.progress", { try = true }) then - import("private.utils.progress") - end - - local function GenerateEmbedHeader(filepath, targetpath) - local bufferSize = 1024 * 1024 - - progress.show(opt.progress, "${color.build.object}embedding %s", filepath) - - local resource = assert(io.open(filepath, "rb")) - local targetFile = assert(io.open(targetpath, "w+")) - - local resourceSize = resource:size() - - local remainingSize = resourceSize - local headerSize = 0 - - while remainingSize > 0 do - local readSize = math.min(remainingSize, bufferSize) - local data = resource:read(readSize) - remainingSize = remainingSize - readSize - - local headerContentTable = {} - for i = 1, #data do - table.insert(headerContentTable, string.format("%d,", data:byte(i))) - end - local content = table.concat(headerContentTable) - - headerSize = headerSize + #content - - targetFile:write(content) - end - - resource:close() - targetFile:close() - end - - for _, sourcebatch in pairs(target:sourcebatches()) do - if sourcebatch.rulename == "embed_resources" then - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local targetpath = sourcefile .. ".h" - if option.get("rebuild") or os.mtime(sourcefile) >= os.mtime(targetpath) then - GenerateEmbedHeader(sourcefile, targetpath) - end - end - end - end - end) diff --git a/xmake/rules/debug_suffix.lua b/xmake/rules/debug_suffix.lua new file mode 100644 index 000000000..f1fd4d2f5 --- /dev/null +++ b/xmake/rules/debug_suffix.lua @@ -0,0 +1,7 @@ +-- Adds -d as a debug suffix +rule("debug_suffix") + on_load(function (target) + if target:kind() ~= "binary" then + target:set("basename", target:basename() .. "-d") + end + end) diff --git a/xmake/rules/embed_resources.lua b/xmake/rules/embed_resources.lua new file mode 100644 index 000000000..d1b12268d --- /dev/null +++ b/xmake/rules/embed_resources.lua @@ -0,0 +1,54 @@ +-- Turns resources into includables headers +rule("embed_resources") + before_build(function (target, opt) + import("core.base.option") + if xmake.version():ge("2.5.9") then + import("utils.progress") + elseif not import("utils.progress", { try = true }) then + import("private.utils.progress") + end + + local function GenerateEmbedHeader(filepath, targetpath) + local bufferSize = 1024 * 1024 + + progress.show(opt.progress, "${color.build.object}embedding %s", filepath) + + local resource = assert(io.open(filepath, "rb")) + local targetFile = assert(io.open(targetpath, "w+")) + + local resourceSize = resource:size() + + local remainingSize = resourceSize + local headerSize = 0 + + while remainingSize > 0 do + local readSize = math.min(remainingSize, bufferSize) + local data = resource:read(readSize) + remainingSize = remainingSize - readSize + + local headerContentTable = {} + for i = 1, #data do + table.insert(headerContentTable, string.format("%d,", data:byte(i))) + end + local content = table.concat(headerContentTable) + + headerSize = headerSize + #content + + targetFile:write(content) + end + + resource:close() + targetFile:close() + end + + for _, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename == "embed_resources" then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local targetpath = sourcefile .. ".h" + if option.get("rebuild") or os.mtime(sourcefile) >= os.mtime(targetpath) then + GenerateEmbedHeader(sourcefile, targetpath) + end + end + end + end + end) diff --git a/xmake/rules/mode.fuzz.lua b/xmake/rules/mode.fuzz.lua new file mode 100644 index 000000000..8e526c25a --- /dev/null +++ b/xmake/rules/mode.fuzz.lua @@ -0,0 +1,11 @@ +rule("mode.fuzz") + on_config(function (target) + if is_mode("fuzz") then + target:set("symbols", "debug") + + target:add("cxflags", "-fsanitize=address,fuzzer") + target:add("mxflags", "-fsanitize=address,fuzzer") + target:add("ldflags", "-fsanitize=address,fuzzer") + target:add("shflags", "-fsanitize=address,fuzzer") + end + end) diff --git a/xmake/rules/renderer_plugins.lua b/xmake/rules/renderer_plugins.lua new file mode 100644 index 000000000..1ac8b40af --- /dev/null +++ b/xmake/rules/renderer_plugins.lua @@ -0,0 +1,14 @@ +-- Builds renderer plugins if linked to NazaraRenderer +rule("build_rendererplugins") + on_load(function (target) + local deps = table.wrap(target:get("deps")) + + if target:kind() == "binary" and (table.contains(deps, "NazaraRenderer") or table.contains(deps, "NazaraGraphics")) then + for name, _ in pairs(modules) do + local depName = "Nazara" .. name + if name:match("^.+Renderer$") and not table.contains(deps, depName) then -- don't overwrite dependency + target:add("deps", depName, {inherit = false}) + end + end + end + end) diff --git a/xmake/toolchains/hfuzz-clang/xmake.lua b/xmake/toolchains/hfuzz-clang/xmake.lua index c76bc7a09..1c7139720 100644 --- a/xmake/toolchains/hfuzz-clang/xmake.lua +++ b/xmake/toolchains/hfuzz-clang/xmake.lua @@ -15,11 +15,6 @@ toolchain("hfuzz-clang") set_toolset("mxx", "hfuzz-clang++") set_toolset("as", "hfuzz-clang") - add_cxflags("-fsanitize=fuzzer-no-link") - add_ldflags("-fsanitize=fuzzer-no-link") - add_shflags("-fsanitize=fuzzer-no-link") - add_arflags("-fsanitize=fuzzer-no-link") - on_check(function (toolchain) return import("lib.detect.find_tool")("hfuzz-clang") end)