commit a2f5121a526ff0c28f5d8283dcb4e4d022208f07 Author: Aandreba Date: Wed Feb 19 12:08:23 2025 +0100 batman diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3389c86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache/ +zig-out/ diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..7018c64 --- /dev/null +++ b/build.zig @@ -0,0 +1,71 @@ +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 { + const fastgltf_dep = b.dependency("fastgltf", .{}); + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const preferred_link_mode = b.option( + std.builtin.LinkMode, + "preferred_link_mode", + "Prefer building fastgltf as a statically or dynamically linked library (default: static)", + ) orelse .static; + const use_custom_smallvec = b.option(bool, "FASTGLTF_USE_CUSTOM_SMALLVECTOR", "Uses a custom SmallVector type optimised for small arrays") orelse false; + const enable_deprecated_ext = b.option(bool, "FASTGLTF_ENABLE_DEPRECATED_EXT", "Enables support for deprecated extensions") orelse false; + const disable_custom_memory_pool = b.option(bool, "FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL", "Disables the memory allocation algorithm based on polymorphic resources") orelse false; + const use_64bit_float = b.option(bool, "FASTGLTF_USE_64BIT_FLOAT", "Default to 64-bit double precision floats for everything") orelse false; + const compile_as_cpp20 = b.option(bool, "FASTGLTF_COMPILE_AS_CPP20", "Have the library compile as C++20") orelse false; + const compile_target = if (compile_as_cpp20) "c++20" else "c++17"; + + const simdjson_dep = b.dependency("simdjson", .{}); + const simdjson_lib = b.addStaticLibrary(.{ + .name = "simdjson", + .target = target, + .optimize = optimize, + .link_libc = true, + }); + simdjson_lib.linkLibCpp(); + simdjson_lib.addCSourceFiles(.{ + .root = simdjson_dep.path("singleheader"), + .files = &.{"simdjson.cpp"}, + .flags = &.{ + b.fmt("--std={s}", .{compile_target}), + }, + }); + simdjson_lib.addIncludePath(simdjson_dep.path("singleheader")); + + const lib: *std.Build.Step.Compile = switch (preferred_link_mode) { + inline else => |x| switch (x) { + .static => std.Build.addStaticLibrary, + .dynamic => std.Build.addSharedLibrary, + }(b, .{ + .name = "fastgltf", + // .version = version, + .target = target, + .optimize = optimize, + .link_libc = true, + }), + }; + lib.linkLibCpp(); + lib.linkLibrary(simdjson_lib); + lib.addIncludePath(fastgltf_dep.path(b.pathJoin(&.{"include"}))); + lib.addIncludePath(simdjson_dep.path("include")); + lib.addCSourceFiles(.{ + .root = fastgltf_dep.path("."), + .files = &(.{ "src/fastgltf.cpp", "src/base64.cpp", "src/io.cpp" }), + .flags = &.{ + "-Wall", + "-Wno-unknown-pragmas", + b.fmt("--std={s}", .{compile_target}), + }, + }); + lib.root_module.addCMacro("FASTGLTF_USE_CUSTOM_SMALLVECTOR", if (use_custom_smallvec) "1" else "0"); + lib.root_module.addCMacro("FASTGLTF_ENABLE_DEPRECATED_EXT", if (enable_deprecated_ext) "1" else "0"); + lib.root_module.addCMacro("FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL", if (disable_custom_memory_pool) "1" else "0"); + lib.root_module.addCMacro("FASTGLTF_USE_64BIT_FLOAT", if (use_64bit_float) "1" else "0"); + + b.installArtifact(lib); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..050043b --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,43 @@ +.{ + // This is the default name used by packages depending on this one. For + // example, when a user runs `zig fetch --save `, this field is used + // as the key in the `dependencies` table. Although the user can choose a + // different name, most users will stick with this provided value. + // + // It is redundant to include "zig" in this name because it is already + // within the Zig package namespace. + .name = "fastgltf-zig", + + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.8.0", + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .fastgltf = .{ + .url = "git+https://github.com/spnda/fastgltf.git?ref=v0.8.0#d4734a7e55d8d25155e755d895e018e423845cd0", + .hash = "122073ceb7d605132a92a1323b5f7661789ead3062f844a89c7f5d3cefdf47a1172d", + }, + .simdjson = .{ + .url = "git+https://github.com/simdjson/simdjson.git?ref=v3.11.6#1b23a77e0348aa212290e8acc5b1c509fb2a978e", + .hash = "1220a00b057c19c88d57eb5b623a1618bafd101296188b726d444b6b4d512c1d2f52", + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + // For example... + //"LICENSE", + //"README.md", + }, +}