Add sanitizers support
Currently you can't generate projects with any type of sanitizers enabled I suggest, to add the ability to generate projects with sanitizers enabled.
What problem will this solve? Sanitizers help with detecting a lot of bugs and issues, that occurs at runtime.
I agree this would be a nice feature, but in the meantime this is the solution I use
-- Add new command line option
newoption {
trigger = "Sanitizer",
value = "Tool",
description = "A sanitizer to add to the build",
allowed = {
{ "Asan", "Address Sanitizer"}
}
}
-- Register api command
premake.api.register{
name="enableASAN",
scope="config",
kind="string",
allowed={"true", "false"}
}
premake.override(premake.vstudio.vc2010, "configurationProperties", function(base, cfg)
local m = premake.vstudio.vc2010
m.propertyGroup(cfg, "Configuration")
premake.callArray(m.elements.configurationProperties, cfg)
if cfg.enableASAN then
m.element("EnableASAN", nil, cfg.enableASAN)
end
premake.pop('</PropertyGroup>')
end)
-- later on.....
local sanitizer = _OPTIONS["Sanitizer"]
if(sanitizer and sanitizer == "Asan") then
flags{ "NoRuntimeChecks", "NoIncrementalLink"}
editAndContinue "Off"
-- Add new api command
filter {"kind:ConsoleApp OR WindowedApp"}
enableASAN "true"
filter {}
end
Then when invoking premake if you add the parameter --Sanitizer=Asan
Note: ASAN cannot be enabled on static libraries as the LInkIncremental value cannot be set as false on them, and will cause a build error
EDIT: Sorry, I should also specify this would only work on MSVC, as it's the only platform I'm currently working on, a cross-platform solution would be much nicer
Bumping this, as it's not sufficient to just add buildoptions "/fsanitize=address" (this has different behavior than Enable Address Sanitizer). See https://developercommunity.visualstudio.com/t/Asan-cannot-find-DLL-only-when-specified/1594652 for details.