Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSC LTO, runtime, subsystem #1552

Merged
merged 1 commit into from
Nov 10, 2020
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
21 changes: 16 additions & 5 deletions src/tools/msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
-- Returns list of C compiler flags for a configuration.
--

local function getRuntimeFlag(cfg, isstatic)
local rt = cfg.runtime
local flag = iif(isstatic, "/MT", "/MD")
if (rt == "Debug") or (rt == nil and config.isDebugBuild(cfg)) then
JoelLinn marked this conversation as resolved.
Show resolved Hide resolved
flag = flag .. "d"
end
return flag
end

msc.shared = {
clr = {
On = "/clr",
Expand All @@ -37,6 +46,7 @@
},
flags = {
FatalCompileWarnings = "/WX",
LinkTimeOptimization = "/GL",
MultiProcessorCompile = "/MP",
NoMinimalRebuild = "/Gm-",
OmitDefaultLibrary = "/Zl"
Expand Down Expand Up @@ -87,11 +97,11 @@
},
staticruntime = {
-- this option must always be emit (does it??)
_ = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end,
_ = function(cfg) return getRuntimeFlag(cfg, false) end,
-- runtime defaults to dynamic in VS
Default = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end,
On = function(cfg) return iif(config.isDebugBuild(cfg), "/MTd", "/MT") end,
Off = function(cfg) return iif(config.isDebugBuild(cfg), "/MDd", "/MD") end,
Default = function(cfg) return getRuntimeFlag(cfg, false) end,
On = function(cfg) return getRuntimeFlag(cfg, true) end,
Off = function(cfg) return getRuntimeFlag(cfg, false) end,
},
stringpooling = {
On = "/GF",
Expand Down Expand Up @@ -239,13 +249,14 @@
msc.linkerFlags = {
flags = {
FatalLinkWarnings = "/WX",
LinkTimeOptimization = "/GL",
LinkTimeOptimization = "/LTCG",
NoIncrementalLink = "/INCREMENTAL:NO",
NoManifest = "/MANIFEST:NO",
OmitDefaultLibrary = "/NODEFAULTLIB",
},
kind = {
SharedLib = "/DLL",
WindowedApp = "/SUBSYSTEM:WINDOWS"
},
symbols = {
On = "/DEBUG"
Expand Down
61 changes: 60 additions & 1 deletion tests/tools/test_msc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@
test.excludes("/Oy", msc.getcflags(cfg))
end

function suite.cflags_onLinkTimeOptimizations()
flags "LinkTimeOptimization"
prepare()
test.contains("/GL", msc.getcflags(cfg))
JoelLinn marked this conversation as resolved.
Show resolved Hide resolved
end

function suite.ldflags_onLinkTimeOptimizations()
flags "LinkTimeOptimization"
prepare()
test.contains("/GL", msc.getldflags(cfg))
test.contains("/LTCG", msc.getldflags(cfg))
end

function suite.cflags_onStringPoolingOn()
Expand Down Expand Up @@ -512,3 +518,56 @@
prepare()
test.isequal({ "/WX", "/MD", "/EHsc" }, msc.getcxxflags(cfg))
end


--
-- Check handling of Run-Time Library flags.
--

function suite.cflags_onStaticRuntime()
staticruntime "On"
prepare()
test.isequal({ "/MT" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntime()
staticruntime "Off"
prepare()
test.isequal({ "/MD" }, msc.getcflags(cfg))
end

function suite.cflags_onStaticRuntimeAndDebug()
staticruntime "On"
runtime "Debug"
prepare()
test.isequal({ "/MTd" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntimeAndDebug()
staticruntime "Off"
runtime "Debug"
prepare()
test.isequal({ "/MDd" }, msc.getcflags(cfg))
end

function suite.cflags_onStaticRuntimeAndSymbols()
staticruntime "On"
symbols "On"
prepare()
test.isequal({ "/MTd", "/Z7" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntimeAndSymbols()
staticruntime "Off"
symbols "On"
prepare()
test.isequal({ "/MDd", "/Z7" }, msc.getcflags(cfg))
end

function suite.cflags_onDynamicRuntimeAndReleaseAndSymbols()
staticruntime "Off"
runtime "Release"
symbols "On"
prepare()
test.isequal({ "/MD", "/Z7" }, msc.getcflags(cfg))
end