aboutsummaryrefslogtreecommitdiff
path: root/example/shared_library
diff options
context:
space:
mode:
Diffstat (limited to 'example/shared_library')
-rw-r--r--example/shared_library/build.zig20
-rw-r--r--example/shared_library/mathtest.zig4
-rw-r--r--example/shared_library/test.c4
3 files changed, 22 insertions, 6 deletions
diff --git a/example/shared_library/build.zig b/example/shared_library/build.zig
new file mode 100644
index 0000000000..1212c58ab8
--- /dev/null
+++ b/example/shared_library/build.zig
@@ -0,0 +1,20 @@
+const Builder = @import("std").build.Builder;
+
+pub fn build(b: &Builder) {
+ const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
+
+ const exe = b.addCExecutable("test");
+ exe.addCompileFlags([][]const u8 {
+ "-std=c99",
+ });
+ exe.addSourceFile("test.c");
+ exe.linkLibrary(lib);
+
+ b.default_step.dependOn(&exe.step);
+
+ const run_cmd = b.addCommand(b.out_dir, b.env_map, "./test", [][]const u8{});
+ run_cmd.step.dependOn(&exe.step);
+
+ const test_step = b.step("test", "Test the program");
+ test_step.dependOn(&run_cmd.step);
+}
diff --git a/example/shared_library/mathtest.zig b/example/shared_library/mathtest.zig
index 9dc33b9555..a11642554f 100644
--- a/example/shared_library/mathtest.zig
+++ b/example/shared_library/mathtest.zig
@@ -1,7 +1,3 @@
export fn add(a: i32, b: i32) -> i32 {
a + b
}
-
-export fn hang() -> unreachable {
- while (true) { }
-}
diff --git a/example/shared_library/test.c b/example/shared_library/test.c
index 4fff250f08..b60a6a5a75 100644
--- a/example/shared_library/test.c
+++ b/example/shared_library/test.c
@@ -1,7 +1,7 @@
#include "mathtest.h"
-#include <stdio.h>
+#include <assert.h>
int main(int argc, char **argv) {
- printf("%d\n", add(42, 1137));
+ assert(add(42, 1337) == 1379);
return 0;
}