aboutsummaryrefslogtreecommitdiff
path: root/examples/hello_world_c_zig
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-09-23 12:22:37 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit5006226e945fc645e6d9b21252c9eee53cc191cc (patch)
tree94371016233562351d70fb3b9ff312c6dacd9bb4 /examples/hello_world_c_zig
parent8fdc481d78a0426f6dbf235e872c3798ec57251e (diff)
Fix various things, add generated zig header files to global include
Fix compile_commands.json missing build steps. Fix c includes -> zig includes flags. Fix crash when running sibs new/init without defining lang. Add generated zig header files to global include so they can be used from c/c++. Add zig and zig/c (using zig and c in the same project) examples.
Diffstat (limited to 'examples/hello_world_c_zig')
-rw-r--r--examples/hello_world_c_zig/.gitignore5
-rw-r--r--examples/hello_world_c_zig/project.conf8
-rw-r--r--examples/hello_world_c_zig/src/foo.zig8
-rw-r--r--examples/hello_world_c_zig/src/main.c14
-rw-r--r--examples/hello_world_c_zig/tests/main.c7
5 files changed, 42 insertions, 0 deletions
diff --git a/examples/hello_world_c_zig/.gitignore b/examples/hello_world_c_zig/.gitignore
new file mode 100644
index 0000000..636c6b9
--- /dev/null
+++ b/examples/hello_world_c_zig/.gitignore
@@ -0,0 +1,5 @@
+# Compiled sibs files
+sibs-build/
+compile_commands.json
+tests/sibs-build/
+tests/compile_commands.json
diff --git a/examples/hello_world_c_zig/project.conf b/examples/hello_world_c_zig/project.conf
new file mode 100644
index 0000000..fa006cd
--- /dev/null
+++ b/examples/hello_world_c_zig/project.conf
@@ -0,0 +1,8 @@
+[package]
+name = "hello_world_c_zig"
+type = "executable"
+version = "0.1.0"
+platforms = ["linux64"]
+tests = "tests"
+
+[dependencies]
diff --git a/examples/hello_world_c_zig/src/foo.zig b/examples/hello_world_c_zig/src/foo.zig
new file mode 100644
index 0000000..464eadd
--- /dev/null
+++ b/examples/hello_world_c_zig/src/foo.zig
@@ -0,0 +1,8 @@
+const warn = @import("std").debug.warn;
+
+extern fn baz() void;
+
+export fn foo() void {
+ warn("zig called from c!\n");
+ baz();
+}
diff --git a/examples/hello_world_c_zig/src/main.c b/examples/hello_world_c_zig/src/main.c
new file mode 100644
index 0000000..aeaeae4
--- /dev/null
+++ b/examples/hello_world_c_zig/src/main.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <zig/src/foo.h>
+
+void baz()
+{
+ printf("c called from zig!\n");
+}
+
+int main(int argc, char **argv)
+{
+ printf("inside c\n");
+ foo();
+ return 0;
+}
diff --git a/examples/hello_world_c_zig/tests/main.c b/examples/hello_world_c_zig/tests/main.c
new file mode 100644
index 0000000..9ad80a6
--- /dev/null
+++ b/examples/hello_world_c_zig/tests/main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ printf("hello, world!\n");
+ return 0;
+}