summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-01-28 04:58:48 +0300
committerSaikari <[email protected]>2026-01-28 04:58:48 +0300
commitdc9ce57e004a18678b3d34a9502560fdbf43a742 (patch)
treeebbc139aec0d5c81547dd84aedeaff9a417df3cf
parent31738aa58d1d1ef893124e544440bf9a86981b45 (diff)
feat: add stb_image support and enhance include directory handling for Nim packages
-rw-r--r--tests/projects/nim/link_library/mainlib.nim6
-rw-r--r--tests/projects/nim/link_library/xmake.lua3
-rw-r--r--xmake/modules/core/tools/nim.lua5
-rw-r--r--xmake/rules/nim/build/target.lua26
4 files changed, 38 insertions, 2 deletions
diff --git a/tests/projects/nim/link_library/mainlib.nim b/tests/projects/nim/link_library/mainlib.nim
index 08d877c5d..6a8078dae 100644
--- a/tests/projects/nim/link_library/mainlib.nim
+++ b/tests/projects/nim/link_library/mainlib.nim
@@ -2,12 +2,18 @@ import static
{.emit: """
#include <zlib.h>
+#define STB_IMAGE_IMPLEMENTATION
+#include <stb_image.h>
""".}
proc zlibVersion(): cstring {.importc: "zlibVersion", nodecl.}
+proc stbi_set_flip_vertically_on_load(flag_true_if_should_flip: cint) {.importc: "stbi_set_flip_vertically_on_load", nodecl.}
echo "Zlib Version: ", zlibVersion()
+stbi_set_flip_vertically_on_load(1)
+echo "STB Image: Flip vertically on load set to 1"
+
echo "Calling static lib addTwo(10): ", addTwo(10)
echo "Calling static lib getAlphabet(): ", getAlphabet()
echo "Calling shared lib getMsg('test'): ", getMsg()
diff --git a/tests/projects/nim/link_library/xmake.lua b/tests/projects/nim/link_library/xmake.lua
index c7b2713da..a9b834a93 100644
--- a/tests/projects/nim/link_library/xmake.lua
+++ b/tests/projects/nim/link_library/xmake.lua
@@ -2,12 +2,13 @@ set_project("link_libs")
add_rules("mode.debug", "mode.release")
add_requires("zlib", {system = false})
+add_requires("stb", {system = false})
target("executablestatic")
set_kind("binary")
add_files("mainlib.nim")
add_deps("staticlib")
- add_packages("zlib")
+ add_packages("zlib", "stb")
add_syslinks("pthread", "m")
target("executableshared")
diff --git a/xmake/modules/core/tools/nim.lua b/xmake/modules/core/tools/nim.lua
index b37d29da5..b327cb09c 100644
--- a/xmake/modules/core/tools/nim.lua
+++ b/xmake/modules/core/tools/nim.lua
@@ -133,6 +133,11 @@ function nf_includedir(self, dir)
return {string.format("--passC:\"-I%s\"", path.translate(dir))}
end
+-- make the sysincludedir flag
+function nf_sysincludedir(self, dir)
+ return nf_includedir(self, dir)
+end
+
-- make the link flag
function nf_link(self, lib)
if self:is_plat("windows") then
diff --git a/xmake/rules/nim/build/target.lua b/xmake/rules/nim/build/target.lua
index 948e317f3..ba6750e6b 100644
--- a/xmake/rules/nim/build/target.lua
+++ b/xmake/rules/nim/build/target.lua
@@ -83,6 +83,29 @@ function build_sourcefiles(target, sourcebatch, opt)
-- get compile flags
local compflags = compinst:compflags({target = target})
+ -- add includedirs from packages
+ for _, pkg in ipairs(target:orderpkgs()) do
+ local pkg_includedirs = pkg:get("includedirs")
+ if pkg_includedirs then
+ for _, dir in ipairs(pkg_includedirs) do
+ local includeflags = compinst:_tool():nf_includedir(dir)
+ if includeflags then
+ table.join2(compflags, includeflags)
+ end
+ end
+ end
+ local pkg_sysincludedirs = pkg:get("sysincludedirs")
+ if pkg_sysincludedirs then
+ for _, dir in ipairs(pkg_sysincludedirs) do
+ local tool = compinst:_tool()
+ local includeflags = tool.nf_sysincludedir and tool:nf_sysincludedir(dir) or tool:nf_includedir(dir)
+ if includeflags then
+ table.join2(compflags, includeflags)
+ end
+ end
+ end
+ end
+
-- add rpathdirs to linker flags (for shared lib support)
local rpathdirs = target:get("rpathdirs") or {}
local rpathdirs_wrap = {}
@@ -115,8 +138,9 @@ function build_sourcefiles(target, sourcebatch, opt)
-- 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" then
+ if dep:kind() == "static" or dep:kind() == "shared" or dep:kind() == "headeronly" then
table.join2(includedirs, dep:get("includedirs"))
+ table.join2(includedirs, dep:get("sysincludedirs"))
end
end
if #includedirs > 0 then