From ea2d5d2454167ee9fe293427df729ff60baee22f Mon Sep 17 00:00:00 2001 From: chooyy Date: Thu, 4 Jun 2026 15:52:38 +0800 Subject: support set_encodings with nvcc --- xmake/languages/cuda/xmake.lua | 1 + xmake/modules/core/tools/nvcc.lua | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) 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..2b9eea319 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} -- cgit v1.3.1 From 9c9c63ad974234bee8a771e4b15aa5cf4a778522 Mon Sep 17 00:00:00 2001 From: chooyy Date: Thu, 4 Jun 2026 16:23:39 +0800 Subject: filter nvcc output --- xmake/modules/core/tools/nvcc.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 2b9eea319..9ce9efdb3 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -381,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)) -- cgit v1.3.1