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

add_files .manifest 支持实现错误 #2008

Closed
Guyutongxue opened this issue Jan 24, 2022 · 4 comments
Closed

add_files .manifest 支持实现错误 #2008

Guyutongxue opened this issue Jan 24, 2022 · 4 comments
Labels
Milestone

Comments

@Guyutongxue
Copy link
Contributor

描述问题

add_files 提供 .manifest 文件时,应当将该清单作为输入并嵌入可执行文件。而目前 xmake 的实现是错误的:它将 MSVC 链接器的清单文件输出覆盖到对应路径。

期待的结果

add_files("app.manifest") 时,应当向链接器提供如下参数:/MANIFEST:EMBED 以及 /MANIFESTINPUT:${filepath}

(但目前 xmake 的做法是提供 /MANIFEST/MANIFESTFILE 参数,这或许是不正确的:参考结尾附微软文档。)

错误信息

xmake -vD
PS C:\Users\Guyutongxue\Downloads\temp\xmake-bug-repro> xmake -vD
checking for platform ... windows
checking for architecture ... x64
checking for vswhere.exe ... C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe
checking for cl.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checkinfo: cannot runv(dmd.exe --version), No such file or directorychecking for dmd ... no
checkinfo: cannot runv(ldc2.exe --version), No such file or directory
checking for ldc2 ... no
checkinfo: cannot runv(gdc.exe --version), No such file or directory
checking for gdc ... no
checkinfo: cannot runv(zig.exe version), No such file or directory
checking for zig ... no
checkinfo: cannot runv(zig.exe version), No such file or directory
checking for zig ... no
checking for link.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
checking for cl.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\cl.exe
checking for the c++ compiler (cxx) ... cl.exe
checkinfo: cannot runv(ccache.exe --version), No such file or directory
checking for ccache ... no
[ 25%]: compiling.release main.cpp
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX64\\x64\\cl.exe" -c /EHsc -nologo -Fobuild\.objs\xmake-bug-repro\windows\x64\release\main.cpp.obj main.cpp
checking for C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\cl.exe ... ok
checking for flags (cl_sourceDependencies) ... ok
> cl.exe "/sourceDependencies" "C:\Users\Guyutongxue\AppData\Local\Temp\.xmake\220124\_76B06D1EC1614E008E5AF95D5EAA9730.json" "/EHsc"
[ 50%]: linking.release xmake-bug-repro.exe
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 /ManifestFile:app.manifest /manifest -out:build\windows\x64\release\xmake-bug-repro.exe build\.objs\xmake-bug-repro\windows\x64\release\main.cpp.obj
[100%]: build ok!

相关环境

  • xmake版本:v2.6.3+master.e2bbeb1b0
  • xmake运行平台:Windows 11 21H2 (22000.434)
  • xmake目标平台:Windows

其他信息

上述错误极小复现代码:

app.manifest

此文件在编译后会错误地被覆盖。

<!-- App Manifest file is required by IsWindows10OrGreater API -->
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
        <application>
            <!-- Windows 10 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
        </application> 
    </compatibility>
</assembly>

main.cpp

若 Manifest 文件成功嵌入,则在 Windows 10 或更高版本下运行应打印 1。嵌入失败时,打印 0。

#include <Windows.h>
#include <versionhelpers.h>
#include <cstdio>
int main() {
    std::printf("%d\n", IsWindows10OrGreater());
}

xmake.lua

target("xmake-bug-repro")
    add_files("main.cpp", "app.manifest")
    -- correct solution:
    -- add_ldflags("/MANIFEST:EMBED")
    -- add_ldflags("/MANIFESTINPUT:app.manifest", { force = true })

/MANIFEST 与 /MANIFEST:EMBED 文档
/MANIFESTFILE 文档
/MANIFESTINPUT 文档
IsWindows10OrGreater 文档

相关 Issue #1241

@Guyutongxue
Copy link
Contributor Author

I will start a PR to fix this later.

@waruqi
Copy link
Member

waruqi commented Jan 24, 2022

那这个 /manifestfile 主要干什么的?

@Guyutongxue
Copy link
Contributor Author

那这个 /manifestfile 主要干什么的?

当 VS 编译程序时,除了生成 a.exe,默认还会生成 a.manifest。这个 /manifestfile 就是指定这个 a.manifest 的生成文件名的。

而 /manifest:embed 就是把这个文件嵌入到 a.exe 里面去。

@waruqi
Copy link
Member

waruqi commented Jan 24, 2022

哦哦 了解了

@waruqi waruqi added this to the v2.6.4 milestone Jan 24, 2022
@waruqi waruqi closed this as completed Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants