xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

Improve copy pdb when using ninja on Windows #5353

Closed star-hengxing closed 4 months ago

star-hengxing commented 4 months ago

Xmake Version

dev

Operating System Version and Architecture

N/A

Describe Bug

使用 ninja 构建一些 debug 包的时候会遇到

if multiple CL.EXE write to the same .PDB file, please use /FS

workaround 方法

if package:is_plat("windows") then
    table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
end

这样解决后,xmake 不会把 pdb 拷贝出来。

Expected Behavior

可能的解决方法:

if package:is_plat("windows") then
    local dir = os.isdir("pdb") and "pdb/" or ""
    if package:config("shared") or not package:is_library() then
        os.vcp(dir .. "**.pdb", package:installdir("bin"))
    else
        os.vcp(dir .. "**.pdb", package:installdir("lib"))
    end
end

Project Configuration

N/A

Additional Information and Error Logs

N/A

waruqi commented 4 months ago

patch /FS 呢

https://github.com/xmake-io/xmake-repo/blob/2989c39b82d4ca991ec8327b8042029be2d8a91e/packages/s/snmalloc/xmake.lua#L24

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


What about patch /FS?

https://github.com/xmake-io/xmake-repo/blob/2989c39b82d4ca991ec8327b8042029be2d8a91e/packages/s/snmalloc/xmake.lua#L24

star-hengxing commented 4 months ago

cmake + debug + ninja 会设置 /FS,但依然报错。 而且我发现只是 jobs 为 1,也是一样的报错

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


cmake + debug + ninja will set /FS, but still report an error. And I found that only if jobs is 1, the same error is reported.

waruqi commented 4 months ago

cmake + debug + ninja 会设置 /FS,但依然报错。 而且我发现只是 jobs 为 1,也是一样的报错

你说的是 backward-cpp 包么,/Fdpdb\ /FS 这个包的 flags 不对,/Fd 后面应该跟一个可写的 pdb file,例如 /Fdxxx.pdb

而不是 pdb/ 目录。。如果 /Fd 后面不是跟的不是可写的 pdb 文件,写入失败,就会报这个错,即使设置了 /FS

所以,其实这个还是 这个包的 cmake 配置,或者 cmake 本身有问题

cl.exe /nologo /TP -DBACKWARD_HAS_BACKTRACE=0 -DBACKWARD_HAS_BACKTRACE_SYMBOL=0 -DBACKWARD_HAS_BFD=0 -DBACKWARD_HAS_DW=0 -DBACKWARD_HAS_DWARF=0 -DBACKWARD_HAS_LIBUNWIND=0 -DBACKWARD_HAS_UNWIND=0 -IC:\Users\wangrunqing\AppData\Local.xmake\cache\packages\2407\b\backward-cpp\v1.6\source /DWIN32 /D_WINDOWS /W3 /GR /EHsc /DWIN32 /D_WINDOWS /W3 /GR /EHsc /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\backward_object.dir\backward.cpp.obj /Fdpdb\ /FS -c C:\Users\wangrunqing\AppData\Local.xmake\cache\packages\2407\b\backward-cpp\v1.6\source\backward.cpp

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


cmake + debug + ninja will set /FS, but still report an error. And I found that only if jobs is 1, the same error is reported.

Are you talking about the backward-cpp package? The flags of /Fdpdb\ /FS are wrong. /Fd should be followed by a writable pdb file, such as /Fdxxx.pdb

instead of the pdb/ directory. . If /Fd is not followed by a pdb file that is not writable and the writing fails, this error will be reported, even if /FS is set.

So, in fact, this is still the cmake configuration of this package, or there is a problem with cmake itself.

cl.exe /nologo /TP -DBACKWARD_HAS_BACKTRACE=0 -DBACKWARD_HAS_BACKTRACE_SYMBOL=0 -DBACKWARD_HAS_BFD=0 -DBACKWARD_HAS_DW=0 -DBACKWARD_HAS_LIBUNWIND=0 -DBACKWARD_HAS_UNWIND=0 -IC:\Users \wangrunqing\AppData\Local.xmake \cache\packages\2407\b\backward-cpp\v1.6\source /DWIN32 /D_WINDOWS /W3 /GR /EHsc /DWIN32 /D_WINDOWS /W3 /GR /EHsc /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles \backward_object.dir\backward.cpp.obj /Fdpdb\ /FS -c C:\Users\wangrunqing\AppData\Local.xmake\cache\packages\2407\b\backward-cpp\v1.6\source\backward .cpp

star-hengxing commented 4 months ago

嗯,不过目前仓库里有 11 个包需要这样 workaround,那感觉 xmake 这边优化下拷贝 pdb 的逻辑可能更好

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


Well, there are currently 11 packages in the warehouse that require this kind of workaround. I feel that it might be better for xmake to optimize the logic of copying pdb here.

waruqi commented 4 months ago

嗯,不过目前仓库里有 11 个包需要这样 workaround,那感觉 xmake 这边优化下拷贝 pdb 的逻辑可能更好

主要还是 cmake 生成的 build.ninja 不会自动创建 build/pdb 目录,导致 /Fdpdb/ 会让 cl.exe 生成 pdb/v140.pdb 写入失败。。

另外一种办法就是提前帮它创建好 build/pdb 目录,就行了

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


Hmm, but there are currently 11 packages in the warehouse that require this kind of workaround. I feel that it might be better for xmake to optimize the logic of copying pdb here.

The main reason is that the build.ninja generated by cmake does not automatically create the build/pdb directory, causing /Fdpdb/ to cause cl.exe to generate pdb/v140.pdb and fail to write. .

Another way is to create the build/pdb directory for it in advance.

waruqi commented 4 months ago

可以试下 这个 patch https://github.com/xmake-io/xmake/pull/5365

durongze commented 1 month ago

if multiple CL.EXE write to the same .PDB file, please use /FS

waruqi commented 1 month ago

if multiple CL.EXE write to the same .PDB file, please use /FS

/FS has been set.