A => .hgignore +1 -0
@@ 0,0 1,1 @@
+^zig-(cache|out)/
A => build.zig +36 -0
@@ 0,0 1,36 @@
+const std = @import("std");
+
+pub fn build(b: *std.build.Builder) void {
+ const mode = b.standardReleaseOptions();
+
+ const janet_headers = b.option([]const u8, "janet-headers", "Location of Janet headers");
+
+ const obj = b.addObject("baseenc-zig", "src/baseenc.zig");
+ obj.setBuildMode(mode);
+
+ const slib = b.addStaticLibrary("baseenc", "src/baseenc.c");
+ slib.linker_allow_shlib_undefined = true;
+ slib.pie = true;
+ if (janet_headers) |h| slib.addIncludeDir(h);
+ slib.setBuildMode(mode);
+ slib.addObject(obj);
+ slib.linkSystemLibrary("pthread");
+ slib.defineCMacro("JANET_ENTRY_NAME", "janet_module_entry_baseenc");
+ slib.install();
+
+ const dlib = b.addSharedLibrary("baseenc", "src/baseenc.c", .unversioned);
+ dlib.linker_allow_shlib_undefined = true;
+ dlib.force_pic = true;
+ if (janet_headers) |h| dlib.addIncludeDir(h);
+ dlib.setBuildMode(mode);
+ dlib.addObject(obj);
+ dlib.linkSystemLibrary("pthread");
+ dlib.defineCMacro("JANET_BUILD_TYPE", "release");
+ dlib.install();
+
+ const main_tests = b.addTest("src/baseenc.zig");
+ main_tests.setBuildMode(mode);
+
+ const test_step = b.step("test", "Run library tests");
+ test_step.dependOn(&main_tests.step);
+}
A => project.janet +25 -0
@@ 0,0 1,25 @@
+(declare-project
+ :name "baseenc"
+ :description "base{64,32,16} encoding/decoding"
+ :version "1.0.0"
+ :dependencies [])
+
+(def- so-ext (if (= (os/which) :macos) "dylib" "so"))
+
+(rule "zig-out/lib/libbaseenc.a"
+ ["src/baseenc.c" "src/baseenc.zig"]
+ (shell "zig" "build" (string "-Djanet-headers=" (dyn :headerpath))))
+(add-output "zig-out/lib/libbaseenc.a" (string "zig-out/lib/libbaseenc." so-ext))
+(add-dep "build" "zig-out/lib/libbaseenc.a")
+
+(def- target (dyn :modpath))
+(task "install" []
+ (copyfile "zig-out/lib/libbaseenc.a" (string target "/baseenc.a"))
+ (copyfile (string "zig-out/lib/libbaseenc." so-ext)
+ (string target "/baseenc.so"))
+ (copyfile "baseenc.meta.janet" (string target "/baseenc.meta.janet")))
+
+(array/push (dyn :installed-files)
+ (string target "/baseenc.a")
+ (string target "/baseenc.so")
+ (string target "/baseenc.meta.janet"))
A => src/baseenc.c +9 -0
@@ 0,0 1,9 @@
+#include <janet.h>
+
+static const JanetReg Baseenc_cfuns[] = {
+ { NULL, NULL, NULL },
+};
+
+JANET_MODULE_ENTRY(JanetTable *env) {
+ janet_cfuns(env, "baseenc", &Baseenc_cfuns[0]);
+}
A => src/baseenc.zig +9 -0
@@ 0,0 1,9 @@
+const std = @import("std");
+
+export fn add(a: i32, b: i32) i32 {
+ return a + b;
+}
+
+test "basic add functionality" {
+ try std.testing.expect(add(3, 7) == 10);
+}