diff options
| author | ruki <[email protected]> | 2023-10-27 03:52:52 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-27 03:52:52 -0500 |
| commit | 1f3b3148942aa52a0467a5433d85304df0b936f5 (patch) | |
| tree | c16c4dbd5ac2be4b38d4f1538ab3b42cb1cf8f95 | |
| parent | a8e4bbaae5223b203b2b787b073599bdcff88497 (diff) | |
| parent | 940f96632647a95229cd61a5694887f483dcc303 (diff) | |
Merge pull request #4326 from xmake-io/asan
improve default config for asan
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index a7377d41b..cf0df2cea 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -308,11 +308,24 @@ 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 @@ -320,10 +333,12 @@ function _add_package_configurations(package) 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"}) @@ -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 @@ -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()` |
