diff options
| author | ruki <[email protected]> | 2026-06-04 22:37:10 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-06-04 22:37:10 +0800 |
| commit | 665fa2c71bb53c2d621f6a3a1a1116f90d56fb21 (patch) | |
| tree | b18b5b97497ff2414d03eaecc0a1a2582ecd09fe | |
| parent | 8197c881a6699fd29b55645e7e8b0cea0dc6d775 (diff) | |
| parent | 9c9c63ad974234bee8a771e4b15aa5cf4a778522 (diff) | |
Merge pull request #7582 from choyy/support-nvcc-encodings
support set_encodings with nvcc
| -rw-r--r-- | xmake/languages/cuda/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 57 |
2 files changed, 58 insertions, 0 deletions
diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index ae43f7fc0..2ae6e26a0 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -40,6 +40,7 @@ language("cuda") , "target.vectorexts:check" , "target.includedirs" , "target.languages" + , "target.encodings" , "target.defines" , "target.undefines" , "toolchain.includedirs" diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 41ae28274..9ce9efdb3 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -227,6 +227,58 @@ function nf_language(self, stdname) return result end +-- make the encoding flag +-- +-- e.g. +-- set_encodings("utf-8") +-- set_encodings("source:utf-8", "target:utf-8") +function nf_encoding(self, encoding) + local kind + local charset + local splitinfo = encoding:split(":") + if #splitinfo > 1 then + kind = splitinfo[1] + charset = splitinfo[2] + else + charset = encoding + end + local charsets = { + ["utf-8"] = "utf-8", + utf8 = "utf-8", + } + local flags = {} + charset = charsets[charset:lower()] + if charset then + if self:is_plat("windows") then + if not kind and charset == "utf-8" then + table.insert(flags, "-Xcompiler") + table.insert(flags, "/utf-8") + else + if kind == "source" or not kind then + table.insert(flags, "-Xcompiler") + table.insert(flags, "-source-charset:" .. charset) + end + if kind == "target" or not kind then + table.insert(flags, "-Xcompiler") + table.insert(flags, "-execution-charset:" .. charset) + end + end + else + if kind == "source" or not kind then + table.insert(flags, "-Xcompiler") + table.insert(flags, "-finput-charset=" .. charset:upper()) + end + if kind == "target" or not kind then + table.insert(flags, "-Xcompiler") + table.insert(flags, "-fexec-charset=" .. charset:upper()) + end + end + end + if #flags > 0 then + return flags + end +end + -- make the define flag function nf_define(self, macro) return {"-D" .. macro} @@ -329,6 +381,11 @@ end -- show warnings function _show_warnings(self, output) local lines = output:split('\n', {plain = true}) + -- filter nvcc output, e.g. xxx.cu, tmpxft_xxx.cudafe1.cpp + table.remove_if(lines, function (_, line) + return line:match("^tmpxft_") or line:match("%.cu$") + end) + if #lines > 0 then if not option.get("diagnosis") then lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines)) |
