From f982f63723200e8974642063117c6f01bb6c1a73 Mon Sep 17 00:00:00 2001 From: Fathony Teguh Irawan Date: Sat, 23 May 2026 23:55:28 +0900 Subject: [PATCH 1/2] bump minimum Zig to 0.16, update README and build script --- .gitignore | 1 + README.md | 60 ++++++++++++++++++++++++++++++--------------------- build.zig | 28 ++++++++---------------- build.zig.zon | 2 +- 4 files changed, 47 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 8be35bd..726650e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ zig-cache/ .zig-cache/ zig-out/ +zig-pkg/ diff --git a/README.md b/README.md index 0a60947..53e6d7e 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,40 @@ # OpenAssetImporter Library Binding for Zig -This repo is a build sdk for [Assimp](https://github.com/assimp/assimp) to be used with the Zig build system: +This repo packages [Assimp](https://github.com/assimp/assimp) 5.3.1 for the Zig build system (requires Zig 0.16.0+). + +## Add the dependency + +```sh +zig fetch --save git+https://github.com/allyourcodebase/assimp.git +``` + +Or add it manually to `build.zig.zon`: + +```zig +.dependencies = .{ + .zig_assimp = .{ + .url = "https://github.com/allyourcodebase/assimp/archive/.tar.gz", + .hash = "...", + }, +}, +``` + +## Use it in `build.zig` ```zig -const std = @import("std"); - -// Import the SDK -const Assimp = @import("Sdk.zig"); - -pub fn build(b: *std.build.Builder) void { - const mode = b.standardReleaseOptions(); - - const exe = b.addExecutable("static-example", null); - exe.setBuildMode(mode); - exe.addCSourceFile("src/example.cpp", &[_][]const u8{"-std=c++17"}); - exe.linkLibC(); - exe.linkLibCpp(); - exe.install(); - - // Create a new instance - var sdk = Assimp.init(b); - - // And link Assimp statically to our exe and enable a default set of - // formats. - sdk.addTo(exe, .static, Assimp.FormatSet.default); -} -``` \ No newline at end of file +const assimp_dep = b.dependency("zig_assimp", .{ + .target = target, + .optimize = optimize, + .formats = @as([]const u8, "STL,Obj,FBX"), // or "all" + .double = false, +}); + +exe.linkLibrary(assimp_dep.artifact("assimp")); +``` + +Headers (including the generated `assimp/config.h`) are installed on the artifact, so `linkLibrary` is enough — no extra include paths needed. + +## Options + +- `formats` — comma-separated list of importers/exporters to compile, or `all`. Empty (default) builds none. See `build.zig` for the full list. +- `double` — store data as `double` instead of `float`. diff --git a/build.zig b/build.zig index 792c154..9f6168e 100644 --- a/build.zig +++ b/build.zig @@ -1,14 +1,4 @@ const std = @import("std"); -const builtin = @import("builtin"); - -const zig_version = builtin.zig_version; -fn lazy_from_path(path_chars: []const u8, owner: *std.Build) std.Build.LazyPath { - if (zig_version.major > 0 or zig_version.minor >= 13) { - return std.Build.LazyPath{ .src_path = .{ .sub_path = path_chars, .owner = owner } }; - } else if (zig_version.minor >= 12) { - return std.Build.LazyPath{ .path = path_chars }; - } else unreachable; -} pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); @@ -32,9 +22,9 @@ pub fn build(b: *std.Build) !void { lib.root_module.addCMacro("OPENDDL_STATIC_LIBARY", ""); } - lib.linkLibC(); + lib.root_module.link_libc = true; if (target.result.abi != .msvc) { - lib.linkLibCpp(); + lib.root_module.link_libcpp = true; } const config_h = b.addConfigHeader( @@ -46,7 +36,7 @@ pub fn build(b: *std.Build) !void { ); lib.root_module.addConfigHeader(config_h); lib.root_module.addIncludePath(assimp.path("include")); - lib.root_module.addIncludePath(lazy_from_path("include", b)); + lib.root_module.addIncludePath(b.path("include")); lib.root_module.addIncludePath(assimp.path("")); lib.root_module.addIncludePath(assimp.path("contrib")); @@ -67,7 +57,7 @@ pub fn build(b: *std.Build) !void { ); lib.installHeadersDirectory( - lazy_from_path("include", b), + b.path("include"), "", .{ .include_extensions = &.{ ".h", ".inl", ".hpp" } }, ); @@ -152,10 +142,10 @@ pub fn build(b: *std.Build) !void { .files = &[_][]const u8{"src/example.cpp"}, .flags = &[_][]const u8{"-std=c++17"}, }); - example_cpp.linkLibrary(lib); - example_cpp.linkLibC(); + example_cpp.root_module.linkLibrary(lib); + example_cpp.root_module.link_libc = true; if (target.result.abi != .msvc) { - example_cpp.linkLibCpp(); + example_cpp.root_module.link_libcpp = true; } example_cpp.root_module.addIncludePath(assimp.path("include")); if (target.result.os.tag == .windows) { @@ -175,8 +165,8 @@ pub fn build(b: *std.Build) !void { .files = &[_][]const u8{"src/example.c"}, .flags = &[_][]const u8{"-std=c99"}, }); - example_c.linkLibrary(lib); - example_c.linkLibC(); + example_c.root_module.linkLibrary(lib); + example_c.root_module.link_libc = true; example_c.root_module.addIncludePath(assimp.path("include")); if (target.result.os.tag == .windows) { example_c.root_module.addCMacro("_WINDOWS", ""); diff --git a/build.zig.zon b/build.zig.zon index fbd33e4..ad3df21 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,7 +10,7 @@ "include", "src", }, - .minimum_zig_version = "0.15.1", + .minimum_zig_version = "0.16.0", .dependencies = .{ .assimp = .{ .url = "https://github.com/assimp/assimp/archive/v5.3.1.tar.gz", From 72d9313b13f83001fa92d12e07f909f636325d3e Mon Sep 17 00:00:00 2001 From: Fathony Teguh Irawan Date: Sun, 24 May 2026 22:50:49 +0900 Subject: [PATCH 2/2] Update to 5.4.0 to fix the stb_image name conflict --- README.md | 2 +- build.zig | 1 + build.zig.zon | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 53e6d7e..1f5e3a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OpenAssetImporter Library Binding for Zig -This repo packages [Assimp](https://github.com/assimp/assimp) 5.3.1 for the Zig build system (requires Zig 0.16.0+). +This repo packages [Assimp](https://github.com/assimp/assimp) 5.4.0 for the Zig build system (requires Zig 0.16.0+). ## Add the dependency diff --git a/build.zig b/build.zig index 9f6168e..dcdaaf4 100644 --- a/build.zig +++ b/build.zig @@ -46,6 +46,7 @@ pub fn build(b: *std.Build) !void { lib.root_module.addIncludePath(assimp.path("contrib/unzip")); lib.root_module.addIncludePath(assimp.path("contrib/zlib")); lib.root_module.addIncludePath(assimp.path("contrib/openddlparser/include")); + lib.root_module.addIncludePath(assimp.path("contrib/utf8cpp/source")); lib.root_module.addCMacro("RAPIDJSON_HAS_STDSTRING", "1"); diff --git a/build.zig.zon b/build.zig.zon index ad3df21..11ab167 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = .zig_assimp, - .version = "5.3.1", + .version = "5.4.0", .fingerprint = 0x3e92a7cfbee36ef8, .paths = .{ "build.zig", @@ -13,8 +13,8 @@ .minimum_zig_version = "0.16.0", .dependencies = .{ .assimp = .{ - .url = "https://github.com/assimp/assimp/archive/v5.3.1.tar.gz", - .hash = "N-V-__8AACI1agiq-JJtHIb-h7Td-FFZ-HgD1WOpv1g_Vl3w", + .url = "https://github.com/assimp/assimp/archive/v5.4.0.tar.gz", + .hash = "N-V-__8AACoWewhH5OBlKGMhvR9XlApEzxGY07K8ZCn7TlH9", }, }, }