Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Export a C library #4

Merged
merged 6 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ pub fn build(b: *std.Build) void {
},
});

// Static Library
const lib = b.addStaticLibrary(.{
.name = "fastlanez",
.target = target,
.optimize = optimize,
.root_source_file = .{ .path = "src/lib.zig" },
});
b.installArtifact(lib);
// Ideally we would use dlib.getEmittedH(), but https://github.com/ziglang/zig/issues/18497
const lib_header = b.addInstallFile(.{ .path = "zig-cache/fastlanez.h" }, "include/fastlanez.h");
b.getInstallStep().dependOn(&lib_header.step);

// Unit Tests
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/fastlanez.zig" },
Expand Down
31 changes: 31 additions & 0 deletions src/lib.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! The C library for FastLanez.
const fl = @import("./fastlanez.zig");
const std = @import("std");

// BitPacking
comptime {
const BitPacking = @import("./bitpacking.zig").BitPacking;
for (.{u8}) |E| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be missing things

const FL = fl.FastLanez(E);

for (1..@bitSizeOf(E)) |W| {
// TODO(ngates): configure this in build.zig
const dbg = @import("builtin").mode == .Debug;
if (dbg and !std.math.isPowerOfTwo(W)) {
// Avoid too much code-gen in debug mode.
continue;
}

const Wrapper = struct {
fn encode(in: *const FL.Vector, out: *FL.PackedBytes(W)) callconv(.C) void {
@call(.always_inline, BitPacking(FL).encode, .{ W, in, out });
}
};

@export(Wrapper.encode, .{
.name = "bitpack_" ++ @typeName(E) ++ "_" ++ @typeName(std.meta.Int(.unsigned, W)),
.linkage = .Strong,
});
}
}
}
Loading