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

Support custom vc build tools #5823

Merged
merged 13 commits into from
Nov 20, 2024
Merged

Conversation

star-hengxing
Copy link
Contributor

@star-hengxing
Copy link
Contributor Author

msvc-wine 并没有提供类似 bat 的环境变量工具 mstorsjo/msvc-wine#146 ,但他们目录结构都是 VCWindows Kits 这样。
感觉可以做成,让用户指定安装目录,xmake 去解析这个目录,类似于 find_qt,比 bat 稳定性好。

@star-hengxing star-hengxing marked this pull request as draft November 15, 2024 06:47
@waruqi
Copy link
Member

waruqi commented Nov 15, 2024

msvc-wine 并没有提供类似 bat 的环境变量工具 mstorsjo/msvc-wine#146 ,但他们目录结构都是 VCWindows Kits 这样。 感觉可以做成,让用户指定安装目录,xmake 去解析这个目录,类似于 find_qt,比 bat 稳定性好。

那就直接复用 --sdk= 参数,如果指定了 xmake f -p windows --sdk=/xxxxx/ ,就尝试从 sdkdir 中探测 vs 环境

@star-hengxing
Copy link
Contributor Author

msvc-wine...

/home/star/msvc/bin/x64/cl.exe -c -nologo -O2 /EHsc -DNDEBUG -Fobuild/.objs/test/windows/x64/release/src/main.cpp.obj src/main.cpp
checking for flags (cl_sourceDependencies) ... no
> cl.exe "/sourceDependencies" "/tmp/.xmake1000/241115/_47189BF6655A4500867A807596EDBC10.json" "-nologo"
checkinfo: _2A70BC855C6B47118314FA08E23BEC9B.cpp
z:\tmp\.xmake1000\241115\_2A70BC855C6B47118314FA08E23BEC9B.cpp : fatal error C1083: Cannot open compiler generated file: 'z:\dev\null.obj': Permission denied

@star-hengxing
Copy link
Contributor Author

star-hengxing commented Nov 15, 2024

add_rules("mode.debug", "mode.release")

set_runtimes("MD")

add_requires("fmt[shared]")
add_packages("fmt")

target("test")
    set_kind("shared")
    add_files("src/*.cpp")
$ xmake f -c -p windows -a x64 --sdk=~/msvc
$ xmake -v
checking for the c++ compiler (cxx) ... cl.exe
checking for flags (-O2) ... ok
checking for flags (-DNDEBUG) ... ok
[ 50%]: cache compiling.release src/main.cpp
/home/star/msvc/bin/x64/cl.exe -c -nologo -O2 -MD -DFMT_LIB_EXPORT /EHsc -I/home/star/.xmake/packages/f/fmt/11.0.2/5686d8134ed840a1bdc1f40efb05e098/include /utf-8 -DNDEBUG -Fobuild/.objs/test/windows/x64/release/src/main.cpp.obj src/main.cpp
checking for flags (cl_sourceDependencies) ... no
[ 75%]: linking.release test.dll
/home/star/msvc/bin/x64/link.exe -dll -nologo -machine:x64 -libpath:/home/star/.xmake/packages/f/fmt/11.0.2/5686d8134ed840a1bdc1f40efb05e098/lib /opt:ref /opt:icf fmt.lib -out:build/windows/x64/release/test.dll build/.objs/test/windows/x64/release/src/main.cpp.obj
checking for the c compiler (cc) ... cl.exe
[100%]: build ok, spent 1.637s

@star-hengxing star-hengxing marked this pull request as ready for review November 18, 2024 11:55
@star-hengxing
Copy link
Contributor Author

  • 目前 clang toolchain 显式加上了 --target= 参数,不然在 windows 上是不会去用 build tools 的,这里小概率会 break 一些项目?
  • clang-xx 目前因为 xmake.lua 位置不一样导致 import 报错,不知道这里有没有更好的写法,或者用 import("check", {rootdir = "xxx"})
  • 发行版打包策略不一样,导致 clang 相关工具链有一些问题。
    • 没有打包 clang-cl ,只能用 clang toolchain。
    • 没有给 lld-link 设置 alias ,只能用 -fuse-ld=lld-link-xx
  • 给 clang 添加了 mingw 平台的支持,会显式加上 --target=--sysroot= ,这个支持是顺手做的,如果没必要可以删了。

@Issues-translate-bot
Copy link

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


  • At present, the clang toolchain explicitly adds the --target= parameter, otherwise the build tools will not be used on windows. Is there a small chance that some projects will break?
  • clang-xx currently reports an import error due to the different location of xmake.lua. I don’t know if there is a better way to write it here, or use import("check", {rootdir = "xxx"}).
  • The packaging strategies of distributions are different, which leads to some problems in clang-related tool chains.
    • clang-cl is not packaged, only clang toolchain can be used.
    • No alias is set for lld-link, only -fuse-ld=lld-link-xx can be used
  • Added mingw platform support to clang, and will explicitly add --target= and --sysroot=. This support is done conveniently, and can be deleted if it is not necessary.

