Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
22 changes: 13 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,28 @@ pub fn build(b: *std.Build) !void {

// Build static library by default
const c_entry = b.path("src/c-api.zig");
const static_lib = b.addStaticLibrary(.{
.name = name,
const c_module = b.addModule("plotille-c", .{
.root_source_file = c_entry,
.target = target,
.optimize = mode,
.version = version,
.strip = strip,
});
const static_lib = b.addLibrary(.{
.name = name,
.root_module = c_module,
.version = version,
.linkage = .static,
});
static_lib.linkLibC();
const installed_static_lib = b.addInstallArtifact(static_lib, .{});
b.getInstallStep().dependOn(&installed_static_lib.step);

// Build dynamic library by default (unless static-only is requested)
const shared_lib = b.addSharedLibrary(.{
const shared_lib = b.addLibrary(.{
.name = name,
.root_source_file = c_entry,
.target = target,
.optimize = mode,
.root_module = c_module,
.version = version,
.strip = strip,
.linkage = .dynamic,
});
shared_lib.linkLibC();
const installed_shared_lib = b.addInstallArtifact(shared_lib, .{});
Expand All @@ -56,8 +58,10 @@ pub fn build(b: *std.Build) !void {
const tests = b.addTest(.{
.name = name,
.root_module = module,
.filter = filter,
});
if (filter) |f| {
tests.filters = &.{f};
}
const run_tests = b.addRunArtifact(tests);
test_step.dependOn(&run_tests.step);
}
10 changes: 5 additions & 5 deletions src/c-api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export fn dots_init() dots.Dots {
}
export fn dots_str(self: dots.Dots, buf: [*]u8, len: usize) usize {
var fbs = std.io.fixedBufferStream(buf[0..len]);
std.fmt.format(fbs.writer(), "{s}", .{self}) catch |err| switch (err) {
std.fmt.format(fbs.writer(), "{f}", .{self}) catch |err| switch (err) {
error.NoSpaceLeft => return 0,
};
return fbs.pos;
Expand Down Expand Up @@ -116,7 +116,7 @@ export fn hist_free(h: *CHistogram) void {

if (h._internal) |internal| {
const hist_ptr: *hist.Histogram = @ptrCast(@alignCast(internal));
hist_ptr.deinit();
hist_ptr.deinit(allocator);
allocator.destroy(hist_ptr);
}

Expand All @@ -128,7 +128,7 @@ export fn hist_str(h: CHistogram, buf: [*]u8, len: usize) usize {
if (h._internal) |internal| {
const hist_ptr: *const hist.Histogram = @ptrCast(@alignCast(internal));
var fbs = std.io.fixedBufferStream(buf[0..len]);
std.fmt.format(fbs.writer(), "{}", .{hist_ptr.*}) catch return 0;
std.fmt.format(fbs.writer(), "{f}", .{hist_ptr.*}) catch return 0;
return fbs.pos;
}
return 0;
Expand Down Expand Up @@ -247,7 +247,7 @@ export fn canvas_str(c: CCanvas, buf: [*]u8, len: usize) usize {
if (c._internal) |internal| {
const canvas_ptr: *const canvas.Canvas = @ptrCast(@alignCast(internal));
var fbs = std.io.fixedBufferStream(buf[0..len]);
std.fmt.format(fbs.writer(), "{}", .{canvas_ptr.*}) catch return 0;
std.fmt.format(fbs.writer(), "{f}", .{canvas_ptr.*}) catch return 0;
return fbs.pos;
}
return 0;
Expand Down Expand Up @@ -461,7 +461,7 @@ export fn figure_str(f: CFigure, buf: [*]u8, len: usize) usize {
if (f._internal) |internal| {
const figure_ptr: *const figure.Figure = @ptrCast(@alignCast(internal));
var fbs = std.io.fixedBufferStream(buf[0..len]);
std.fmt.format(fbs.writer(), "{}", .{figure_ptr.*}) catch return 0;
std.fmt.format(fbs.writer(), "{f}", .{figure_ptr.*}) catch return 0;
return fbs.pos;
}
return 0;
Expand Down
Loading
Loading