diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/editor.xml b/.idea/editor.xml
new file mode 100644
index 0000000..95d51a7
--- /dev/null
+++ b/.idea/editor.xml
@@ -0,0 +1,580 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/fastgltf-zig.iml b/.idea/fastgltf-zig.iml
new file mode 100644
index 0000000..bc2cd87
--- /dev/null
+++ b/.idea/fastgltf-zig.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..6d9f582
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/zigbrains.xml b/.idea/zigbrains.xml
new file mode 100644
index 0000000..c1e2dd4
--- /dev/null
+++ b/.idea/zigbrains.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.zig b/build.zig
index 0fab169..94755fa 100644
--- a/build.zig
+++ b/build.zig
@@ -3,7 +3,7 @@ const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
-pub fn build(b: *std.Build) void {
+pub fn build(b: *std.Build) !void {
const fastgltf_dep = b.dependency("fastgltf", .{});
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@@ -21,6 +21,9 @@ pub fn build(b: *std.Build) void {
const compile_target = if (compile_as_cpp20) "c++20" else "c++17";
const simdjson_dep = b.dependency("simdjson", .{});
+ const simdjson_evex512: ?*std.Build.Step.WriteFile = if (target.result.cpu.arch == .x86_64) try fix_evex512_simdjson(b, simdjson_dep) else null;
+ const simdjson_source_file_root = if (simdjson_evex512) |evex512| evex512.getDirectory() else simdjson_dep.path("singleheader");
+
const simdjson_lib = b.addStaticLibrary(.{
.name = "simdjson",
.target = target,
@@ -29,7 +32,7 @@ pub fn build(b: *std.Build) void {
});
simdjson_lib.linkLibCpp();
simdjson_lib.addCSourceFiles(.{
- .root = simdjson_dep.path("singleheader"),
+ .root = simdjson_source_file_root,
.files = &.{"simdjson.cpp"},
.flags = &.{
b.fmt("--std={s}", .{compile_target}),
@@ -37,6 +40,7 @@ pub fn build(b: *std.Build) void {
});
simdjson_lib.addIncludePath(simdjson_dep.path("singleheader"));
simdjson_lib.installHeadersDirectory(simdjson_dep.path("singleheader"), ".", .{ .include_extensions = &.{".h"} });
+ if (simdjson_evex512) |evex512| simdjson_lib.step.dependOn(&evex512.step);
b.installArtifact(simdjson_lib);
const fastgltf_lib: *std.Build.Step.Compile = switch (preferred_link_mode) {
@@ -88,3 +92,21 @@ pub fn build(b: *std.Build) void {
run.dependOn(&run_artifact.step);
// b.installArtifact(example);
}
+
+fn fix_evex512_simdjson(b: *std.Build, simdjson_dep: *std.Build.Dependency) !*std.Build.Step.WriteFile {
+ const original_file = try std.fs.openFileAbsolute(simdjson_dep.path(b.pathJoin(&.{ "singleheader", "simdjson.cpp" })).getPath(b), .{});
+ defer original_file.close();
+
+ const original_content = try original_file.readToEndAlloc(b.allocator, std.math.maxInt(usize));
+ defer b.allocator.free(original_content);
+ const edited_content = try std.mem.replaceOwned(
+ u8,
+ b.allocator,
+ original_content,
+ "SIMDJSON_TARGET_REGION(\"avx512f,avx512dq,avx512cd,avx512bw,avx512vbmi,avx512vbmi2,avx512vl,avx2,bmi,pclmul,lzcnt,popcnt\")",
+ "SIMDJSON_TARGET_REGION(\"avx512f,avx512dq,avx512cd,avx512bw,avx512vbmi,avx512vbmi2,avx512vl,avx2,bmi,pclmul,lzcnt,popcnt,evex512\")",
+ );
+ defer b.allocator.free(edited_content);
+
+ return b.addWriteFile("simdjson.cpp", edited_content);
+}