Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .agents/docs/2026-11-24-add-tinygltf-plan.md
Original file line number Diff line number Diff line change
@@ -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<ver>.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.
3 changes: 3 additions & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
83 changes: 83 additions & 0 deletions pkgs/c/compat.tinygltf.lua
Original file line number Diff line number Diff line change
@@ -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-<ver>/` 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" },
},
},
}
9 changes: 9 additions & 0 deletions tests/examples/tinygltf-nofs/mcpp.toml
Original file line number Diff line number Diff line change
@@ -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 = "../../.." }
66 changes: 66 additions & 0 deletions tests/examples/tinygltf-nofs/tests/test_tinygltf_nofs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <string>

#include <tiny_gltf_v3.h>

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<const uint8_t *>(kMinimalGltf),
static_cast<uint64_t>(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<int>(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;
}
9 changes: 9 additions & 0 deletions tests/examples/tinygltf-v301/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "tinygltf-v301-tests"
version = "0.1.0"

[dependencies.compat]
tinygltf = "3.0.1"

[indices]
compat = { path = "../../.." }
114 changes: 114 additions & 0 deletions tests/examples/tinygltf-v301/tests/test_tinygltf_v301.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <string>

#include <tiny_gltf_v3.h>

#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<const uint8_t *>(kTriangleGltf),
static_cast<uint64_t>(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<int>(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<int>(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<int>(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<uint32_t>(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<int>(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<int>(err));
return 1;
}

return 0;
}
9 changes: 9 additions & 0 deletions tests/examples/tinygltf/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "tinygltf-tests"
version = "0.1.0"

[dependencies.compat]
tinygltf = "3.1.0"

[indices]
compat = { path = "../../.." }
Loading
Loading