Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve default config for asan #4326

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,22 +308,37 @@ function _sort_librarydeps(package, opt)
return orderdeps
end

-- get builtin configuration default values
function _get_default_config_value_of(name)
local defaults = {
debug = false,
shared = false,
pic = true,
lto = false,
asan = false
}
return defaults[name]
end

-- add some builtin configurations to package
function _add_package_configurations(package)
-- we can define configs to override it and it's default value in package()
if package:extraconf("configs", "debug", "default") == nil then
package:add("configs", "debug", {builtin = true, description = "Enable debug symbols.", default = false, type = "boolean"})
local default = _get_default_config_value_of("debug")
package:add("configs", "debug", {builtin = true, description = "Enable debug symbols.", default = default, type = "boolean"})
end
if package:extraconf("configs", "shared", "default") == nil then
-- we always use static library if it's for wasm platform
local readonly
if package:is_plat("wasm") then
readonly = true
end
package:add("configs", "shared", {builtin = true, description = "Build shared library.", default = false, readonly = readonly, type = "boolean"})
local default = _get_default_config_value_of("shared")
package:add("configs", "shared", {builtin = true, description = "Build shared library.", default = default, readonly = readonly, type = "boolean"})
end
if package:extraconf("configs", "pic", "default") == nil then
package:add("configs", "pic", {builtin = true, description = "Enable the position independent code.", default = true, type = "boolean"})
local default = _get_default_config_value_of("pic")
package:add("configs", "pic", {builtin = true, description = "Enable the position independent code.", default = default, type = "boolean"})
end
if package:extraconf("configs", "lto", "default") == nil then
package:add("configs", "lto", {builtin = true, description = "Enable the link-time build optimization.", type = "boolean"})
Expand Down Expand Up @@ -502,8 +517,12 @@ function _init_requireinfo(requireinfo, package, opt)
if project.policy("package.inherit_external_configs") then
requireinfo.configs.vs_runtime = requireinfo.configs.vs_runtime or get_config("vs_runtime")
end
requireinfo.configs.lto = requireinfo.configs.lto or project.policy("build.optimization.lto")
requireinfo.configs.asan = requireinfo.configs.asan or project.policy("build.sanitizer.address")
if requireinfo.configs.lto == nil then
requireinfo.configs.lto = project.policy("build.optimization.lto")
end
if requireinfo.configs.asan == nil then
requireinfo.configs.asan = project.policy("build.sanitizer.address")
end
end
-- but we will ignore some configs for buildhash in the headeronly and host/binary package
-- @note on_test still need these configs, @see https://github.com/xmake-io/xmake/issues/4124
Expand Down Expand Up @@ -537,6 +556,14 @@ function _finish_requireinfo(requireinfo, package)
requireinfo.configs[name] = nil
end
end
-- sync default value to prevent cache mismatch (buildhash)
-- @see https://github.com/xmake-io/xmake/pull/4324
for k, v in pairs(requireinfo.configs) do
local default = _get_default_config_value_of(k)
if v == default then
requireinfo.configs[k] = nil
end
end
end

-- merge requireinfo from `add_requireconfs()`
Expand Down
Loading