Skip to content

Commit d5fd2ec

Browse files
build(deps): headers only in the system lock files; the libraries as modules
zlib, zstd and xz are their mwrap modules (mcpplibs.mwrap.zlib, .zstd, .xz), replacing compat.* and the codecs' #include; deflateInit2/inflateInit2 are called as the functions they expand to, and LZMA_STREAM_INIT is a value- initialised stream. JSON is nlohmann.json from the index: the copied json.hpp and mcpp.libs.json are removed. The C library's macros (stdout, stderr, errno, EOF, _IOLBF) are mcpplibs.mwrap.libc's, and the error numbers std::errc's. .github/tools/check_include_regions.sh keeps #include to the two system lock files. The single-file launcher depends on mcpplibs.mwrap.zstd. The bytes of a gzip, zstd, xz and zip package are those mcpp wrote before (design 2026-11-07 D10, C5). Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent ed87e64 commit d5fd2ec

86 files changed

Lines changed: 447 additions & 487 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
# check_include_regions.sh — headers are included only where a system has no
3+
# module for what is needed (design 2026-11-07 D10).
4+
#
5+
# mcpp imports the standard library (`import std`), its dependencies as modules
6+
# (nlohmann.json, mcpplibs.os, the mwrap wrappers of zlib, zstd, xz and of the
7+
# C library's macros), and nothing else. The only `#include` directives of
8+
# `src/` and `modules/` are the operating system's headers of the file lock,
9+
# each in the source file of its system (src/native/<system>/lock.cpp). A
10+
# directive anywhere else is a header a module should provide: depend on the
11+
# package that wraps it, or wrap it (mcpp-index docs/mwrap.md).
12+
#
13+
# Text that only looks like a directive is not one: a raw string (the source
14+
# mcpp writes for a launcher or a template) and a comment are skipped. Tests
15+
# (`tests/`, a module's `tests/`) are outside the rule.
16+
set -euo pipefail
17+
cd "$(dirname "$0")/../.."
18+
python3 - <<'PY'
19+
import re, sys
20+
from pathlib import Path
21+
22+
ALLOWED = {Path("src/native/posix/lock.cpp"), Path("src/native/windows/lock.cpp")}
23+
RAW = re.compile(r'(?:u8|u|U|L)?R"([^()\\ ]{0,16})\(')
24+
25+
def directives(text):
26+
"""Line numbers of `#include` directives outside comments and raw strings."""
27+
out, i, n, line = [], 0, len(text), 1
28+
at_line_start = True
29+
while i < n:
30+
c = text[i]
31+
if c == '\n':
32+
line += 1; at_line_start = True; i += 1; continue
33+
if text.startswith('//', i):
34+
j = text.find('\n', i); i = n if j < 0 else j; continue
35+
if text.startswith('/*', i):
36+
j = text.find('*/', i + 2); j = n if j < 0 else j + 2
37+
line += text.count('\n', i, j); i = j; continue
38+
m = RAW.match(text, i)
39+
if m and (i == 0 or not (text[i - 1].isalnum() or text[i - 1] == '_')):
40+
end = text.find(')' + m.group(1) + '"', m.end()); end = n if end < 0 else end + len(m.group(1)) + 2
41+
line += text.count('\n', i, end); i = end; at_line_start = False; continue
42+
if c == '"':
43+
j = i + 1
44+
while j < n and text[j] not in '"\n':
45+
j += 2 if text[j] == '\\' else 1
46+
i = j + 1; at_line_start = False; continue
47+
if at_line_start and c == '#':
48+
if re.match(r'#\s*include\b', text[i:]): out.append(line)
49+
if not c.isspace(): at_line_start = False
50+
i += 1
51+
return out
52+
53+
bad = 0
54+
for path in sorted(list(Path("src").rglob("*.cpp*")) + list(Path("modules").rglob("*.cpp*"))):
55+
if "tests" in path.parts or "test" in path.parts or path in ALLOWED:
56+
continue
57+
for line in directives(path.read_text(encoding="utf-8", errors="replace")):
58+
print(f"{path}:{line}: #include outside the system lock files; import a module instead")
59+
bad += 1
60+
for path in ALLOWED:
61+
if not path.exists():
62+
print(f"{path}: the allowed region is gone; update this check")
63+
bad += 1
64+
print(f"check_include_regions: {bad} problem(s)")
65+
sys.exit(1 if bad else 0)
66+
PY

‎.github/tools/check_modules_wiring.sh‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,10 @@ for f in tools/bootstrap-macos.sh .github/workflows/bootstrap-macos.yml \
107107
|| bad "$f does not add modules/*/src/**.cppm — it would build a strict subset of mcpp and report success"
108108
done
109109

110-
# The vendored json header is reached through a private include dir. Its path
111-
# appears in three places and has already moved once.
112-
for f in tools/bootstrap-macos.sh .github/workflows/bootstrap-macos.yml \
113-
bench/projects/mcpp/xmake.lua; do
114-
grep -qF 'modules/libs/src/json' "$f" \
115-
|| bad "$f does not add the json include dir (modules/libs/src/json)"
116-
done
117-
[[ -f modules/libs/src/json/json.hpp ]] \
118-
|| bad "modules/libs/src/json/json.hpp is missing, but three files name that path"
110+
# No third-party source is copied into the tree (2026.11.7.1): nlohmann.json
111+
# and the C libraries are packages of the index, imported as modules.
112+
[[ -e modules/libs/src/json ]] \
113+
&& bad "modules/libs/src/json is back: depend on nlohmann.json from the index instead"
119114

