Skip to content
Draft
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
2 changes: 1 addition & 1 deletion modules/vstudio/vstudio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@

function vstudio.needsExplicitLink(cfg)
if not cfg._needsExplicitLink then
local ex = cfg.implicitlink == p.OFF
local ex = cfg.implicitlink == p.OFF or cfg.wholearchive == p.ON
if not ex then
local prjdeps = project.getdependencies(cfg.project, "linkOnly")
local cfgdeps = config.getlinks(cfg, "dependencies", "object")
Expand Down
10 changes: 10 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,16 @@
}
}

api.register {
name = "wholearchive",
scope = "config",
kind = "string",
allowed = {
"Off",
Copy link
Member

Choose a reason for hiding this comment

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

If it's just on/off, it should be a boolean and not a string.

Copy link
Member

Choose a reason for hiding this comment

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

We should probably have "Default" as well, because we should probably allow users to specify to use the default toolset/exporter behavior, rather than enforcing one behavior or another.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used linkgroups as model :-/

Ideally, I wanted libraries as well, but too lazy to do it, so currently an all or nothing.

Implementation would be more "On" or "Default" BTW :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not checked if we can have boolean or string (for individual library).

"On",
}
}

api.register {
name = "editorintegration",
scope = "workspace",
Expand Down
6 changes: 3 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
14 changes: 10 additions & 4 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@

function gcc.getlinks(cfg, systemonly, nogroups)
local result = {}
local lib_flag = iif(cfg.system == p.MACOSX and cfg.wholearchive == p.ON, "-force_load ", "-l")

if not systemonly then
if cfg.userelativelinks == p.ON then
Expand All @@ -640,7 +641,7 @@
if string.startswith(link, "lib") then
link = link:sub(4)
end
table.insert(result, "-l" .. link)
table.insert(result, lib_flag .. link)
end
else
-- Don't use the -l form for sibling libraries, since they may have
Expand All @@ -666,12 +667,12 @@
-- Check whether link mode decorator is present
if name:endswith(":static") then
name = string.sub(name, 0, -8)
table.insert(static_syslibs, "-l" .. name)
table.insert(static_syslibs, lib_flag .. name)
elseif name:endswith(":shared") then
name = string.sub(name, 0, -8)
table.insert(shared_syslibs, "-l" .. name)
table.insert(shared_syslibs, lib_flag .. name)
else
table.insert(shared_syslibs, "-l" .. name)
table.insert(shared_syslibs, lib_flag .. name)
end
end
end
Expand All @@ -691,6 +692,11 @@
table.insert(result, "-Wl,--end-group")
end

if cfg.wholearchive == p.ON and cfg.system ~= p.MACOSX and #result > 0 then
table.insert(result, 1, "-Wl,--whole-archive")
table.insert(result, "-Wl,--no-whole-archive")
end

return result
end

Expand Down
5 changes: 5 additions & 0 deletions src/tools/msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
table.insert(links, link)
end

if cfg.wholearchive == p.ON then
-- Don't use "/WHOLEARCHIVE" as path.translate might be applied to result
links = table.translate(links, function (s) return "-WHOLEARCHIVE:" .. s end)
Copy link
Member

Choose a reason for hiding this comment

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

Is the path.translate issue something that you did indeed find to be a problem? Or is this pre-emptive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I encounter it in visual.
Using - as workaround is rejected in commandline though (as ninja).
I think we have to specify 'shell' and translate path here.

Copy link
Member

Choose a reason for hiding this comment

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

Also, this should probably go into the linker flags, rather than the getlinks functionality. Also, I think the proper way to do this would be: link.exe foo.lib /WHOLEARCHIVE:foo.lib -- Following up on this, if we don't support granular whole archive, we can just have a single /WHOLEARCHIVE without specifying the individual libs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might try that.

if we don't support granular
I hope to add that support.

end

return links
end

Expand Down
15 changes: 15 additions & 0 deletions tests/tools/test_gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,21 @@
test.contains({ "-lole32" }, gcc.getlinks(cfg))
end

function suite.links_onWholeArchive_onNonMacOSX()
system "windows"
links { "ole32" }
wholearchive "On"
prepare()
test.contains({ "-Wl,--whole-archive", "-lole32", "-Wl,--no-whole-archive" }, gcc.getlinks(cfg))
end

function suite.links_onWholeArchive_onMacOSX()
system "MacOSX"
links { "ole32" }
wholearchive "On"
prepare()
test.contains({ "-force_load ole32" }, gcc.getlinks(cfg))
end

--
-- When linking to a static sibling library, the relative path to the library
Expand Down
16 changes: 16 additions & 0 deletions tests/tools/test_msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,22 @@ function suite.cflags_onVs2022IncludeDirsAfter()
test.contains("/external:I/usr/local/include", msc.getincludedirs(cfg, cfg.includedirs, cfg.externalincludedirs, cfg.frameworkdirs, cfg.includedirsafter))
end

--
-- Check handling of library.
--

function suite.links()
links { "mylibrary" }
prepare()
test.contains("mylibrary.lib", msc.getlinks(cfg))
end

function suite.links_wholearchive()
links { "mylibrary" }
wholearchive "On"
prepare()
test.contains("-WHOLEARCHIVE:mylibrary.lib", msc.getlinks(cfg))
end

--
-- Check handling of library search paths.
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 @@ -161,6 +161,7 @@
| [vectorextensions](vectorextensions.md) | Enable hardware vector extensions |
| [vpaths](vpaths.md) | |
| [warnings](warnings.md) | |
| [wholearchive](wholearchive.md) | |
| [workspace](workspace.md) | |

### Builtin Extension APIs ###
Expand Down
38 changes: 38 additions & 0 deletions website/docs/wholearchive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Apply whole archive flag to linked libraries.
Copy link
Member

Choose a reason for hiding this comment

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

Reword suggestion: Controls whether the linker should include all objects in the linked binary.

That would include all their symbols.

```lua
wholearchive "value"
```

### Parameters ###

`value` is one of:

| Value | Description |
|---------|---------------------------------------------------|
| On | Turn on whole archive. |
| Off | Turn off whole archive. |

### Availability ###

Premake 5.0-beta8 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 'On'
-- ..
```

### 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 @@ -300,6 +300,7 @@ module.exports = {
'vpaths',
'vsprops',
'warnings',
'wholearchive',
'workspace',
'wpf',
'xcodebuildresources',
Expand Down
Loading