Skip to content

Commit 2467c7a

Browse files
committed
Fixes for Ninja on Windows
1 parent a73d125 commit 2467c7a

File tree

3 files changed

+389
-2
lines changed

3 files changed

+389
-2
lines changed

modules/ninja/ninja_cpp.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ function m.getFileCxxFlags(cfg, filecfg, toolset)
436436
local allExternalIncludedirs = table.join(cfg.externalincludedirs or {}, filecfg.externalincludedirs or {})
437437
local allFrameworkdirs = table.join(cfg.frameworkdirs or {}, filecfg.frameworkdirs or {})
438438
local allIncludedirsafter = table.join(cfg.includedirsafter or {}, filecfg.includedirsafter or {})
439-
local includedirs = toolset.getincludedirs(cfg, allIncludedirs, allExternalIncludedirs, allFrameworkdirs, allIncludedirsafter)
439+
local includedirs = toolset.getincludedirs(cfg, allIncludedirs, allExternalIncludedDirs, allFrameworkdirs, allIncludedirsafter)
440440
flags = table.join(flags, includedirs)
441441

442442
local forceincludes = toolset.getforceincludes(filecfg)
@@ -539,6 +539,13 @@ function m.getLdFlags(cfg, toolset)
539539
flags = table.join(flags, rpaths)
540540
end
541541

542+
-- For MSVC shared libraries, add /IMPLIB: to specify the import library location
543+
-- MSVC is Windows-only, so no need to check cfg.system
544+
if cfg.kind == p.SHAREDLIB and toolset == p.tools.msc and not cfg.flags.NoImportLib then
545+
local impLibPath = path.getrelative(cfg.workspace.location, cfg.linktarget.directory) .. "/" .. cfg.linktarget.name
546+
table.insert(flags, "/IMPLIB:" .. impLibPath)
547+
end
548+
542549
return flags
543550
end
544551

@@ -1112,7 +1119,16 @@ function m.linkTarget(cfg)
11121119

11131120
local hasPostBuild = #cfg.postbuildcommands > 0 or cfg.postbuildmessage
11141121

1115-
_p("build %s: %s %s%s", targetPath, rule, table.concat(cfg._objectFiles, " "), implicitDeps)
1122+
-- For MSVC shared libraries with import libraries, list the import library as an implicit output
1123+
-- Dependencies will reference the .lib file (linktarget), which Ninja will know how to build.
1124+
-- MSVC is Windows-only, so no need to check cfg.system
1125+
local implicitOutputs = ""
1126+
if cfg.kind == p.SHAREDLIB and toolset == p.tools.msc and not cfg.flags.NoImportLib then
1127+
local impLibPath = path.getrelative(cfg.workspace.location, cfg.linktarget.directory) .. "/" .. cfg.linktarget.name
1128+
implicitOutputs = " | " .. impLibPath
1129+
end
1130+
1131+
_p("build %s%s: %s %s%s", targetPath, implicitOutputs, rule, table.concat(cfg._objectFiles, " "), implicitDeps)
11161132

11171133
if cfg.kind ~= p.STATICLIB then
11181134
_p(" ldflags = $ldflags_%s", ninja.key(cfg))

modules/ninja/tests/_tests.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ return {
1515
"test_ninja_custom_build.lua",
1616
"test_ninja_custom_rules.lua",
1717
"test_ninja_dependson.lua",
18+
"test_ninja_implib.lua",
1819
"test_ninja_pch.lua",
1920
"test_ninja_perfile_config.lua",
2021
"test_ninja_project.lua",

0 commit comments

Comments
 (0)