120115
# Anything that hashes mcpp's sources has to hash BOTH trees. A cache key that
121116
# saw only `src/**` would restore a target/ built from different sources and

‎.github/workflows/bootstrap-macos.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ jobs:
7878
-- directly.
7979
add_files("modules/*/src/**.cppm")
8080
add_packages("cmdline")
81-
add_includedirs("modules/libs/src/json")
8281
set_policy("build.c++.modules", true)
8382
-- Static link libc++ for minimal runtime dependencies
8483
add_ldflags("-static-libstdc++", {force = true})

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ jobs:
100100
- name: Check modules/ wiring
101101
run: bash .github/tools/check_modules_wiring.sh
102102

103+
- name: Check that headers are included only in the system lock files
104+
run: bash .github/tools/check_include_regions.sh
105+
103106
- name: Check src/build/prepare* file lengths
104107
run: bash .github/tools/check_file_lengths.sh
105108

‎mcpp.toml‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,23 @@ linkage = "static"
8787
# past 0.0.6) understands this, so the legacy quoted form is no longer needed.
8888
[dependencies]
8989
mcpplibs.cmdline = "0.0.1"
90+
# JSON for Modern C++, as the index's module package (no copied header).
91+
"nlohmann.json" = "3.12.0"
92+
# The C library's macros (`stdout`, `stderr`, `EOF`, `errno` …) as C++ names:
93+
# `import std` carries no macro (design 2026-11-07 D10).
94+
"mcpplibs.mwrap.libc" = "17.0.0"
95+
# The codecs of a package's container (SPEC-014 §5): gzip and raw DEFLATE,
96+
# zstd, xz. The reference libraries, through their mwrap modules, so an archive
97+
# is written the same way on every host and nothing is looked for on PATH.
98+
"mcpplibs.mwrap.zlib" = "1.3.2"
99+
"mcpplibs.mwrap.zstd" = "1.5.7"
100+
"mcpplibs.mwrap.xz" = "5.8.3"
90101

91102
# The operating system is mcpplibs.os's (design 2026-10-26 §25): mcpp keeps no
92103
# layer of its own.
93104
[dependencies.mcpplibs]
94105
os = "0.3.0"
95106

96-
# The codecs of a package's container (SPEC-014 §5): gzip and raw DEFLATE,
97-
# zstd, xz. The reference libraries, so an archive is written the same way on
98-
# every host and nothing is looked for on PATH.
99-
[dependencies.compat]
100-
zlib = "1.3.2"
101-
zstd = "1.5.7"
102-
xz = "5.8.3"
103107

104108
[target.linux.build]
105109
sources = ["!src/native/windows/**"]

‎modules/buildmcpp/mcpp.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ license = "Apache-2.0"
3131
# as the engine consumes them. A change that breaks only the local test is a
3232
# contract change; one that breaks only the global test is a consumer that had
3333
# been relying on something the contract never promised.
34+
[dependencies]
35+
"nlohmann.json" = "3.12.0"
36+
3437
[dependencies.mcpp]
3538
invocation = { path = "../invocation" }
3639
libs = { path = "../libs" }

‎modules/buildmcpp/src/directives.cppm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export module mcpp.build.directives;
3939

4040
import std;
4141
import mcpp.build.program_protocol;
42-
import mcpp.libs.json;
42+
import nlohmann.json;
4343
import mcpp.manifest;
4444
import mcpp.source_kind;
4545
import mcpp.toolchain.dialect;

‎modules/buildmcpp/src/tool_store.cppm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export module mcpp.build.tool_store;
4545

4646
import std;
4747
import mcpp.invocation;
48-
import mcpp.libs.json;
48+
import nlohmann.json;
4949
import mcpp.manifest;
5050
import mcpp.toolchain.fingerprint;
5151

‎modules/dyndep/src/dyndep.cppm‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
// (`gcm.cache/<sanitized>.gcm`, with ':' replaced by '-' to keep
1313
// filename-safe).
1414

15-
module;
16-
#include <cstdio>
17-
1815
export module mcpp.dyndep;
1916

2017
import std;

‎modules/libs/mcpp.toml‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
# libs — third-party parsers, wrapped as modules of this project.
2-
#
3-
# A module this project builds and exports is a module of this project, whoever
4-
# wrote the code inside. `json` wraps nlohmann's header; `toml` is written here.
5-
# They live together because they answer the same question -- "read this text
6-
# format" -- and because neither imports anything from mcpp.
7-
#
8-
# `include_dirs` is what the root manifest used to carry on their behalf. It is
9-
# private to this package by construction: a package's build inputs never widen
10-
# its public interface.
1+
# libs — text-format parsers written for mcpp: `toml`. It imports nothing from
2+
# mcpp. JSON is nlohmann.json from the index (2026.11.7.1): no third-party
3+
# source is copied into this tree.
114
[package]
125
name = "libs"
136
namespace = "mcpp"
147
version = "0.1.0"
15-
description = "Vendored and in-house text-format parsers as mcpp modules"
8+
description = "The TOML parser of mcpp, as a module"
169
license = "Apache-2.0"
1710

18-
[build]
19-
include_dirs = ["src/json"]

0 commit comments

Comments
 (0)