diff --git a/.agents/docs/2026-11-24-add-tinygltf-plan.md b/.agents/docs/2026-11-24-add-tinygltf-plan.md new file mode 100644 index 00000000..df50b2a7 --- /dev/null +++ b/.agents/docs/2026-11-24-add-tinygltf-plan.md @@ -0,0 +1,42 @@ +# Add `compat.tinygltf` (`syoyo/tinygltf` v3.0.1 & v3.1.0) + +## Summary + +Add `compat.tinygltf` (`pkgs/c/compat.tinygltf.lua`) wrapping `syoyo/tinygltf` v3 at release versions `3.0.1` and `3.1.0` (MIT license) in its own branch off `upstream/main`. + +## Package Architecture + +- **Identity & Versioning**: + - Adapted from a local `pf.tinygltf` (`3.0.1+pf.1`) draft to `compat.tinygltf` (`namespace = "compat"`, `name = "tinygltf"`) with bare upstream versions `"3.0.1"` and `"3.1.0"` so it follows `mcpp-index` conventions for third-party C/C++ compat packages and satisfies `xpkgindex-update` ordered-release checks. +- **Upstream Archive & Source Layout**: + - Plain upstream GitHub tag archives (`https://github.com/syoyo/tinygltf/archive/refs/tags/v.tar.gz`) are used across `linux`, `macosx`, and `windows` (no local `gitcode` `mcpp-res` credentials available; CN mirrors can be added by maintainers later). + - SHA256 verified twice for stability: + - `3.0.1`: `b7e953f13a30d7b6fd677e484de35febde954143a265da15dacd92ed171c73e6` + - `3.1.0`: `6e3043d1353d31daa4a06b17606bc9f4c46bf8f047bddffe1a63a6a79446182e` + - Three-file archive root layout (`tiny_gltf_v3.h`, `tiny_gltf_v3.c`, `tinygltf_json_c.h`), built as C11 (`c_standard = "c11"`, `sources = { "*/tiny_gltf_v3.c" }`, `include_dirs = { "*" }`, `license_files = { "*/LICENSE" }`). + - `windows.cflags = { "-D_CRT_SECURE_NO_WARNINGS" }` silences MSVC CRT deprecation warnings on `fopen`. +- **Feature Design**: + - `features.default = { implies = { "fs" } }` + - `features.fs = { defines = { "TINYGLTF3_ENABLE_FS" } }` + - Enabled by default so `tg3_parse_file` and `tg3_write_to_file` use stdio out of the box, while consumers opting out via `default-features = false` compile without stdio filesystem helpers (`TINYGLTF3_ENABLE_FS` omitted). +- **Automatic Updates**: + - `extensions.autoupdate` tracks `syoyo/tinygltf` releases with `tag = "v${version}"` and `url = "https://github.com/syoyo/tinygltf/archive/refs/tags/${tag}.tar.gz"`. + +## Workspace Test Members + +1. `tests/examples/tinygltf` (`compat.tinygltf = "3.1.0"`): + - Compile-time check for `TG3_GLTF21_UNSTABLE` (confirms `3.1.0+` header resolution). + - Verifies in-memory glTF 2.0 JSON parse (`tg3_parse`), decoded vertex float payload, binary GLB round-trip (`tg3_write_to_memory` + `tg3_parse_auto`), stdio file write/read (`tg3_write_to_file` + `tinygltf3::parse_file`), and out-of-range index validation (`TG3_ERR_INVALID_INDEX`). +2. `tests/examples/tinygltf-v301` (`compat.tinygltf = "3.0.1"`): + - Compile-time check `#ifdef TG3_GLTF21_UNSTABLE #error ...` (confirms `3.0.1` header resolution). + - Verifies in-memory glTF 2.0 parse, GLB round-trip, and stdio file write/read. +3. `tests/examples/tinygltf-nofs` (`compat.tinygltf = { version = "3.1.0", default-features = false }`): + - Negative feature check: confirms in-memory `tg3_parse` succeeds while `tinygltf3::parse_file` without custom callbacks fails because `TINYGLTF3_ENABLE_FS` is not defined. + +## Local Verification (`mcpp 2026.11.23.1`) + +- Repo lints (`check_mirror_urls.lua`, `check_package_name.lua`, `check_reserved_namespace.lua`, `check_mplugin_layout.lua`, `check_cross_package_refs.lua`, `check_platform_version_parity.lua`, `check_duplicate_versions.lua`, `check_capability_providers.lua`, `check_quill_install.lua`, `tools/platform_rows.py check`, `test_check_mplugin.py`, `test_check_capability_providers.py`, `tests/openkal/compat.py selftest`, `tests/red_members.py selftest`) and `mcpp xpkg parse` across all descriptors passed (`compat.tinygltf`: `versions linux/macosx/windows 3.0.1, 3.1.0`, `features 2`, `parse OK`). +- Cold `MCPP_HOME` `tests/run_members.sh tinygltf tinygltf-v301 tinygltf-nofs` passed under both GCC (`gcc@16.2.0`) and LLVM (`llvm@23.1.6`). +- Verified `compile_commands.json` passes `-std=c11` and `-DTINYGLTF3_ENABLE_FS` for default consumers and omits `-DTINYGLTF3_ENABLE_FS` for `tinygltf-nofs`. +- `tests/select_members.py --base upstream/main pkgs/c/compat.tinygltf.lua` selected `tinygltf tinygltf-v301 tinygltf-nofs`. +- `xpkgindex_update` unit tests (26 + 4 passed), `tests/autoupdate/ci.py audit --base upstream/main` (`111` updateable descriptors), `inspect`, and `check --package compat:tinygltf` (`up-to-date`, `current: "3.1.0"`) all passed. diff --git a/mcpp.toml b/mcpp.toml index 09c7a84b..13528b5f 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -251,6 +251,9 @@ members = [ "tests/examples/websocket-tls", "tests/examples/wolfssl", "tests/examples/tl-optional", + "tests/examples/tinygltf", + "tests/examples/tinygltf-v301", + "tests/examples/tinygltf-nofs", "tests/examples/tray", "tests/examples/xsimd", "tests/examples/wuffs", diff --git a/pkgs/c/compat.tinygltf.lua b/pkgs/c/compat.tinygltf.lua new file mode 100644 index 00000000..ef16dedc --- /dev/null +++ b/pkgs/c/compat.tinygltf.lua @@ -0,0 +1,83 @@ +-- compat.tinygltf — syoyo/tinygltf v3 C11-first glTF 2.0 loader and writer. +-- Three-file archive root layout: tiny_gltf_v3.h, tiny_gltf_v3.c, and +-- tinygltf_json_c.h. `default` implies `fs` (defines TINYGLTF3_ENABLE_FS so +-- tg3_parse_file / tg3_write_to_file use stdio); consumers passing +-- `default-features = false` compile out stdio filesystem helpers. +-- +-- All `mcpp` paths are GLOBS relative to the verdir; the leading `*/` +-- absorbs the GitHub tarball's `tinygltf-/` wrap layer. +-- Plain upstream URLs are used here because no local gitcode `mcpp-res` +-- credentials are available; CN mirrors can be added by maintainers later. +package = { + spec = "1", + namespace = "compat", + name = "tinygltf", + description = "tinygltf v3 — C11-first glTF 2.0 loader and writer (POD API, arena allocator)", + licenses = {"MIT"}, + repo = "https://github.com/syoyo/tinygltf", + type = "package", + + extensions = { + autoupdate = { + tag = "v${version}", + url = "https://github.com/syoyo/tinygltf/archive/refs/tags/${tag}.tar.gz", + }, + }, + + xpm = { + linux = { + ["3.0.1"] = { + url = "https://github.com/syoyo/tinygltf/archive/refs/tags/v3.0.1.tar.gz", + sha256 = "b7e953f13a30d7b6fd677e484de35febde954143a265da15dacd92ed171c73e6", + }, + ["3.1.0"] = { + url = "https://github.com/syoyo/tinygltf/archive/refs/tags/v3.1.0.tar.gz", + sha256 = "6e3043d1353d31daa4a06b17606bc9f4c46bf8f047bddffe1a63a6a79446182e", + }, + }, + macosx = { + ["3.0.1"] = { + url = "https://github.com/syoyo/tinygltf/archive/refs/tags/v3.0.1.tar.gz", + sha256 = "b7e953f13a30d7b6fd677e484de35febde954143a265da15dacd92ed171c73e6", + }, + ["3.1.0"] = { + url = "https://github.com/syoyo/tinygltf/archive/refs/tags/v3.1.0.tar.gz", + sha256 = "6e3043d1353d31daa4a06b17606bc9f4c46bf8f047bddffe1a63a6a79446182e", + }, + }, + windows = { + ["3.0.1"] = { + url = "https://github.com/syoyo/tinygltf/archive/refs/tags/v3.0.1.tar.gz", + sha256 = "b7e953f13a30d7b6fd677e484de35febde954143a265da15dacd92ed171c73e6", + }, + ["3.1.0"] = { + url = "https://github.com/syoyo/tinygltf/archive/refs/tags/v3.1.0.tar.gz", + sha256 = "6e3043d1353d31daa4a06b17606bc9f4c46bf8f047bddffe1a63a6a79446182e", + }, + }, + }, + + mcpp = { + language = "c++23", + import_std = false, + c_standard = "c11", + license_files = { "*/LICENSE" }, + include_dirs = { "*" }, + sources = { "*/tiny_gltf_v3.c" }, + targets = { ["tinygltf"] = { kind = "lib" } }, + deps = {}, + + features = { + ["default"] = { + implies = { "fs" }, + }, + ["fs"] = { + defines = { "TINYGLTF3_ENABLE_FS" }, + }, + }, + + windows = { + cflags = { "-D_CRT_SECURE_NO_WARNINGS" }, + }, + }, +} diff --git a/tests/examples/tinygltf-nofs/mcpp.toml b/tests/examples/tinygltf-nofs/mcpp.toml new file mode 100644 index 00000000..058c1fb8 --- /dev/null +++ b/tests/examples/tinygltf-nofs/mcpp.toml @@ -0,0 +1,9 @@ +[package] +name = "tinygltf-nofs-tests" +version = "0.1.0" + +[dependencies.compat] +tinygltf = { version = "3.1.0", default-features = false } + +[indices] +compat = { path = "../../.." } diff --git a/tests/examples/tinygltf-nofs/tests/test_tinygltf_nofs.cpp b/tests/examples/tinygltf-nofs/tests/test_tinygltf_nofs.cpp new file mode 100644 index 00000000..ac26904a --- /dev/null +++ b/tests/examples/tinygltf-nofs/tests/test_tinygltf_nofs.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +#include + +static const char *kMinimalGltf = R"({ + "asset": { "version": "2.0" }, + "scenes": [ { "nodes": [] } ] +})"; + +int main() { + // 1. In-memory parse still works with `default-features = false`. + tinygltf3::Model mem_model; + tinygltf3::ErrorStack mem_errors; + tg3_parse_options opts; + tg3_parse_options_init(&opts); + + tg3_error_code err = tg3_parse( + mem_model.get(), mem_errors.get(), + reinterpret_cast(kMinimalGltf), + static_cast(std::strlen(kMinimalGltf)), + "", 0, &opts); + if (err != TG3_OK || mem_errors.has_error() || + tg3_str_equals_cstr(mem_model->asset.version, "2.0") == 0) { + std::fprintf(stderr, "in-memory tg3_parse failed: err=%d\n", static_cast(err)); + return 1; + } + + // 2. Negative check: without `fs` (TINYGLTF3_ENABLE_FS), tg3_parse_file + // without custom fs callbacks must fail even on an existing valid file. + const std::filesystem::path tmp_path = + std::filesystem::temp_directory_path() / "mcpp_tinygltf_nofs_test.gltf"; + const std::string tmp_str = tmp_path.string(); + { + FILE *fp = std::fopen(tmp_str.c_str(), "wb"); + if (!fp) { + std::fprintf(stderr, "failed to create temp file\n"); + return 1; + } + const std::size_t len = std::strlen(kMinimalGltf); + const std::size_t written = std::fwrite(kMinimalGltf, 1, len, fp); + std::fclose(fp); + if (written != len) { + std::error_code ec; + std::filesystem::remove(tmp_path, ec); + std::fprintf(stderr, "short write to temp file\n"); + return 1; + } + } + + tinygltf3::Model file_model; + tinygltf3::ErrorStack file_errors; + err = tinygltf3::parse_file(file_model, file_errors, tmp_str.c_str(), &opts); + std::error_code ec; + std::filesystem::remove(tmp_path, ec); + + if (err == TG3_OK || !file_errors.has_error()) { + std::fprintf(stderr, + "expected tg3_parse_file to fail when TINYGLTF3_ENABLE_FS is disabled\n"); + return 1; + } + + return 0; +} diff --git a/tests/examples/tinygltf-v301/mcpp.toml b/tests/examples/tinygltf-v301/mcpp.toml new file mode 100644 index 00000000..227a173c --- /dev/null +++ b/tests/examples/tinygltf-v301/mcpp.toml @@ -0,0 +1,9 @@ +[package] +name = "tinygltf-v301-tests" +version = "0.1.0" + +[dependencies.compat] +tinygltf = "3.0.1" + +[indices] +compat = { path = "../../.." } diff --git a/tests/examples/tinygltf-v301/tests/test_tinygltf_v301.cpp b/tests/examples/tinygltf-v301/tests/test_tinygltf_v301.cpp new file mode 100644 index 00000000..a26f1921 --- /dev/null +++ b/tests/examples/tinygltf-v301/tests/test_tinygltf_v301.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include + +#include + +#ifdef TG3_GLTF21_UNSTABLE +#error "expected tinygltf 3.0.1 headers (unexpected TG3_GLTF21_UNSTABLE from 3.1.0+)" +#endif + +static const char *kTriangleGltf = R"({ + "asset": { "version": "2.0", "generator": "mcpp-tinygltf-v301-test" }, + "scene": 0, + "scenes": [ { "nodes": [ 0 ] } ], + "nodes": [ { "mesh": 0, "name": "tri" } ], + "meshes": [ { + "primitives": [ { + "attributes": { "POSITION": 0 }, + "mode": 4 + } ] + } ], + "buffers": [ { + "uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAA", + "byteLength": 36 + } ], + "bufferViews": [ { + "buffer": 0, + "byteOffset": 0, + "byteLength": 36 + } ], + "accessors": [ { + "bufferView": 0, + "componentType": 5126, + "count": 3, + "type": "VEC3" + } ] +})"; + +int main() { + tinygltf3::Model model; + tinygltf3::ErrorStack errors; + tg3_parse_options opts; + tg3_parse_options_init(&opts); + + tg3_error_code err = tg3_parse( + model.get(), errors.get(), + reinterpret_cast(kTriangleGltf), + static_cast(std::strlen(kTriangleGltf)), + "", 0, &opts); + if (err != TG3_OK || errors.has_error() || + tg3_str_equals_cstr(model->asset.version, "2.0") == 0 || + model->meshes_count != 1 || model->buffers_count != 1 || + model->buffers[0].data.count != 36) { + std::fprintf(stderr, "3.0.1 tg3_parse failed: err=%d\n", static_cast(err)); + return 1; + } + + // GLB round-trip + tg3_write_options wopts; + tg3_write_options_init(&wopts); + wopts.write_binary = 1; + wopts.embed_buffers = 1; + + uint8_t *glb_data = nullptr; + uint64_t glb_size = 0; + tinygltf3::ErrorStack werrors; + err = tg3_write_to_memory(model.get(), werrors.get(), &glb_data, &glb_size, &wopts); + if (err != TG3_OK || !glb_data || glb_size < 12 || std::memcmp(glb_data, "glTF", 4) != 0) { + std::fprintf(stderr, "3.0.1 tg3_write_to_memory failed: err=%d\n", static_cast(err)); + if (glb_data) tg3_write_free(glb_data, &wopts); + return 1; + } + + tinygltf3::Model glb_model; + tinygltf3::ErrorStack glb_errors; + err = tg3_parse_auto(glb_model.get(), glb_errors.get(), glb_data, glb_size, "", 0, &opts); + tg3_write_free(glb_data, &wopts); + if (err != TG3_OK || glb_errors.has_error() || glb_model->meshes_count != 1) { + std::fprintf(stderr, "3.0.1 GLB round-trip failed: err=%d\n", static_cast(err)); + return 1; + } + + // Filesystem I/O via default `fs` feature + const std::filesystem::path tmp_path = + std::filesystem::temp_directory_path() / "mcpp_tinygltf_v301_test.gltf"; + const std::string tmp_str = tmp_path.string(); + std::error_code ec; + std::filesystem::remove(tmp_path, ec); + + tg3_write_options fopts; + tg3_write_options_init(&fopts); + fopts.embed_buffers = 1; + tinygltf3::ErrorStack fwerrors; + err = tg3_write_to_file( + model.get(), fwerrors.get(), + tmp_str.c_str(), static_cast(tmp_str.size()), &fopts); + if (err != TG3_OK) { + std::filesystem::remove(tmp_path, ec); + std::fprintf(stderr, "3.0.1 tg3_write_to_file failed: err=%d\n", static_cast(err)); + return 1; + } + + tinygltf3::Model file_model; + tinygltf3::ErrorStack file_errors; + err = tinygltf3::parse_file(file_model, file_errors, tmp_str.c_str(), &opts); + std::filesystem::remove(tmp_path, ec); + if (err != TG3_OK || file_errors.has_error() || file_model->meshes_count != 1) { + std::fprintf(stderr, "3.0.1 parse_file failed: err=%d\n", static_cast(err)); + return 1; + } + + return 0; +} diff --git a/tests/examples/tinygltf/mcpp.toml b/tests/examples/tinygltf/mcpp.toml new file mode 100644 index 00000000..403cf93d --- /dev/null +++ b/tests/examples/tinygltf/mcpp.toml @@ -0,0 +1,9 @@ +[package] +name = "tinygltf-tests" +version = "0.1.0" + +[dependencies.compat] +tinygltf = "3.1.0" + +[indices] +compat = { path = "../../.." } diff --git a/tests/examples/tinygltf/tests/test_tinygltf.cpp b/tests/examples/tinygltf/tests/test_tinygltf.cpp new file mode 100644 index 00000000..52d3b539 --- /dev/null +++ b/tests/examples/tinygltf/tests/test_tinygltf.cpp @@ -0,0 +1,156 @@ +#include +#include +#include +#include +#include + +#include + +#ifndef TG3_GLTF21_UNSTABLE +#error "expected tinygltf 3.1.0+ headers (missing TG3_GLTF21_UNSTABLE)" +#endif + +static const char *kTriangleGltf = R"({ + "asset": { "version": "2.0", "generator": "mcpp-tinygltf-test" }, + "scene": 0, + "scenes": [ { "nodes": [ 0 ] } ], + "nodes": [ { "mesh": 0, "name": "tri" } ], + "meshes": [ { + "primitives": [ { + "attributes": { "POSITION": 0 }, + "mode": 4 + } ] + } ], + "buffers": [ { + "uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAA", + "byteLength": 36 + } ], + "bufferViews": [ { + "buffer": 0, + "byteOffset": 0, + "byteLength": 36 + } ], + "accessors": [ { + "bufferView": 0, + "componentType": 5126, + "count": 3, + "type": "VEC3", + "min": [ 0.0, 0.0, 0.0 ], + "max": [ 1.0, 1.0, 0.0 ] + } ] +})"; + +int main() { + bool ok = true; + + // 1. In-memory JSON parse + decoded buffer verification + tinygltf3::Model model; + tinygltf3::ErrorStack errors; + tg3_parse_options opts; + tg3_parse_options_init(&opts); + + tg3_error_code err = tg3_parse( + model.get(), errors.get(), + reinterpret_cast(kTriangleGltf), + static_cast(std::strlen(kTriangleGltf)), + "", 0, &opts); + if (err != TG3_OK || errors.has_error()) { + std::fprintf(stderr, "tg3_parse failed: err=%d\n", static_cast(err)); + return 1; + } + + ok = ok && tg3_str_equals_cstr(model->asset.version, "2.0") != 0; + ok = ok && model->buffers_count == 1; + ok = ok && model->buffers[0].data.count == 36; + ok = ok && model->meshes_count == 1; + ok = ok && model->meshes[0].primitives_count == 1; + ok = ok && model->nodes_count == 1; + ok = ok && model->scenes_count == 1; + ok = ok && model->default_scene == 0; + if (!ok) { + std::fprintf(stderr, "unexpected parsed model structure\n"); + return 1; + } + + float verts[9] = {}; + std::memcpy(verts, model->buffers[0].data.data, sizeof(verts)); + const float expected[9] = {0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}; + for (int i = 0; i < 9; ++i) { + if (std::fabs(verts[i] - expected[i]) > 1e-6f) { + std::fprintf(stderr, "vertex mismatch at %d: %f vs %f\n", i, verts[i], expected[i]); + return 1; + } + } + + // 2. GLB write-to-memory + parse_auto round-trip + tg3_write_options wopts; + tg3_write_options_init(&wopts); + wopts.write_binary = 1; + wopts.embed_buffers = 1; + + uint8_t *glb_data = nullptr; + uint64_t glb_size = 0; + tinygltf3::ErrorStack werrors; + err = tg3_write_to_memory(model.get(), werrors.get(), &glb_data, &glb_size, &wopts); + if (err != TG3_OK || !glb_data || glb_size < 12 || std::memcmp(glb_data, "glTF", 4) != 0) { + std::fprintf(stderr, "tg3_write_to_memory failed: err=%d size=%llu\n", + static_cast(err), static_cast(glb_size)); + if (glb_data) tg3_write_free(glb_data, &wopts); + return 1; + } + + tinygltf3::Model glb_model; + tinygltf3::ErrorStack glb_errors; + err = tg3_parse_auto(glb_model.get(), glb_errors.get(), glb_data, glb_size, "", 0, &opts); + tg3_write_free(glb_data, &wopts); + if (err != TG3_OK || glb_errors.has_error() || + glb_model->meshes_count != 1 || glb_model->buffers_count != 1) { + std::fprintf(stderr, "GLB round-trip parse failed: err=%d\n", static_cast(err)); + return 1; + } + + // 3. Filesystem I/O via default `fs` feature (TINYGLTF3_ENABLE_FS) + const std::filesystem::path tmp_path = + std::filesystem::temp_directory_path() / "mcpp_tinygltf_v310_test.gltf"; + const std::string tmp_str = tmp_path.string(); + std::error_code ec; + std::filesystem::remove(tmp_path, ec); + + tg3_write_options fopts; + tg3_write_options_init(&fopts); + fopts.embed_buffers = 1; + tinygltf3::ErrorStack fwerrors; + err = tg3_write_to_file( + model.get(), fwerrors.get(), + tmp_str.c_str(), static_cast(tmp_str.size()), &fopts); + if (err != TG3_OK) { + std::filesystem::remove(tmp_path, ec); + std::fprintf(stderr, "tg3_write_to_file failed: err=%d\n", static_cast(err)); + return 1; + } + + tinygltf3::Model file_model; + tinygltf3::ErrorStack file_errors; + err = tinygltf3::parse_file(file_model, file_errors, tmp_str.c_str(), &opts); + std::filesystem::remove(tmp_path, ec); + if (err != TG3_OK || file_errors.has_error() || file_model->meshes_count != 1) { + std::fprintf(stderr, "tinygltf3::parse_file failed: err=%d\n", static_cast(err)); + return 1; + } + + // 4. Out-of-range index rejection (validate_indices default-on) + const char *bad_gltf = R"({"asset":{"version":"2.0"},"nodes":[{"mesh":99}]})"; + tinygltf3::Model bad_model; + tinygltf3::ErrorStack bad_errors; + err = tg3_parse( + bad_model.get(), bad_errors.get(), + reinterpret_cast(bad_gltf), + static_cast(std::strlen(bad_gltf)), + "", 0, &opts); + if (err != TG3_ERR_INVALID_INDEX || !bad_errors.has_error()) { + std::fprintf(stderr, "expected TG3_ERR_INVALID_INDEX, got %d\n", static_cast(err)); + return 1; + } + + return ok ? 0 : 1; +}