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

ninja: error: build.ninja:68: unknown build rule 'cu' #5646

Open
dddddjent opened this issue Sep 22, 2024 · 5 comments
Open

ninja: error: build.ninja:68: unknown build rule 'cu' #5646

dddddjent opened this issue Sep 22, 2024 · 5 comments

Comments

@dddddjent
Copy link

Xmake 版本

2.9.4

操作系统版本和架构

Archlinux

描述问题

xmake project -k ninja 生成的build.ninja没有cuda编译相关的rule,不能正常编译
但是直接xmake build可以

期待的结果

ninja能够成功编译

工程配置

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!

@dddddjent dddddjent added the bug label Sep 22, 2024
@Issues-translate-bot
Copy link

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


Xmake version

2.9.4

Operating system version and architecture

Archlinux

Describe the problem

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

Expected results

ninja can compile successfully

Project configuration

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")

Additional information and error logs

Create OK!

@waruqi
Copy link
Member

waruqi commented Sep 23, 2024

我暂时没有 cuda 环境,你可以自己在这个位置加上 cuda.build 的 rule 试试,然后提个 pr 过来。。

or rulename == "objc.build" or rulename == "objc++.build" then

@Issues-translate-bot
Copy link

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. .

or rulename == "objc.build" or rulename == "objc++.build" then

@star-hengxing
Copy link
Contributor

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)

@Issues-translate-bot
Copy link

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)

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

No branches or pull requests

4 participants