Skip to content

Commit

Permalink
Merge pull request #4904 from xmake-io/def
Browse files Browse the repository at this point in the history
Fix incremental compilation for .def files
  • Loading branch information
waruqi committed Mar 31, 2024
2 parents 073bd32 + 2b1491a commit cec09d4
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 76 deletions.
30 changes: 4 additions & 26 deletions xmake/actions/build/kinds/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
39 changes: 39 additions & 0 deletions xmake/actions/build/kinds/linkdepfiles.lua
Original file line number Diff line number Diff line change
@@ -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
29 changes: 4 additions & 25 deletions xmake/actions/build/kinds/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 4 additions & 25 deletions xmake/actions/build/kinds/static.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions xmake/rules/linker/link_scripts/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

2 changes: 2 additions & 0 deletions xmake/rules/platform/windows/def/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions xmake/rules/platform/windows/manifest/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cec09d4

Please sign in to comment.