diff options
Diffstat (limited to 'tests/projects/zig')
| -rw-r--r-- | tests/projects/zig/c_interop/src/main.zig | 11 | ||||
| -rw-r--r-- | tests/projects/zig/c_interop/src/native/mathlib.c | 9 | ||||
| -rw-r--r-- | tests/projects/zig/c_interop/src/native/mathlib.h | 7 | ||||
| -rw-r--r-- | tests/projects/zig/c_interop/test.lua | 10 | ||||
| -rw-r--r-- | tests/projects/zig/c_interop/xmake.lua | 12 | ||||
| -rw-r--r-- | tests/projects/zig/c_interop_with_package/src/main.zig | 10 | ||||
| -rw-r--r-- | tests/projects/zig/c_interop_with_package/test.lua | 10 | ||||
| -rw-r--r-- | tests/projects/zig/c_interop_with_package/xmake.lua | 7 |
8 files changed, 76 insertions, 0 deletions
diff --git a/tests/projects/zig/c_interop/src/main.zig b/tests/projects/zig/c_interop/src/main.zig new file mode 100644 index 000000000..6cd61100d --- /dev/null +++ b/tests/projects/zig/c_interop/src/main.zig @@ -0,0 +1,11 @@ +const std = @import("std"); +const c = @cImport({ + @cInclude("mathlib.h"); +}); + +pub fn main() void { + const sum = c.c_add(3, 4); + const product = c.c_multiply(5, 6); + std.debug.print("c_add(3,4)={d}\n", .{sum}); + std.debug.print("c_multiply(5,6)={d}\n", .{product}); +} diff --git a/tests/projects/zig/c_interop/src/native/mathlib.c b/tests/projects/zig/c_interop/src/native/mathlib.c new file mode 100644 index 000000000..8728d1df3 --- /dev/null +++ b/tests/projects/zig/c_interop/src/native/mathlib.c @@ -0,0 +1,9 @@ +#include "mathlib.h" + +int c_add(int a, int b) { + return a + b; +} + +int c_multiply(int a, int b) { + return a * b; +} diff --git a/tests/projects/zig/c_interop/src/native/mathlib.h b/tests/projects/zig/c_interop/src/native/mathlib.h new file mode 100644 index 000000000..78dcbc931 --- /dev/null +++ b/tests/projects/zig/c_interop/src/native/mathlib.h @@ -0,0 +1,7 @@ +#ifndef MATHLIB_H +#define MATHLIB_H + +int c_add(int a, int b); +int c_multiply(int a, int b); + +#endif diff --git a/tests/projects/zig/c_interop/test.lua b/tests/projects/zig/c_interop/test.lua new file mode 100644 index 000000000..62ed37e4d --- /dev/null +++ b/tests/projects/zig/c_interop/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local zig = find_tool("zig") + if zig then + t:build() + else + return t:skip("zig not found") + end +end diff --git a/tests/projects/zig/c_interop/xmake.lua b/tests/projects/zig/c_interop/xmake.lua new file mode 100644 index 000000000..3c93834bb --- /dev/null +++ b/tests/projects/zig/c_interop/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +target("mathlib") + set_kind("static") + add_files("src/native/*.c") + add_includedirs("src/native", {public = true}) + +target("test") + set_kind("binary") + add_deps("mathlib") + add_files("src/*.zig") + add_includedirs("src/native") diff --git a/tests/projects/zig/c_interop_with_package/src/main.zig b/tests/projects/zig/c_interop_with_package/src/main.zig new file mode 100644 index 000000000..21dd9eb9a --- /dev/null +++ b/tests/projects/zig/c_interop_with_package/src/main.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const c = @cImport({ + @cInclude("zlib.h"); +}); + +pub fn main() void { + const version = c.zlibVersion(); + const ver_str: [*:0]const u8 = @ptrCast(version); + std.debug.print("zlib version: {s}\n", .{ver_str}); +} diff --git a/tests/projects/zig/c_interop_with_package/test.lua b/tests/projects/zig/c_interop_with_package/test.lua new file mode 100644 index 000000000..62ed37e4d --- /dev/null +++ b/tests/projects/zig/c_interop_with_package/test.lua @@ -0,0 +1,10 @@ +import("lib.detect.find_tool") + +function test_build(t) + local zig = find_tool("zig") + if zig then + t:build() + else + return t:skip("zig not found") + end +end diff --git a/tests/projects/zig/c_interop_with_package/xmake.lua b/tests/projects/zig/c_interop_with_package/xmake.lua new file mode 100644 index 000000000..56b95995d --- /dev/null +++ b/tests/projects/zig/c_interop_with_package/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") +add_requires("zlib", {system = false}) + +target("test") + set_kind("binary") + add_files("src/*.zig") + add_packages("zlib") |
