diff options
| author | ruki <[email protected]> | 2023-02-27 22:46:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-02-27 22:46:47 +0800 |
| commit | ba3b6f151515c3ea1e400e489e2661f87ce2e032 (patch) | |
| tree | 8b2891b2b3a18073928a831fd271fc86558a8c6e | |
| parent | 3f0c48dcfb366e61b9c8d2c1c0d6f8a565039061 (diff) | |
improve to load tool
| -rw-r--r-- | xmake/core/tool/compiler.lua | 7 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 7 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 26 |
4 files changed, 43 insertions, 13 deletions
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index db6badf76..c610116c7 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -167,6 +167,13 @@ function compiler.load(sourcekind, target) compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end end + + -- we need to load it at the end because in tool.load(). + -- because we may need to call has_flags, which requires the full platform toolchain flags + local ok, errors = compiler_tool:_load() + if not ok then + return nil, errors + end return instance end diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index bf2e9b46c..2682acc9a 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -195,6 +195,13 @@ function linker.load(targetkind, sourcekinds, target) linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end end + + -- we need to load it at the end because in tool.load(). + -- because we may need to call has_flags, which requires the full platform toolchain flags + local ok, errors = linkertool:_load() + if not ok then + return nil, errors + end return instance end diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index b2bb05659..9d94bc375 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -67,11 +67,23 @@ function _instance.new(kind, name, program, plat, arch, toolchain_inst) return nil, errors end end - - -- ok return instance end +-- load tool +function _instance:_load() + if not self._LOADED then + if self.load then + local ok, errors = sandbox.load(self.load, self) + if not ok then + return false, errors + end + end + self._LOADED = true + end + return true +end + -- get the tool name function _instance:name() return self._NAME diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 84a1d187f..0d33decb4 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -32,7 +32,6 @@ import("utils.progress") import("private.cache.build_cache") import("private.service.distcc_build.client", {alias = "distcc_build_client"}) --- init it function init(self) -- init mxflags @@ -44,16 +43,6 @@ function init(self) -- init shflags self:set("shflags", "-shared") - -- add -fPIC for shared - -- - -- we need check it for clang/gcc with window target - -- @see https://github.com/xmake-io/xmake/issues/1392 - -- - if not self:is_plat("windows", "mingw") and self:has_flags("-fPIC", "cxflags") then - self:add("shflags", "-fPIC") - self:add("shared.cxflags", "-fPIC") - end - -- init flags map self:set("mapflags", { -- warnings @@ -76,6 +65,21 @@ function init(self) end end +-- we can only call has_flags in load(), +-- as it requires the full platform toolchain flags. +-- +function load(self) + -- add -fPIC for shared + -- + -- we need check it for clang/gcc with window target + -- @see https://github.com/xmake-io/xmake/issues/1392 + -- + if not self:is_plat("windows", "mingw") and self:has_flags("-fPIC", "cxflags") then + self:add("shflags", "-fPIC") + self:add("shared.cxflags", "-fPIC") + end +end + -- make the strip flag function nf_strip(self, level, target) local maps = { |