@waruqi
Copy link
Member

waruqi commented Nov 19, 2024

  • clang-xx 目前因为 xmake.lua 位置不一样导致 import 报错,不知道这里有没有更好的写法,或者用 import("check", {rootdir = "xxx"})

为啥会位置不同,用的是当前目录下的 check.lua , xmake.lua 不也在这个目录下么。

@Issues-translate-bot
Copy link

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


  • clang-xx currently reports an import error due to the different location of xmake.lua. I don’t know if there is a better way to write it here, or use import("check", {rootdir = "xxx"}).

Why are the locations different? Check.lua in the current directory is used. Isn’t xmake.lua also in this directory?

@star-hengxing
Copy link
Contributor Author

error: @programdir\core\main.lua:329: @programdir\core\tool\toolchain.lua:284: ...mdir\core\sandbox\modules\import\core\sandbox\module.lua:557: cannot import module: check, not found!
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1004]:
    [...mdir\core\sandbox\modules\import\core\sandbox\module.lua:557]: in function 'import'
    [@programdir\toolchains\clang-19\..\clang\xmake.lua:48]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:244]:
    [@programdir\core\tool\toolchain.lua:280]: in function 'check'
    [@programdir\actions\config\main.lua:144]: in function '_check_target_toolchains'
    [@programdir\actions\config\main.lua:403]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:244]:
    [@programdir\core\base\task.lua:491]: in function 'run'
    [@programdir\core\main.lua:327]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1004: in function 'os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>

@waruqi
Copy link
Member

waruqi commented Nov 19, 2024

我这可以的么

ruki-2:test ruki$ xmake f --toolchain=clang -c
checking for platform ... macosx
checking for architecture ... x86_64
check
diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua
index cc8da1d26..b5eb7ec15 100644
--- a/xmake/toolchains/clang/xmake.lua
+++ b/xmake/toolchains/clang/xmake.lua
@@ -44,6 +44,7 @@ toolchain("clang" .. suffix)
     set_toolset("mrc", "llvm-rc")

     on_check(function (toolchain)
+        import("check")()
         return import("lib.detect.find_tool")("clang" .. suffix)
     end)

$ cat xmake/toolchains/clang/check.lua
function main()
    print("check")
end

@star-hengxing
Copy link
Contributor Author

可能没描述清楚,需要指定 clang 版本 set_toolchains("clang-19")

@Issues-translate-bot
Copy link

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


It may not be described clearly, you need to specify the clang version set_toolchains("clang-19")

@waruqi
Copy link
Member

waruqi commented Nov 19, 2024

可能没描述清楚,需要指定 clang 版本 set_toolchains("clang-19")

哦,那是因为加了 suffix 目录不对了,那就加个 rootdir 就好了

@Issues-translate-bot
Copy link

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


It may not be described clearly, you need to specify the clang version set_toolchains("clang-19")

Oh, that’s because adding the suffix directory is wrong, then just add a rootdir.

@waruqi waruqi added this to the v2.9.7 milestone Nov 20, 2024
@waruqi
Copy link
Member

waruqi commented Nov 20, 2024

目前看没啥大问题,能开个 issues ,大概备注下 当前 patch 支持的 toolchains,对应的下载 link ,以及配置和编译命令么? 也便于其他人查阅使用,后期也方便同步到文档。

另外,这些 toolchain 如果能做成包,直接走包集成使用就更好了,直接一键拉取编译。

还有,msvc wine 里面带 wine 么,是不是编译出来的 bin ,也可以扩展 xmake run,直接通过 wine 运行?这样 linux 上,编译运行都可以一起搞定了。

@waruqi waruqi merged commit 6f2dc65 into xmake-io:dev Nov 20, 2024
19 checks passed
@Issues-translate-bot
Copy link

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


There are no big problems so far. Can you open an issue and make notes about the toolchains supported by the current patch, the corresponding download links, and the configuration and compilation commands? It is also convenient for other people to check and use, and it is also convenient to synchronize to the document later.

In addition, it would be better if these toolchains can be made into packages and directly integrated and used, and they can be directly pulled and compiled with one click.

_get_configs_for_cross(package, configs, opt)
else
_get_configs_for_generic(package, configs, opt)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

貌似 windows 平台使用了交叉编译 configs 反而才是对的,不过可能会 break 一些包。
比如在交叉编译下,CMAKE_SYSTEM_VERSION 这个值是空的,需要手动传参

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants