Skip to content

Commit 665fa2c

Browse files
authored
Merge pull request #7582 from choyy/support-nvcc-encodings
support set_encodings with nvcc
2 parents 8197c88 + 9c9c63a commit 665fa2c

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

xmake/languages/cuda/xmake.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ language("cuda")
4040
, "target.vectorexts:check"
4141
, "target.includedirs"
4242
, "target.languages"
43+
, "target.encodings"
4344
, "target.defines"
4445
, "target.undefines"
4546
, "toolchain.includedirs"

xmake/modules/core/tools/nvcc.lua

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,58 @@ function nf_language(self, stdname)
227227
return result
228228
end
229229

230+
-- make the encoding flag
231+
--
232+
-- e.g.
233+
-- set_encodings("utf-8")
234+
-- set_encodings("source:utf-8", "target:utf-8")
235+
function nf_encoding(self, encoding)
236+
local kind
237+
local charset
238+
local splitinfo = encoding:split(":")
239+
if #splitinfo > 1 then
240+
kind = splitinfo[1]
241+
charset = splitinfo[2]
242+
else
243+
charset = encoding
244+
end
245+
local charsets = {
246+
["utf-8"] = "utf-8",
247+
utf8 = "utf-8",
248+
}
249+
local flags = {}
250+
charset = charsets[charset:lower()]
251+
if charset then
252+
if self:is_plat("windows") then
253+
if not kind and charset == "utf-8" then
254+
table.insert(flags, "-Xcompiler")
255+
table.insert(flags, "/utf-8")
256+
else
257+
if kind == "source" or not kind then
258+
table.insert(flags, "-Xcompiler")
259+
table.insert(flags, "-source-charset:" .. charset)
260+
end
261+
if kind == "target" or not kind then
262+
table.insert(flags, "-Xcompiler")
263+
table.insert(flags, "-execution-charset:" .. charset)
264+
end
265+
end
266+
else
267+
if kind == "source" or not kind then
268+
table.insert(flags, "-Xcompiler")
269+
table.insert(flags, "-finput-charset=" .. charset:upper())
270+
end
271+
if kind == "target" or not kind then
272+
table.insert(flags, "-Xcompiler")
273+
table.insert(flags, "-fexec-charset=" .. charset:upper())
274+
end
275+
end
276+
end
277+
if #flags > 0 then
278+
return flags
279+
end
280+
end
281+
230282
-- make the define flag
231283
function nf_define(self, macro)
232284
return {"-D" .. macro}
@@ -329,6 +381,11 @@ end
329381
-- show warnings
330382
function _show_warnings(self, output)
331383
local lines = output:split('\n', {plain = true})
384+
-- filter nvcc output, e.g. xxx.cu, tmpxft_xxx.cudafe1.cpp
385+
table.remove_if(lines, function (_, line)
386+
return line:match("^tmpxft_") or line:match("%.cu$")
387+
end)
388+
332389
if #lines > 0 then
333390
if not option.get("diagnosis") then
334391
lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines))

0 commit comments

Comments
 (0)