summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-01-28 09:10:34 +0300
committerSaikari <[email protected]>2026-01-28 09:10:34 +0300
commit8747fbba42745624a78f9410b43c8de57106df7c (patch)
tree61ee6637347063b581fa2f86a28e9fc69057824f
parentdc9ce57e004a18678b3d34a9502560fdbf43a742 (diff)
feat: add header file and implement test_add_five function for Nim integration
-rw-r--r--tests/projects/nim/link_library/headers/test_header.h10
-rw-r--r--tests/projects/nim/link_library/maindll.nim11
-rw-r--r--tests/projects/nim/link_library/mainlib.nim11
-rw-r--r--tests/projects/nim/link_library/shared.nim10
-rw-r--r--tests/projects/nim/link_library/static.nim10
-rw-r--r--tests/projects/nim/link_library/xmake.lua7
6 files changed, 59 insertions, 0 deletions
diff --git a/tests/projects/nim/link_library/headers/test_header.h b/tests/projects/nim/link_library/headers/test_header.h
new file mode 100644
index 000000000..4b71d3173
--- /dev/null
+++ b/tests/projects/nim/link_library/headers/test_header.h
@@ -0,0 +1,10 @@
+#ifndef TEST_HEADER_H
+#define TEST_HEADER_H
+
+#define TEST_HEADER_VAL 123
+
+static int test_add_five(int x) {
+ return x + 5;
+}
+
+#endif
diff --git a/tests/projects/nim/link_library/maindll.nim b/tests/projects/nim/link_library/maindll.nim
index d5e4c8283..b13fe1caf 100644
--- a/tests/projects/nim/link_library/maindll.nim
+++ b/tests/projects/nim/link_library/maindll.nim
@@ -3,3 +3,14 @@ import shared
echo "Calling shared lib mulTwo(10): ", mulTwo(10)
echo "Calling shared lib countWords('hello, world, hello'): ", countWords("hello, world, hello")
echo "Calling shared lib getMsg('test'): ", getMsg()
+
+{.emit: """
+#include <test_header.h>
+""".}
+
+var testHeaderVal {.importc: "TEST_HEADER_VAL", nodecl.}: cint
+echo "TEST_HEADER_VAL: ", testHeaderVal
+
+proc test_add_five(x: cint): cint {.importc: "test_add_five", nodecl.}
+echo "test_add_five(80): ", test_add_five(80)
+
diff --git a/tests/projects/nim/link_library/mainlib.nim b/tests/projects/nim/link_library/mainlib.nim
index 6a8078dae..868789d0f 100644
--- a/tests/projects/nim/link_library/mainlib.nim
+++ b/tests/projects/nim/link_library/mainlib.nim
@@ -17,3 +17,14 @@ 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()
+
+{.emit: """
+#include <test_header.h>
+""".}
+
+var testHeaderVal {.importc: "TEST_HEADER_VAL", nodecl.}: cint
+echo "TEST_HEADER_VAL: ", testHeaderVal
+
+proc test_add_five(x: cint): cint {.importc: "test_add_five", nodecl.}
+echo "test_add_five(55): ", test_add_five(55)
+
diff --git a/tests/projects/nim/link_library/shared.nim b/tests/projects/nim/link_library/shared.nim
index 61a204d09..58dacc6df 100644
--- a/tests/projects/nim/link_library/shared.nim
+++ b/tests/projects/nim/link_library/shared.nim
@@ -17,3 +17,13 @@ proc getMsg*(): cstring {.exportc, dynlib.} =
var msg: cstring
{.emit: "`msg` = TEST_MSG;".}
return msg
+
+{.emit: """
+#include <test_header.h>
+""".}
+
+var testHeaderVal {.importc: "TEST_HEADER_VAL", nodecl.}: cint
+echo "TEST_HEADER_VAL: ", testHeaderVal
+
+proc test_add_five(x: cint): cint {.importc: "test_add_five", nodecl.}
+echo "test_add_five(10): ", test_add_five(10)
diff --git a/tests/projects/nim/link_library/static.nim b/tests/projects/nim/link_library/static.nim
index 1a80c5a58..6808d5895 100644
--- a/tests/projects/nim/link_library/static.nim
+++ b/tests/projects/nim/link_library/static.nim
@@ -14,3 +14,13 @@ proc getMsg*(): cstring {.exportc, dynlib.} =
var msg: cstring
{.emit: "`msg` = TEST_MSG;".}
return msg
+
+{.emit: """
+#include <test_header.h>
+""".}
+
+var testHeaderVal {.importc: "TEST_HEADER_VAL", nodecl.}: cint
+echo "TEST_HEADER_VAL: ", testHeaderVal
+
+proc test_add_five(x: cint): cint {.importc: "test_add_five", nodecl.}
+echo "test_add_five(60): ", test_add_five(60)
diff --git a/tests/projects/nim/link_library/xmake.lua b/tests/projects/nim/link_library/xmake.lua
index a9b834a93..76481bd6b 100644
--- a/tests/projects/nim/link_library/xmake.lua
+++ b/tests/projects/nim/link_library/xmake.lua
@@ -4,6 +4,11 @@ add_rules("mode.debug", "mode.release")
add_requires("zlib", {system = false})
add_requires("stb", {system = false})
+target("headers")
+ set_kind("headeronly")
+ add_files("headers/*.h")
+ add_includedirs("headers")
+
target("executablestatic")
set_kind("binary")
add_files("mainlib.nim")
@@ -23,6 +28,7 @@ target("staticlib")
add_includedirs("inc")
add_headerfiles("inc/*.h")
add_syslinks("pthread", "m")
+ add_deps("headers")
target("sharedlib")
set_kind("shared")
@@ -30,3 +36,4 @@ target("sharedlib")
add_includedirs("inc")
add_headerfiles("inc/*.h")
add_syslinks("pthread", "m")
+ add_deps("headers")