From 676cb9e8125b744dd4ba2c66b203908007b7cb07 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 1 Dec 2026 07:33:26 +0800 Subject: [PATCH 1/2] fix: the hash groups are sub-modules, as the README and the mwrap spec name them (mwrap-3.6.8.1) Until now each group was a partition of the root (mcpplibs.mwrap.mbedtls:sha256), so the README's `import mcpplibs.mwrap.mbedtls.sha256;` did not compile: an importer could only take the root. Each group is now its own module and the root re-exports the six; tests/submodule_test.cpp imports sha256 alone. A consumer met this combining the wrap with the first real use (xgit). --- .tmp_tt.py | 92 ---------------------------------------- mcpp.toml | 4 +- src/mbedtls.cppm | 16 ++++--- src/md.cppm | 2 +- src/md5.cppm | 2 +- src/sha1.cppm | 2 +- src/sha256.cppm | 2 +- src/sha3.cppm | 2 +- src/sha512.cppm | 2 +- tests/submodule_test.cpp | 46 ++++++++++++++++++++ tools/generate.py | 2 +- 11 files changed, 64 insertions(+), 108 deletions(-) delete mode 100644 .tmp_tt.py create mode 100644 tests/submodule_test.cpp diff --git a/.tmp_tt.py b/.tmp_tt.py deleted file mode 100644 index 67f4584..0000000 --- a/.tmp_tt.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python3 -"""Render an installed candidate's default mcpp template, then build and run it.""" -import argparse -import json -import os -from pathlib import Path -import shutil -import subprocess -import tempfile -import tomllib - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--mcpp", default="mcpp") - parser.add_argument("--namespace", help="index namespace for legacy manifests without package.namespace") - parser.add_argument("--toolchain", default="llvm@23.1.3") - parser.add_argument("--template", help="named template; omit for the package default") - parser.add_argument("--run-arg", action="append", default=[]) - parser.add_argument("--index", type=Path, help="candidate SDK/wrapper index for unpublished feature dependencies") - args = parser.parse_args() - root = Path(__file__).resolve().parents[1] - metadata = tomllib.loads((root / "mcpp.toml").read_text())["package"] - namespace = metadata.get("namespace", args.namespace) - assert namespace, "Supply the published index namespace for this legacy manifest" - name, version = metadata["name"], metadata["version"] - identity = namespace + "." + name - with tempfile.TemporaryDirectory(prefix=name + "-template-") as directory: - temporary = Path(directory) - home = temporary / "home" - package = home / "registry/data/xpkgs" / (namespace + "-x-" + name) / version / (name + "-" + version) - shutil.copytree(root, package, ignore=shutil.ignore_patterns( - ".git", "target", ".mcpp", ".xlings", ".candidate-index", "__pycache__", "mcpp.lock", "compile_commands.json", "mcpp-2026.*")) - # What an install records beside the source: mcpp 2026.11.27.1 reads the - # resolution to know which package (and version) the directory is. - (package.parent / ".xlings-resolution.json").write_text( - json.dumps({"deps": [], "package": namespace + ":" + name + "@" + version}) + "\n") - (package.parent / ".xpkg-install.json").write_text( - json.dumps({"os": "", "version": version, "xlings_version": "", "registered": 0, "revision": 0}) + "\n") - index = home / "indices/mcpplibs/pkgs/mwrap" - index.mkdir(parents=True) - entry = '{url="https://example.invalid/candidate.tar.gz",sha256="fixture"}' - descriptor = ('package={spec="1",namespace=' + json.dumps(namespace) + ',name=' + json.dumps(name) + - ',description="Installed template fixture",type="package",mcpp="mcpp.toml",xpm={') - descriptor += ",".join(platform + "={[" + json.dumps(version) + "]=" + entry + "}" - for platform in ("linux", "macosx", "windows")) + "}}\n" - (index / (identity + ".lua")).write_text(descriptor) - env = dict(os.environ, MCPP_HOME=str(home)) - selector = identity + "@" + version - for command in ([args.mcpp, "new", "--list-templates", selector], - [args.mcpp, "new", "quickstart", "--template", selector + (":" + args.template if args.template else "")]): - print("+", " ".join(command), flush=True) - subprocess.run(command, cwd=temporary, env=env, check=True) - project = temporary / "quickstart" - manifest = project / "mcpp.toml" - text = manifest.read_text() - # The key is unquoted, so TOML reads it as one table per segment. - dependency = tomllib.loads(text)["dependencies"] - for segment in identity.split("."): - dependency = dependency[segment] - options = {"version": dependency} if isinstance(dependency, str) else dependency - assert options["version"] == version, options - replacement = '{ path = ' + json.dumps(package.as_posix()) - if options.get("features"): - replacement += ', features = ' + json.dumps(options["features"]) - replacement += ' }' - lines = text.splitlines() - matches = [i for i, line in enumerate(lines) if line.startswith(identity + " =")] - assert len(matches) == 1, "Expected exactly one unquoted qualified dependency from self.name" - lines[matches[0]] = identity + " = " + replacement - manifest.write_text("\n".join(lines) + "\n") - if args.index: - candidate_index = args.index.resolve() - subprocess.run([os.sys.executable, str(candidate_index / "tests/prepare_mwrap_indices.py")], - cwd=candidate_index, check=True) - with manifest.open("a") as out: - out.write("\n[indices]\n") - for namespace in ("compat", "mcpplibs.mwrap"): - view = candidate_index / "tests/mwrap/.indices" / namespace - out.write(json.dumps(namespace) + ' = { path = ' + json.dumps(view.as_posix()) + ' }\n') - command = [args.mcpp, "build", "--toolchain", args.toolchain, "--strict"] - print("+", " ".join(command), flush=True) - subprocess.run(command, cwd=project, check=True) - command = [args.mcpp, "run", "--toolchain", args.toolchain] - if args.run_arg: - command += ["--", *args.run_arg] - print("+", " ".join(command), flush=True) - subprocess.run(command, cwd=project, check=True) - - -if __name__ == "__main__": - main() diff --git a/mcpp.toml b/mcpp.toml index 2141377..5e3f737 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -2,8 +2,8 @@ [package] namespace = "mcpplibs.mwrap" name = "mbedtls" -version = "3.6.8" -description = "Mbed TLS 3.6.8 hashes as C++ modules for mcpp (import mcpplibs.mwrap.mbedtls;): SHA-1, SHA-224/256, SHA-384/512, SHA-3, MD5, the generic message-digest and HMAC API, over compat.mbedtls" +version = "3.6.8.1" +description = "Mbed TLS 3.6.8 hashes as C++ modules for mcpp (import mcpplibs.mwrap.mbedtls; or one sub-module, mcpplibs.mwrap.mbedtls.sha256): SHA-1, SHA-224/256, SHA-384/512, SHA-3, MD5, the generic message-digest and HMAC API, over compat.mbedtls" license = "Apache-2.0" authors = ["mcpp-community"] repo = "https://github.com/mcpplibs/mbedtls-m" diff --git a/src/mbedtls.cppm b/src/mbedtls.cppm index ad312c3..18c6931 100644 --- a/src/mbedtls.cppm +++ b/src/mbedtls.cppm @@ -1,12 +1,14 @@ -// mcpplibs.mwrap.mbedtls --- the root: every public module below, re-exported. +// mcpplibs.mwrap.mbedtls --- the root: every public sub-module below, re-exported. +// An importer takes the root for all of them, or one sub-module on its own +// (`mcpplibs.mwrap.mbedtls.sha256`, ...), as the mwrap spec names them. // The names are Mbed TLS's own (mbedtls_sha256, mbedtls_md_hmac, ...), in the // global namespace where upstream declares them. The implementation is // compat.mbedtls. Written by hand: a root has nothing to read from a header. export module mcpplibs.mwrap.mbedtls; -export import :sha256; -export import :sha512; -export import :sha1; -export import :md5; -export import :sha3; -export import :md; +export import mcpplibs.mwrap.mbedtls.sha256; +export import mcpplibs.mwrap.mbedtls.sha512; +export import mcpplibs.mwrap.mbedtls.sha1; +export import mcpplibs.mwrap.mbedtls.md5; +export import mcpplibs.mwrap.mbedtls.sha3; +export import mcpplibs.mwrap.mbedtls.md; diff --git a/src/md.cppm b/src/md.cppm index 05aff53..85f1288 100644 --- a/src/md.cppm +++ b/src/md.cppm @@ -10,7 +10,7 @@ module; #include -export module mcpplibs.mwrap.mbedtls:md; +export module mcpplibs.mwrap.mbedtls.md; export using ::mbedtls_md_info_t; diff --git a/src/md5.cppm b/src/md5.cppm index 6bf9a73..bb5dc84 100644 --- a/src/md5.cppm +++ b/src/md5.cppm @@ -10,7 +10,7 @@ module; #include -export module mcpplibs.mwrap.mbedtls:md5; +export module mcpplibs.mwrap.mbedtls.md5; export { using ::mbedtls_md5_context; diff --git a/src/sha1.cppm b/src/sha1.cppm index 1713763..eb9b783 100644 --- a/src/sha1.cppm +++ b/src/sha1.cppm @@ -10,7 +10,7 @@ module; #include -export module mcpplibs.mwrap.mbedtls:sha1; +export module mcpplibs.mwrap.mbedtls.sha1; export { using ::mbedtls_sha1_context; diff --git a/src/sha256.cppm b/src/sha256.cppm index c01de70..9e56773 100644 --- a/src/sha256.cppm +++ b/src/sha256.cppm @@ -10,7 +10,7 @@ module; #include -export module mcpplibs.mwrap.mbedtls:sha256; +export module mcpplibs.mwrap.mbedtls.sha256; export { using ::mbedtls_sha256_context; diff --git a/src/sha3.cppm b/src/sha3.cppm index 0599d27..5eaae29 100644 --- a/src/sha3.cppm +++ b/src/sha3.cppm @@ -10,7 +10,7 @@ module; #include -export module mcpplibs.mwrap.mbedtls:sha3; +export module mcpplibs.mwrap.mbedtls.sha3; export { using enum mbedtls_sha3_id; diff --git a/src/sha512.cppm b/src/sha512.cppm index 9d9a2f8..35fb40a 100644 --- a/src/sha512.cppm +++ b/src/sha512.cppm @@ -10,7 +10,7 @@ module; #include -export module mcpplibs.mwrap.mbedtls:sha512; +export module mcpplibs.mwrap.mbedtls.sha512; export { using ::mbedtls_sha512_context; diff --git a/tests/submodule_test.cpp b/tests/submodule_test.cpp new file mode 100644 index 0000000..89889b7 --- /dev/null +++ b/tests/submodule_test.cpp @@ -0,0 +1,46 @@ +// Each sub-module stands on its own, as the README and the mwrap spec name +// them: an importer that takes only `mcpplibs.mwrap.mbedtls.sha256` gets the +// SHA-256 API without the root. (mwrap-3.6.8.1: until then they were partitions +// of the root, and this import did not compile.) +import std; +import mcpplibs.mwrap.mbedtls.sha256; + +namespace { + +int failures = 0; +void check(bool ok, std::string_view what) +{ + if (!ok) ++failures; + std::println("{} {}", ok ? "ok " : "FAIL", what); +} + +std::string hex(const unsigned char* bytes, std::size_t n) +{ + std::string out; + for (std::size_t i = 0; i < n; ++i) out += std::format("{:02x}", bytes[i]); + return out; +} + +} // namespace + +int main() +{ + // FIPS 180-2's vector for "abc", by the one-shot call. + unsigned char out[32] = {}; + const int rc = mbedtls_sha256(reinterpret_cast("abc"), 3, out, 0); + check(rc == 0 && hex(out, 32) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", + "the sha256 sub-module alone hashes \"abc\" to the published digest"); + + // The context type and the streaming calls come with it. + mbedtls_sha256_context ctx; + mbedtls_sha256_init(&ctx); + int rc2 = mbedtls_sha256_starts(&ctx, 0); + rc2 |= mbedtls_sha256_update(&ctx, reinterpret_cast("ab"), 2); + rc2 |= mbedtls_sha256_update(&ctx, reinterpret_cast("c"), 1); + rc2 |= mbedtls_sha256_finish(&ctx, out); + mbedtls_sha256_free(&ctx); + check(rc2 == 0 && hex(out, 32) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", + "the sha256 sub-module alone streams the same bytes to the same digest"); + + return failures == 0 ? 0 : 1; +} diff --git a/tools/generate.py b/tools/generate.py index d3bd36c..483e326 100644 --- a/tools/generate.py +++ b/tools/generate.py @@ -60,7 +60,7 @@ def render(module, header, what, types, functions, opaque, enums): out.append("module;") out.append(f"#include <{header}>") out.append("") - out.append(f"export module mcpplibs.mwrap.mbedtls:{module};") + out.append(f"export module mcpplibs.mwrap.mbedtls.{module};") out.append("") for name in opaque: out.append(f"export using ::{name};") From 1736a0bc45dd4f173ca0c7ba7be70f8db98b49b5 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Tue, 1 Dec 2026 07:35:15 +0800 Subject: [PATCH 2/2] docs: the READMEs name the package version, 3.6.8.1 (check_mwrap_release) --- README.md | 4 ++-- README.zh.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c75b204..29d7f2a 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ built once; the modules only declare its interface. ## Getting started ```sh -mcpp new hash --template mcpplibs.mwrap.mbedtls@3.6.8 +mcpp new hash --template mcpplibs.mwrap.mbedtls@3.6.8.1 cd hash mcpp run ``` @@ -42,7 +42,7 @@ that streaming gives the same SHA-256. ```toml [dependencies] -mcpplibs.mwrap.mbedtls = "3.6.8" +mcpplibs.mwrap.mbedtls = "3.6.8.1" ``` ```cpp diff --git a/README.zh.md b/README.zh.md index 1f3bcbc..b029eba 100644 --- a/README.zh.md +++ b/README.zh.md @@ -31,7 +31,7 @@ ## 快速开始 ```sh -mcpp new hash --template mcpplibs.mwrap.mbedtls@3.6.8 +mcpp new hash --template mcpplibs.mwrap.mbedtls@3.6.8.1 cd hash mcpp run ``` @@ -40,7 +40,7 @@ mcpp run ```toml [dependencies] -mcpplibs.mwrap.mbedtls = "3.6.8" +mcpplibs.mwrap.mbedtls = "3.6.8.1" ``` ```cpp