diff options
| author | ruki <[email protected]> | 2023-02-27 14:39:11 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-27 14:39:11 +0800 |
| commit | fcc1ee94099948888d1e0fc45abb648448a04599 (patch) | |
| tree | af5a4b6deb36446fe122c2ca59e63afe577377f7 | |
| parent | 58b151f08ab263a9ff3f9de0943a8ef142c2c2a4 (diff) | |
| parent | e965be5351fdad4e51f6dc5a925b936a3a6d0369 (diff) | |
Merge pull request #3431 from xmake-io/tool
improve to load tool
| -rw-r--r-- | xmake/core/tool/compiler.lua | 14 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 14 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 26 |
4 files changed, 51 insertions, 19 deletions
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index db6badf76..b20591d3c 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -153,9 +153,6 @@ function compiler.load(sourcekind, target) -- init flag kinds instance._FLAGKINDS = table.wrap(result:sourceflags()[sourcekind]) - -- save this instance - compiler._INSTANCES[cachekey] = instance - -- add toolchains flags to the compiler tool, e.g. gcc.cxflags or cxflags local toolname = compiler_tool:name() if target and target.toolconfig then @@ -167,6 +164,17 @@ 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 + + -- @note we have to save it after the load to avoid + -- other concurrent processes going ahead and getting an incomplete instance of the tool. + compiler._INSTANCES[cachekey] = instance return instance end diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index bf2e9b46c..717936b6c 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -177,9 +177,6 @@ function linker.load(targetkind, sourcekinds, target) -- init flag kinds instance._FLAGKINDS = {linkerinfo.linkerflag} - -- save this instance - builder._INSTANCES[cachekey] = instance - -- add toolchains flags to the linker tool -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags local toolkind = linkertool:kind() @@ -195,6 +192,17 @@ 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 + + -- @note we have to save it after the load to avoid + -- other concurrent processes going ahead and getting an incomplete instance of the tool. + builder._INSTANCES[cachekey] = instance 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 = { |
