Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions modules/ninja/ninja_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,7 @@ function m.configurationVariables(cfg)

local links = toolset.getlinks(cfg)
if #links > 0 then
local wksLinks = {}
for _, link in ipairs(links) do
if not path.isabsolute(link) and link:match('[/\\]') then
local absPath = path.join(cfg.project.location, link)
link = path.getrelative(cfg.workspace.location, absPath)
end
table.insert(wksLinks, link)
end
_p("links_%s = %s", ninja.key(cfg), table.concat(wksLinks, " "))
_p("links_%s = %s", ninja.key(cfg), table.concat(links, " "))
end

_p("objdir_%s = %s", ninja.key(cfg), project.getrelative(cfg.project, cfg.objdir))
Expand Down Expand Up @@ -1131,13 +1123,7 @@ function m.linkTarget(cfg)
local deps = config.getlinks(cfg, "siblings", "fullpath")
local implicitDeps = ""
if #deps > 0 then
local wksRelDeps = {}
for _, dep in ipairs(deps) do
local absPath = path.join(cfg.project.location, dep)
local relDep = path.getrelative(cfg.workspace.location, absPath)
table.insert(wksRelDeps, relDep)
end
implicitDeps = " | " .. table.concat(wksRelDeps, " ")
implicitDeps = " | " .. table.concat(deps, " ")
end

-- Use pre-computed dependency targets if available, otherwise compute them inline
Expand Down
21 changes: 20 additions & 1 deletion modules/vstudio/tests/vc2010/test_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
local p = premake
local suite = test.declare("vs2010_link")
local vc2010 = p.vstudio.vc2010
local project = p.project


--
Expand Down Expand Up @@ -883,6 +882,26 @@
end


--
-- Whole archive should be listed in additional dependencies.
--

function suite.wholearchive()
links { "MyProject2" }
wholearchive { "kernel32", "MyProject2" }
project "MyProject2"
kind "StaticLib"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>/WHOLEARCHIVE:kernel32;/WHOLEARCHIVE:bin\Debug\MyProject2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary>bin\Debug\MyProject.lib</ImportLibrary>
</Link>
]]
end


--
-- Test for the Profile flag.
--
Expand Down
8 changes: 7 additions & 1 deletion modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,10 @@
function m.additionalDependencies(cfg, explicit)
local links

local toolgetrelative = p.tools.getrelative
p.tools.getrelative = function(...)
return path.translate(toolgetrelative(...))
end
-- check to see if this project uses an external toolset. If so, let the
-- toolset define the format of the links
local toolset = config.toolset(cfg)
Expand All @@ -1969,8 +1973,10 @@
else
links = vstudio.getLinks(cfg, explicit)
end
links = table.join(links, p.tools.msc.wholearchive(cfg))
p.tools.getrelative = toolgetrelative

links = path.translate(table.concat(links, ";"))
links = table.concat(links, ";")

local additional = ";%(AdditionalDependencies)"
if cfg.inheritdependencies ~= nil then
Expand Down
2 changes: 1 addition & 1 deletion modules/xcode/xcode_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@
end
end

settings['OTHER_LDFLAGS'] = table.join(flags, cfg.linkoptions)
settings['OTHER_LDFLAGS'] = table.join(flags, cfg.linkoptions, toolset.wholearchive(cfg))

if cfg.staticruntime == "On" then
settings['STANDARD_C_PLUS_PLUS_LIBRARY_TYPE'] = 'static'
Expand Down
6 changes: 6 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,12 @@
}
}

api.register {
name = "wholearchive",
scope = "config",
kind = "list:string"
}

api.register {
name = "editorintegration",
scope = "workspace",
Expand Down
26 changes: 23 additions & 3 deletions src/base/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@

if part == "directory" then
table.foreachi(cfg.libdirs, function(dir)
table.insert(result, project.getrelative(cfg.project, dir))
table.insert(result, p.tools.getrelative(cfg.project, dir))
end)
end

Expand Down Expand Up @@ -294,7 +294,7 @@
if part == "object" then
item = prjcfg
else
item = project.getrelative(cfg.project, prjcfg.linktarget.fullpath)
item = p.tools.getrelative(cfg.project, prjcfg.linktarget.fullpath)
end

end
Expand All @@ -309,7 +309,7 @@
-- system library or assembly), make it project-relative
item = link
if item:find("/", nil, true) then
item = project.getrelative(cfg.project, item)
item = p.tools.getrelative(cfg.project, item)
end
end

Expand Down Expand Up @@ -343,6 +343,26 @@
return result
end

--
-- Return list of (non-decorated) wholearchive fullpath
--

function config.getwholearchive(cfg)
local getfullpath = function(libraryname)
local prj = p.workspace.findproject(cfg.workspace, libraryname)
local prjcfg = prj and project.getconfig(prj, cfg.buildcfg, cfg.platform)
if prj and config.canLink(cfg, prjcfg) then -- is sibling project
return p.tools.getrelative(cfg.project, prjcfg.linktarget.fullpath)
else
if path.isabsolute(libraryname) then
return libraryname
else
return p.tools.getrelative(cfg.project, libraryname)
end
end
end
return table.translate(cfg.wholearchive, getfullpath)
end

--
-- Returns the list of sibling target directories
Expand Down
5 changes: 5 additions & 0 deletions src/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,13 @@
}
}

clang.wholearchive = gcc.wholearchive

