diff options
| author | ruki <[email protected]> | 2024-03-31 18:33:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-31 18:33:25 +0800 |
| commit | cec09d4b59cb5b872bb91469a9bfaa731eff77dd (patch) | |
| tree | 38ecec3fc91ce6e51d464df41469d8e13919c40f | |
| parent | 073bd32b3d0fc31246a8708d59a3b277606db3bd (diff) | |
| parent | 2b1491a54695612af04e79b24b38c2da2f794e16 (diff) | |
Merge pull request #4904 from xmake-io/def
Fix incremental compilation for .def files
| -rw-r--r-- | xmake/actions/build/kinds/binary.lua | 30 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/linkdepfiles.lua | 39 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/shared.lua | 29 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/static.lua | 29 | ||||
| -rw-r--r-- | xmake/rules/linker/link_scripts/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/platform/windows/def/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/platform/windows/manifest/xmake.lua | 1 |
7 files changed, 56 insertions, 76 deletions
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index 2f5bad0fc..76ccbcd9b 100644 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -27,53 +27,31 @@ import("core.project.depend") import("utils.progress") import("private.utils.batchcmds") import("object", {alias = "add_batchjobs_for_object"}) +import("linkdepfiles", {alias = "get_linkdepfiles"}) -- do link target function _do_link_target(target, opt) - - -- load linker instance local linkinst = linker.load(target:kind(), target:sourcekinds(), {target = target}) - - -- get link flags local linkflags = linkinst:linkflags({target = target}) - -- get object files - local objectfiles = target:objectfiles() - -- need build this target? - local depfiles = objectfiles - for _, dep in ipairs(target:orderdeps()) do - if dep:kind() == "static" then - if depfiles == objectfiles then - depfiles = table.copy(objectfiles) - end - table.insert(depfiles, dep:targetfile()) - end - end + local depfiles = get_linkdepfiles(target) local dryrun = option.get("dry-run") local depvalues = {linkinst:program(), linkflags} depend.on_changed(function () - - -- the target file local targetfile = target:targetfile() - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress info progress.show(opt.progress, "${color.build.target}linking.$(mode) %s", path.filename(targetfile)) - -- trace verbose info + local objectfiles = target:objectfiles() + local verbose = option.get("verbose") if verbose then -- show the full link command with raw arguments, it will expand @xxx.args for msvc/link on windows print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true})) end - -- link it if not dryrun then assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags})) end - end, {dependfile = target:dependfile(), lastmtime = os.mtime(target:targetfile()), changed = target:is_rebuilt(), diff --git a/xmake/actions/build/kinds/linkdepfiles.lua b/xmake/actions/build/kinds/linkdepfiles.lua new file mode 100644 index 000000000..f96e532fc --- /dev/null +++ b/xmake/actions/build/kinds/linkdepfiles.lua @@ -0,0 +1,39 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file linkdepfiles.lua +-- + +-- get link depfiles +function main(target) + local extrafiles = {} + for _, dep in ipairs(target:orderdeps()) do + if dep:kind() == "static" then + table.insert(extrafiles, dep:targetfile()) + end + end + local linkdepfiles = target:data("linkdepfiles") + if linkdepfiles then + table.join2(extrafiles, linkdepfiles) + end + local objectfiles = target:objectfiles() + local depfiles = objectfiles + if #extrafiles > 0 then + depfiles = table.join(objectfiles, extrafiles) + end + return depfiles +end diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index 81cf0ebb5..67671b7ef 100644 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -27,49 +27,28 @@ import("core.project.depend") import("utils.progress") import("private.utils.batchcmds") import("object", {alias = "add_batchjobs_for_object"}) +import("linkdepfiles", {alias = "get_linkdepfiles"}) -- do link target function _do_link_target(target, opt) - - -- load linker instance local linkinst = linker.load(target:kind(), target:sourcekinds(), {target = target}) - - -- get link flags local linkflags = linkinst:linkflags({target = target}) - -- get object files - local objectfiles = target:objectfiles() - -- need build this target? - local depfiles = objectfiles - for _, dep in ipairs(target:orderdeps()) do - if dep:kind() == "static" then - if depfiles == objectfiles then - depfiles = table.copy(objectfiles) - end - table.insert(depfiles, dep:targetfile()) - end - end + local depfiles = get_linkdepfiles(target) local dryrun = option.get("dry-run") local depvalues = {linkinst:program(), linkflags} depend.on_changed(function () - - -- the target file local targetfile = target:targetfile() - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress info progress.show(opt.progress, "${color.build.target}linking.$(mode) %s", path.filename(targetfile)) - -- trace verbose info + local objectfiles = target:objectfiles() + local verbose = option.get("verbose") if verbose then -- show the full link command with raw arguments, it will expand @xxx.args for msvc/link on windows print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true})) end - -- link it if not dryrun then assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags})) end diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index 47668770d..11f9c7f6a 100644 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -27,49 +27,28 @@ import("core.project.depend") import("utils.progress") import("private.utils.batchcmds") import("object", {alias = "add_batchjobs_for_object"}) +import("linkdepfiles", {alias = "get_linkdepfiles"}) -- do link target function _do_link_target(target, opt) - - -- load linker instance local linkinst = linker.load(target:kind(), target:sourcekinds(), {target = target}) - - -- get link flags local linkflags = linkinst:linkflags({target = target}) - -- get object files - local objectfiles = target:objectfiles() - -- need build this target? - local depfiles = objectfiles - for _, dep in ipairs(target:orderdeps()) do - if dep:kind() == "static" then - if depfiles == objectfiles then - depfiles = table.copy(objectfiles) - end - table.insert(depfiles, dep:targetfile()) - end - end + local depfiles = get_linkdepfiles(target) local dryrun = option.get("dry-run") local depvalues = {linkinst:program(), linkflags} depend.on_changed(function () - - -- the target file local targetfile = target:targetfile() - - -- is verbose? - local verbose = option.get("verbose") - - -- trace progress info progress.show(opt.progress, "${color.build.target}archiving.$(mode) %s", path.filename(targetfile)) - -- trace verbose info + local objectfiles = target:objectfiles() + local verbose = option.get("verbose") if verbose then -- show the full link command with raw arguments, it will expand @xxx.args for msvc/link on windows print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true})) end - -- link it if not dryrun then assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags})) end diff --git a/xmake/rules/linker/link_scripts/xmake.lua b/xmake/rules/linker/link_scripts/xmake.lua index fdd714988..34bbc3f4f 100644 --- a/xmake/rules/linker/link_scripts/xmake.lua +++ b/xmake/rules/linker/link_scripts/xmake.lua @@ -42,8 +42,10 @@ rule("linker.link_scripts") if target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true}) + target:data_add("linkdepfiles", scriptfile) elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true}) + target:data_add("linkdepfiles", scriptfile) end end) diff --git a/xmake/rules/platform/windows/def/xmake.lua b/xmake/rules/platform/windows/def/xmake.lua index 8aaac52d6..9bdcdc874 100644 --- a/xmake/rules/platform/windows/def/xmake.lua +++ b/xmake/rules/platform/windows/def/xmake.lua @@ -37,7 +37,9 @@ rule("platform.windows.def") if target:is_plat("windows") then flag = "/def:" .. flag end + -- https://github.com/xmake-io/xmake/pull/4901 target:add("shflags", flag, {force = true}) + target:data_add("linkdepfiles", sourcefile) break; end end diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua index 8d24ced97..6bde53a3d 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -34,6 +34,7 @@ rule("platform.windows.manifest") for _, sourcefile in ipairs(sourcebatch.sourcefiles) do target:add("ldflags", "/manifestinput:" .. path.translate(sourcefile), {force = true}) target:add("shflags", "/manifestinput:" .. path.translate(sourcefile), {force = true}) + target:data_add("linkdepfiles", sourcefile) manifest = true local content = io.readfile(sourcefile) if content then |
