summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-01-31 00:32:27 +0800
committerSaikari <[email protected]>2026-01-30 19:57:56 +0300
commit9ac89545c1cb1845b2e2006b98cbe185c8ee64fb (patch)
treecaf297dd60287b8fc9531f707d8b0a131df14f07
parent484b4d116e54eeced612b250344d7d3bf428d187 (diff)
improve nim supports
-rw-r--r--tests/projects/nim/link_library/xmake.lua8
-rw-r--r--xmake/languages/nim/xmake.lua11
-rw-r--r--xmake/rules/nim/build/target.lua97
3 files changed, 13 insertions, 103 deletions
diff --git a/tests/projects/nim/link_library/xmake.lua b/tests/projects/nim/link_library/xmake.lua
index edc577e9e..f15417cb1 100644
--- a/tests/projects/nim/link_library/xmake.lua
+++ b/tests/projects/nim/link_library/xmake.lua
@@ -7,13 +7,13 @@ add_requires("stb", {system = false})
target("headers")
set_kind("headeronly")
add_files("headers/*.h")
- add_includedirs("headers")
+ add_includedirs("headers", {public = true})
target("executablestatic")
set_kind("binary")
add_files("mainlib.nim")
add_deps("staticlib")
- add_packages("zlib", "stb")
+ add_packages("zlib", "stb", {public = true})
if is_plat("linux") then
add_syslinks("pthread", "m")
end
@@ -29,7 +29,7 @@ target("executableshared")
target("staticlib")
set_kind("static")
add_files("static.nim")
- add_includedirs("inc")
+ add_includedirs("inc", {public = true})
add_headerfiles("inc/*.h")
if is_plat("linux") then
add_syslinks("pthread", "m")
@@ -39,7 +39,7 @@ target("staticlib")
target("sharedlib")
set_kind("shared")
add_files("shared.nim")
- add_includedirs("inc")
+ add_includedirs("inc", {public = true})
add_headerfiles("inc/*.h")
if is_plat("linux") then
add_syslinks("pthread", "m")
diff --git a/xmake/languages/nim/xmake.lua b/xmake/languages/nim/xmake.lua
index 7b29bc8a7..458cd1d33 100644
--- a/xmake/languages/nim/xmake.lua
+++ b/xmake/languages/nim/xmake.lua
@@ -39,10 +39,13 @@ language("nim")
, "target.optimize:check"
, "target.vectorexts:check"
, "target.includedirs"
+ , "target.sysincludedirs"
, "toolchain.includedirs"
}
, binary = {
"config.linkdirs"
+ , "target.includedirs"
+ , "target.sysincludedirs"
, "target.linkdirs"
, "target.rpathdirs"
, "target.strip"
@@ -52,12 +55,14 @@ language("nim")
, "config.links"
, "target.links"
, "toolchain.links"
- , "config.syslinks"
- , "target.syslinks"
+ , "config.syslinks"
+ , "target.syslinks"
, "toolchain.syslinks"
}
, shared = {
"config.linkdirs"
+ , "target.includedirs"
+ , "target.sysincludedirs"
, "target.linkdirs"
, "target.strip"
, "target.symbols"
@@ -72,6 +77,8 @@ language("nim")
, static = {
"target.strip"
, "target.symbols"
+ , "target.includedirs"
+ , "target.sysincludedirs"
}
}
diff --git a/xmake/rules/nim/build/target.lua b/xmake/rules/nim/build/target.lua
index dd12c8ae7..52599b74d 100644
--- a/xmake/rules/nim/build/target.lua
+++ b/xmake/rules/nim/build/target.lua
@@ -25,16 +25,6 @@ import("core.tool.compiler")
import("core.project.depend")
import("utils.progress")
--- get values from target
--- @see https://github.com/xmake-io/xmake/issues/3930
-local function _get_values_from_target(target, name)
- local values = {}
- for _, value in ipairs((target:get_from(name, "*"))) do
- table.join2(values, value)
- end
- return table.unique(values)
-end
-
-- generate dependency info
function _generate_dependinfo(compinst, compflags, sourcefiles, dependinfo)
@@ -74,90 +64,6 @@ function _generate_dependinfo(compinst, compflags, sourcefiles, dependinfo)
end
end
--- add dependency flags
-function _add_dependency_flags(target, compinst, compflags)
-
- -- add flags from target (includedirs, links, ...)
- local pathmaps = {
- {"includedirs", "includedir"},
- {"sysincludedirs", "sysincludedir"},
- {"linkdirs", "linkdir"}
- }
- for _, pathmap in ipairs(pathmaps) do
- local flags = compiler.map_flags("nim", pathmap[2], _get_values_from_target(target, pathmap[1]))
- if flags then
- table.join2(compflags, flags)
- end
- end
-
- local linkmaps = {
- {"links", "link"},
- {"syslinks", "syslink"}
- }
- for _, linkmap in ipairs(linkmaps) do
- local flags = compiler.map_flags("nim", linkmap[2], _get_values_from_target(target, linkmap[1]))
- if flags then
- table.join2(compflags, flags)
- end
- end
-
- -- add flags from packages
- for _, pkg in ipairs(target:orderpkgs()) do
- for _, pathmap in ipairs(pathmaps) do
- local flags = compiler.map_flags("nim", pathmap[2], pkg:get(pathmap[1]))
- if flags then
- table.join2(compflags, flags)
- end
- end
- for _, linkmap in ipairs(linkmaps) do
- local flags = compiler.map_flags("nim", linkmap[2], pkg:get(linkmap[1]))
- if flags then
- table.join2(compflags, flags)
- end
- end
- end
-
- -- add rpathdirs to linker flags (for shared lib support)
- local rpathdirs_wrap = {}
-
- -- add rpathdirs from dependencies
- if target:is_binary() or target:is_shared() then
- for _, dep in ipairs(target:orderdeps()) do
- if dep:is_shared() then
- table.insert(rpathdirs_wrap, dep:targetdir())
- end
- end
- end
-
- if #rpathdirs_wrap > 0 then
- -- deduplicate
- rpathdirs_wrap = table.unique(rpathdirs_wrap)
- local rpathflags = compiler.map_flags("nim", "rpathdir", rpathdirs_wrap)
- if rpathflags then
- table.join2(compflags, rpathflags)
- end
- end
-
- -- add includedirs from dependencies (for static/shared lib with exportc)
- -- the dependencies will be compiled via imported symbol at the end
- -- we need pass includedirs of static/shared lib to the target
- local includedirs = {}
- for _, dep in ipairs(target:orderdeps()) do
- if dep:kind() == "static" or dep:kind() == "shared" or dep:is_headeronly() then
- table.join2(includedirs, table.wrap(dep:get("includedirs")))
- table.join2(includedirs, table.wrap(dep:get("sysincludedirs")))
- end
- end
- if #includedirs > 0 then
- -- deduplicate
- includedirs = table.unique(includedirs)
- local includeflags = compiler.map_flags("nim", "includedir", includedirs)
- if includeflags then
- table.join2(compflags, includeflags)
- end
- end
-end
-
-- build the source files
function build_sourcefiles(target, sourcebatch, opt)
@@ -177,9 +83,6 @@ function build_sourcefiles(target, sourcebatch, opt)
-- get compile flags
local compflags = compinst:compflags({target = target})
- -- add dependency flags
- _add_dependency_flags(target, compinst, compflags)
-
-- load dependent info
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})