function clang.getldflags(cfg)
local flags = config.mapFlags(cfg, clang.ldflags)

flags = table.join(flags, gcc.wholearchive(cfg))

return flags
end

Expand Down
14 changes: 14 additions & 0 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,22 @@
}
}

function gcc.wholearchive(cfg)
if cfg.system == p.MACOSX then
return table.translate(config.getwholearchive(cfg), function(libraryname) return "-force_load " .. libraryname end)
else
if #cfg.wholearchive == 0 then
return {}
end
return table.join({ "-Wl,--whole-archive" }, config.getwholearchive(cfg), { "-Wl,--no-whole-archive" })
end
end

function gcc.getldflags(cfg)
local flags = config.mapFlags(cfg, gcc.ldflags)

flags = table.join(flags, gcc.wholearchive(cfg))

return flags
end

Expand Down
6 changes: 6 additions & 0 deletions src/tools/msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@
}
}

function msc.wholearchive(cfg)
return table.translate(config.getwholearchive(cfg), function(libraryname) return "/WHOLEARCHIVE:" .. libraryname end)
end

function msc.getldflags(cfg)
local map = iif(cfg.kind ~= p.STATICLIB, msc.linkerFlags, msc.librarianFlags)
local flags = config.mapFlags(cfg, map)
Expand Down Expand Up @@ -425,6 +429,8 @@
end
end

flags = table.join(flags, msc.wholearchive(cfg))

return flags
end

Expand Down
33 changes: 32 additions & 1 deletion tests/tools/test_gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
local suite = test.declare("tools_gcc")

local gcc = p.tools.gcc
local project = p.project


--
Expand Down Expand Up @@ -498,6 +497,27 @@
test.contains({ "-shared" }, gcc.getldflags(cfg))
end

function suite.ldflags_onWindows_onWholeArchive()
system "windows"
links { "MyProject2" }
wholearchive { "ole32", "MyProject2" }
project "MyProject2"
kind "StaticLib"
system "windows"
prepare()
test.isequal({ "-s", "-Wl,--whole-archive", "ole32", "bin/Debug/MyProject2.lib", "-Wl,--no-whole-archive" }, gcc.getldflags(cfg))
end

function suite.ldflags_onLinux_onWholeArchive()
system "linux"
links { "MyProject2" }
wholearchive { "ole32", "MyProject2" }
project "MyProject2"
kind "StaticLib"
system "linux"
prepare()
test.isequal({ "-s", "-Wl,--whole-archive", "ole32", "bin/Debug/libMyProject2.a", "-Wl,--no-whole-archive" }, gcc.getldflags(cfg))
end
--
-- Check Mac OS X variants on LDFLAGS.
--
Expand Down Expand Up @@ -539,6 +559,17 @@
test.contains({ "-dynamiclib" }, gcc.getldflags(cfg))
end

function suite.ldflags_onMacOSX_onWholeArchive()
system "MacOSX"
links { "MyProject2" }
wholearchive { "ole32", "MyProject2" }
project "MyProject2"
kind "StaticLib"
system "MacOSX"
prepare()
test.isequal({"-Wl,-x", "-force_load ole32", "-force_load bin/Debug/libMyProject2.a" }, gcc.getldflags(cfg))
end

--
-- Check Mac OS X deployment target flags
--
Expand Down
11 changes: 11 additions & 0 deletions tests/tools/test_msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@ end
test.missing("/PROFILE", msc.getldflags(cfg))
end

function suite.ldflags_wholearchive()
system "windows"
links { "MyProject2" }
wholearchive { "kernel32", "MyProject2" }
project "MyProject2"
system "windows"
kind "StaticLib"
prepare()
test.isequal({"/NOLOGO", "/DLL", "/WHOLEARCHIVE:kernel32", "/WHOLEARCHIVE:bin/Debug/MyProject2.lib"}, msc.getldflags(cfg))
end

--
-- Check handling of CLR settings.
--
Expand Down
1 change: 1 addition & 0 deletions website/docs/Project-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
| [vectorextensions](vectorextensions.md) | Enable hardware vector extensions |
| [vpaths](vpaths.md) | |
| [warnings](warnings.md) | |
| [wholearchive](wholearchive.md) | |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope of this PR, but I feel like I always forget to add things here. We should probably check to make sure all of the APIs are actually here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or remove it completely, as it doesn't bring more information that reference listing on the left panel.
I also note that for some pages, including Project-API, we lose the left panel.

| [workspace](workspace.md) | |

### Builtin Extension APIs ###
Expand Down
32 changes: 32 additions & 0 deletions website/docs/wholearchive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Command linker to include all objects of given libraries.

```lua
wholearchive { "libraries" }
```

### Parameters ###

`libraries` is the list of static libraries for which to include all their symbols.

### Availability ###

Premake 5.0 or later.

### Examples ###

```lua
project 'some_library'
kind 'StaticLib'
defines { 'MAKING_DLL_LIB' } -- for dllexport
-- ..
project 'some_dll'
kind 'SharedLib'
defines { 'MAKING_DLL_LIB' } -- for dllexport
links { 'some_library' }
wholearchive { 'some_library' }
-- ..
```

### See Also ###

* [links](links.md)
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ module.exports = {
'vpaths',
'vsprops',
'warnings',
'wholearchive',
'workspace',
'wpf',
'xcodebuildresources',
Expand Down
Loading