Skip to content

Commit

Permalink
Update to newest build system
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhear committed Feb 6, 2023
1 parent abc92eb commit c1ce052
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This library implements Zig bindings for the [CRoaring library](https://github.c
## Naming
Any C function that begins with `roaring_bitmap_` is a method of the `Bitmap` struct, e.g. `roaring_bitmap_add` becomes `Bitmap.add`. Because `and` and `or` are Zig keywords, the bitwise operators `and`, `or`, and `xor` are consistently prefixed with an underscore, e.g. `Bitmap._or` and `Bitmap._orCardinality`. All functions have been renamed to Zig's naming convention (camel-case).

## std.Build breaking changes
On January 31st, [this pull request](https://github.com/ziglang/zig/pull/14498) introduced breaking changes to the zig build system. If you are **not** using a Zig daily build from after that point, you will need to checkout the `og_build` tag which uses the old build system.

## Adding with zigmod
If you're using the zigmod dependency manager, you can add roaring-zig to your project by adding it as a dependency in your zigmod.yml file:

Expand Down
32 changes: 21 additions & 11 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
const std = @import("std");
const Builder = std.build.Builder;
const CrossTarget = std.zig.CrossTarget;

pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
var lib = add(b, mode);
var lib = add(b, target, optimize);
lib.install();

var main_tests = b.addTest("src/test.zig");
main_tests.setBuildMode(mode);
var main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/test.zig" },
});
main_tests.linkLibrary(lib);
main_tests.addIncludePath("croaring");

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);

var example = b.addExecutable("example", "src/example.zig");
example.setBuildMode(mode);
var example = b.addExecutable(.{
.name = "example",
.root_source_file = .{ .path = "src/example.zig" },
.target = target,
.optimize = optimize,
});
example.linkLibrary(lib);
example.addIncludePath("croaring");

Expand All @@ -28,9 +34,13 @@ pub fn build(b: *Builder) void {
}

/// Add Roaring Bitmaps to your build process
pub fn add(b: *Builder, mode: std.builtin.Mode) *std.build.LibExeObjStep {
var lib = b.addStaticLibrary("roaring-zig", "src/roaring.zig");
lib.setBuildMode(mode);
pub fn add(b: *std.Build, target: CrossTarget, optimize: std.builtin.Mode) *std.build.LibExeObjStep {
var lib = b.addStaticLibrary(.{
.name = "roaring-zig",
.root_source_file = .{ .path = "src/roaring.zig" },
.target = target,
.optimize = optimize,
});
lib.linkLibC();
lib.addCSourceFile("croaring/roaring.c", &[_][]const u8{""});
lib.addIncludePath("croaring");
Expand Down

0 comments on commit c1ce052

Please sign in to comment.