Skip to content

Commit

Permalink
build: expose simdjzon mod, use it in main and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
travisstaloch committed Oct 7, 2023
1 parent d3a3a5c commit 42ef696
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
17 changes: 8 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,21 @@ pub fn build(b: *std.build.Builder) void {
options.addOption(bool, "ondemand", ondemand);
options.addOption(u16, "ondemand_read_cap", ondemand_read_cap);
options.addOption(std.log.Level, "log_level", log_level);
const options_mod = options.createModule();

const lib = b.addStaticLibrary(.{
.name = "simdjzon",
.root_source_file = .{ .path = "src/simdjzon.zig" },
.target = target,
.optimize = optimize,
const mod = b.addModule("simdjzon", .{
.source_file = .{ .path = "src/simdjzon.zig" },
.dependencies = &.{
.{ .name = "build_options", .module = options_mod },
},
});
lib.addOptions("build_options", options);
b.installArtifact(lib);

var main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/tests.zig" },
.target = target,
.optimize = optimize,
});
main_tests.addOptions("build_options", options);
main_tests.addModule("simdjzon", mod);
// main_tests.setFilter("tape build 1");

const test_step = b.step("test", "Run tests");
Expand All @@ -62,7 +61,7 @@ pub fn build(b: *std.build.Builder) void {
.target = target,
.optimize = optimize,
});
exe.addOptions("build_options", options);
exe.addModule("simdjzon", mod);
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand Down
1 change: 0 additions & 1 deletion src/atom_parsing.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const std = @import("std");
const Iterator = @import("main.zig").Iterator;
const atom_rue = std.mem.readIntLittle(u24, "rue");
const atom_alse = std.mem.readIntLittle(u32, "alse");
const atom_ull = std.mem.readIntLittle(u24, "ull");
Expand Down
5 changes: 4 additions & 1 deletion src/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub const u8xstep_size = std.meta.Vector(STEP_SIZE, u8);
pub const STREAMING = false;
pub const SIMDJSON_PADDING = 32;

pub const log_level: std.log.Level = std.enums.nameCast(std.log.Level, @import("build_options").log_level);
pub const log_level: std.log.Level = std.enums.nameCast(std.log.Level, if (@hasDecl(root, "build_options"))
root.build_options.log_level
else
@import("build_options").log_level);
pub var debug = log_level == .debug;
pub fn println(comptime fmt: []const u8, args: anytype) void {
print(fmt ++ "\n", args);
Expand Down
6 changes: 3 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const build_options = @import("build_options");
const std = @import("std");

const os = std.os;
const common = @import("common.zig");
const simdjzon = @import("simdjzon.zig");
const simdjzon = @import("simdjzon");
pub const build_options = simdjzon.build_options;
const common = simdjzon.common;
const dom = simdjzon.dom;
const ondemand = simdjzon.ondemand;
pub const step_size = if (build_options.step_128) 128 else 64;
Expand Down
2 changes: 0 additions & 2 deletions src/number_parsing.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const mem = std.mem;
const main = @import("main.zig");
const CharUtils = @import("string_parsing.zig").CharUtils;
const dom = @import("dom.zig");
const Iterator = dom.Iterator;
Expand Down Expand Up @@ -67,7 +66,6 @@ pub fn parse_number(
try parse_exponent(src, &p, &exponent);
}
if (is_float) {
// main.println("is_float {c}", .{p[0]});
const dirty_end = CharUtils.is_not_structural_or_whitespace(p[0]);
try write_float(src, negative, i, start_digits, digit_count, exponent, tb);
if (dirty_end) {
Expand Down
2 changes: 2 additions & 0 deletions src/simdjzon.zig
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub const dom = @import("dom.zig");
pub const ondemand = @import("ondemand.zig");
pub const common = @import("common.zig");
pub const build_options = @import("build_options");
4 changes: 2 additions & 2 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const testing = std.testing;
const mem = std.mem;

const TapeType = dom.TapeType;
const simdjzon = @import("simdjzon.zig");
const simdjzon = @import("simdjzon");
const dom = simdjzon.dom;
const ondemand = simdjzon.ondemand;
const cmn = @import("common.zig");
const cmn = simdjzon.common;

const allr = testing.allocator;
test "tape build 1" {
Expand Down

0 comments on commit 42ef696

Please sign in to comment.