Open dddddjent opened 1 month ago
Bot detected the issue body's language is not English, translate it automatically.
Xmake version
2.9.4
Archlinux
The build.ninja generated by xmake project -k ninja
does not have rules related to cuda compilation and cannot be compiled normally.
But you can directly xmake build
ninja can compile successfully
xmake create [project_name]
mv src/main.cpp src/main.cu
add_rules("mode.debug", "mode.release")
target("xmake_cuda_ninja_test")
set_kind("binary")
add_files("src/*.cu")
Create OK!
我暂时没有 cuda 环境,你可以自己在这个位置加上 cuda.build
的 rule 试试,然后提个 pr 过来。。
Bot detected the issue body's language is not English, translate it automatically.
I don’t have a cuda environment for the time being. You can try adding the
cuda.build
rule to this location and submit a PR. .
rule name 很早就加了,所以这里加一行就能编译正常 cuda 代码。不过 devlink 不是基于 batchcmd,目前不太好处理。
diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua
index 2e55faf05..4d913a3ea 100644
--- a/xmake/plugins/project/ninja/build_ninja.lua
+++ b/xmake/plugins/project/ninja/build_ninja.lua
@@ -182,6 +182,14 @@ function _add_rules_for_compiler_windres(ninjafile, sourcekind, program)
ninjafile:print("")
end
+-- add rules for complier (cuda/nvcc)
+function _add_rules_for_compiler_cuda(ninjafile, sourcekind, program)
+ ninjafile:print("rule %s", sourcekind)
+ ninjafile:print(" command = %s -c $ARGS $in -o $out", program)
+ ninjafile:print(" description = compiling.%s $in", config.mode())
+ ninjafile:print("")
+end
+
-- add rules for complier
function _add_rules_for_compiler(ninjafile)
ninjafile:print("# rules for compiler")
@@ -203,7 +211,8 @@ function _add_rules_for_compiler(ninjafile)
ml = _add_rules_for_compiler_msvc_ml,
ml64 = _add_rules_for_compiler_msvc_ml,
rc = _add_rules_for_compiler_msvc_rc,
- windres = _add_rules_for_compiler_windres
+ windres = _add_rules_for_compiler_windres,
+ nvcc = _add_rules_for_compiler_cuda,
}
for sourcekind, _ in pairs(language.sourcekinds()) do
local program, toolname = platform.tool(sourcekind)
Bot detected the issue body's language is not English, translate it automatically.
The rule name was added very early, so adding one line here can compile normal cuda code. However, devlink is not based on batchcmd and is currently not easy to handle.
diff --git a/xmake/plugins/project/ninja/build_ninja.lua b/xmake/plugins/project/ninja/build_ninja.lua
index 2e55faf05..4d913a3ea 100644
--- a/xmake/plugins/project/ninja/build_ninja.lua
+++ b/xmake/plugins/project/ninja/build_ninja.lua
@@ -182,6 +182,14 @@ function _add_rules_for_compiler_windres(ninjafile, sourcekind, program)
ninjafile:print("")
end
+-- add rules for complier (cuda/nvcc)
+function _add_rules_for_compiler_cuda(ninjafile, sourcekind, program)
+ ninjafile:print("rule %s", sourcekind)
+ ninjafile:print(" command = %s -c $ARGS $in -o $out", program)
+ ninjafile:print(" description = compiling.%s $in", config.mode())
+ ninjafile:print("")
+end
+
-- add rules for complier
function _add_rules_for_compiler(ninjafile)
ninjafile:print("# rules for compiler")
@@ -203,7 +211,8 @@ function _add_rules_for_compiler(ninjafile)
ml = _add_rules_for_compiler_msvc_ml,
ml64 = _add_rules_for_compiler_msvc_ml,
rc = _add_rules_for_compiler_msvc_rc,
- windres = _add_rules_for_compiler_windres
+ windres = _add_rules_for_compiler_windres,
+ nvcc = _add_rules_for_compiler_cuda,
}
for sourcekind, _ in pairs(language.sourcekinds()) do
local program, toolname = platform.tool(sourcekind)
+-- add rules for complier (cuda/nvcc) +function _add_rules_for_compiler_cuda(ninjafile, sourcekind, program) + ninjafile:print("rule %s", sourcekind) + ninjafile:print(" command = %s -c $ARGS $in -o $out", program) + ninjafile:print(" description = compiling.%s $in", config.mode()) + ninjafile:print("") +end
这个 patch 我加上了,可以先试下
@dddddjent
Bot detected the issue body's language is not English, translate it automatically.
+-- add rules for complier (cuda/nvcc) +function _add_rules_for_compiler_cuda(ninjafile, sourcekind, program) + ninjafile:print("rule %s", sourcekind) + ninjafile:print(" command = %s -c $ARGS $in -o $out", program) + ninjafile:print(" description = compiling.%s $in", config.mode()) + ninjafile:print("") +end
I added this patch, you can try it first
@dddddjent
Xmake 版本
2.9.4
操作系统版本和架构
Archlinux
描述问题
xmake project -k ninja
生成的build.ninja没有cuda编译相关的rule,不能正常编译 但是直接xmake build可以期待的结果
ninja能够成功编译
工程配置
附加信息和错误日志
create ok!