Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
d0ae156
mcpp.plugins.binary: the libraries an ELF, PE or Mach-O file names as…
Sunrisepeak Nov 23, 2026
ebb1285
rules-qt: moc_json, moc_includes, compile_ex and lupdate extensions, …
Sunrisepeak Nov 23, 2026
70ac4ac
rules-qt: plugin_closure completes the libraries deployed plugins loa…
Sunrisepeak Nov 23, 2026
0294863
rules-qml: the module chain, Qt's own modules beside the program, qt.…
Sunrisepeak Nov 23, 2026
d96681d
rules-qml: fixtures qml-modules, qml-deploy, qml-import-only, qml-sha…
Sunrisepeak Nov 23, 2026
4c4a1ee
0.27.0: rules-qml and mcpp.plugins.binary; documentation
Sunrisepeak Nov 23, 2026
d698827
rules-qml: CI steps, the reader fixture, and the llvm lane for the ne…
Sunrisepeak Nov 23, 2026
51ac0df
rules-qml: rcc writes a depfile; the escaping test does not need a fi…
Sunrisepeak Nov 23, 2026
482cd6c
Take the workaround out: mcpp#1011 is fixed in the engine, which carr…
Sunrisepeak Nov 23, 2026
ef113d2
Design notes: revision 5, the engine closes deployed libraries
Sunrisepeak Nov 23, 2026
ca4bf55
rules-qml: review fixes (qsb missing leaves the shaders out of the re…
Sunrisepeak Nov 23, 2026
5f5cd5e
rules-qt: on macOS moc_includes also gives -I<sdk>/include, where QtQ…
Sunrisepeak Nov 23, 2026
efd5d46
CI: on macOS the QML fixtures check the directory the program was bui…
Sunrisepeak Nov 23, 2026
39f9feb
rules-qml: the debug-twin rule for Windows DLLs applies to Qt's own S…
Sunrisepeak Nov 23, 2026
1ae673a
CI and docs: mcpp 2026.11.23.1, whose pack closes over what the build…
Sunrisepeak Nov 24, 2026
2be9a2b
CI: strip the carriage return Python and llvm-readobj write on Window…
Sunrisepeak Nov 24, 2026
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
634 changes: 634 additions & 0 deletions .agents/docs/2026-11-24-rules-qml-design.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions .agents/docs/2026-11-24-rules-qml-spikes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# rules-qml spikes (2026-11-24)

Throwaway prototypes behind `../2026-11-24-rules-qml-design.md`. They are evidence, not the implementation:
the implementation is C++23 modules under `rules/` and `src/`. Section numbers refer to the design document.

| file | what it proves | how it was run |
|---|---|---|
| `closure.py` | the runtime-module closure (design Q1, §8) equals `qmlimportscanner`'s on 4 samples, including all 40 top-level Qt modules (24/27/15/49 modules, both difference sets empty) | `python3 -I closure.py <dir of .qml>` |
| `binary.hpp`, `needed_main.cpp` | `needed(path)` for ELF/PE/Mach-O (design Q2, §7): 180/180 SDK ELF files identical to `readelf -d`; mingw-built PE and lld-built Mach-O (thin and fat) identical to `objdump -p` / `llvm-otool -L`; 1500 truncated or corrupted inputs, no crash under ASan+UBSan | `g++ -std=c++23 -fsanitize=address,undefined needed_main.cpp -o needed` |
| `module-pipeline.build.mcpp`, `module-pipeline.Main.qml` | the per-module action chain (design §6 steps 1-6) for one dotted uri with a C++ type, a singleton, a `.js`, a nested file and a resource: `cpp=84 singleton=red js=42 nested=7 resource=hello-resource`; with a C++ `QML_SINGLETON` added: `theme=9` | a package whose `build.mcpp` is this file, `src/backend.h` with `QML_ELEMENT`, `qml/ui/*`, `xim:qt` 6.11.1, `mcpp run` |
| `multi-module.build.mcpp`, `multi-module.Main.qml` | two modules (`app.core` with C++ types and `Card.qml`, `app.ui` importing it); `--foreign-types` across modules gives `prototype: "Base"` for a class derived across modules; `sum=19`; the qmldir needs no `depends` line | same as above, ASCII path without spaces |
| `llvm-check.sh` | the generated sources compile with clang (20.1.7, 22.1.8, 23.1.3, 23.1.6) against the real libstdc++, link with lld and run with the same output as gcc | see the pitfall in the script header |

Not covered by any spike: Windows, macOS, `qsb` (not runnable from `xim:qt-addons`), `qmllint`, `qt.conf` under a macOS bundle.
120 changes: 120 additions & 0 deletions .agents/docs/2026-11-24-rules-qml-spikes/binary.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Prototype of mcpp.plugins.binary::needed -- std only. Returns the library names a
// shared library or program names as dependencies, or an error string.
#pragma once
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <iterator>
#include <string>
#include <string_view>
#include <vector>
namespace binary {
struct result { std::vector<std::string> names; std::string error; bool ok() const { return error.empty(); } };
namespace detail {
struct view {
const unsigned char* p; std::size_t n;
bool in(std::uint64_t off, std::uint64_t len) const { return off <= n && len <= n - off; }
template <class T> bool get(std::uint64_t off, T& out, bool big = false) const {
if (!in(off, sizeof(T))) return false;
unsigned char b[sizeof(T)]; std::memcpy(b, p + off, sizeof(T));
if (big) std::reverse(b, b + sizeof(T));
std::memcpy(&out, b, sizeof(T)); return true; // host is little-endian (x86-64, arm64)
}
bool cstr(std::uint64_t off, std::string& out, std::size_t max = 4096) const {
out.clear();
for (std::size_t i = 0; i < max; ++i) { if (!in(off + i, 1)) return false; char c = char(p[off + i]); if (!c) return true; out += c; }
return false;
}
};
inline void add(result& r, std::string s) { if (!s.empty() && std::ranges::find(r.names, s) == r.names.end()) r.names.push_back(std::move(s)); }

inline result elf(const view& v) {
result r; const bool is64 = v.p[4] == 2;
if (v.p[5] != 1) { r.error = "big-endian ELF is not read"; return r; }
std::uint64_t phoff; std::uint16_t phentsize, phnum;
if (is64) { std::uint64_t o; if (!v.get(32, o)) { r.error = "truncated ELF header"; return r; } phoff = o; v.get(54, phentsize); v.get(56, phnum); }
else { std::uint32_t o; if (!v.get(28, o)) { r.error = "truncated ELF header"; return r; } phoff = o; v.get(42, phentsize); v.get(44, phnum); }
struct seg { std::uint64_t vaddr, off, filesz; };
std::vector<seg> loads; std::uint64_t dynoff = 0, dynsz = 0; bool haveDyn = false;
for (unsigned i = 0; i < phnum; ++i) {
const std::uint64_t at = phoff + std::uint64_t(i) * phentsize; std::uint32_t type;
if (!v.get(at, type)) { r.error = "truncated program headers"; return r; }
std::uint64_t off, vaddr, filesz;
if (is64) { std::uint64_t a, b, c; if (!v.get(at + 8, a) || !v.get(at + 16, b) || !v.get(at + 32, c)) { r.error = "truncated program headers"; return r; } off = a; vaddr = b; filesz = c; }
else { std::uint32_t a, b, c; if (!v.get(at + 4, a) || !v.get(at + 8, b) || !v.get(at + 16, c)) { r.error = "truncated program headers"; return r; } off = a; vaddr = b; filesz = c; }
if (type == 1) loads.push_back({vaddr, off, filesz});
if (type == 2) { dynoff = off; dynsz = filesz; haveDyn = true; }
}
if (!haveDyn) return r; // statically linked: no dependencies
auto to_off = [&](std::uint64_t va, std::uint64_t& out) { for (auto& s : loads) if (va >= s.vaddr && va < s.vaddr + s.filesz) { out = va - s.vaddr + s.off; return true; } return false; };
std::uint64_t strtab = 0; std::vector<std::uint64_t> needed;
const std::size_t esz = is64 ? 16 : 8;
for (std::uint64_t o = 0; o + esz <= dynsz; o += esz) {
std::uint64_t tag, val;
if (is64) { if (!v.get(dynoff + o, tag) || !v.get(dynoff + o + 8, val)) { r.error = "truncated dynamic section"; return r; } }
else { std::uint32_t a, b; if (!v.get(dynoff + o, a) || !v.get(dynoff + o + 4, b)) { r.error = "truncated dynamic section"; return r; } tag = a; val = b; }
if (tag == 0) break; if (tag == 1) needed.push_back(val); if (tag == 5) strtab = val;
}
std::uint64_t soff; if (needed.empty()) return r;
if (!to_off(strtab, soff)) { r.error = "dynamic string table is outside the file"; return r; }
for (auto n : needed) { std::string s; if (!v.cstr(soff + n, s)) { r.error = "bad dependency name"; return r; } add(r, s); }
return r;
}
inline result pe(const view& v) {
result r; std::uint32_t lfanew, sig;
if (!v.get(0x3c, lfanew) || !v.get(lfanew, sig) || sig != 0x00004550) { r.error = "not a PE file"; return r; }
std::uint16_t nsec, optsz, magic;
if (!v.get(lfanew + 6, nsec) || !v.get(lfanew + 20, optsz) || !v.get(lfanew + 24, magic)) { r.error = "truncated PE header"; return r; }
const std::uint64_t opt = lfanew + 24, dirs = opt + (magic == 0x20b ? 112 : 96);
if (magic != 0x20b && magic != 0x10b) { r.error = "unknown PE optional header"; return r; }
struct sec { std::uint32_t va, vsize, raw, rawsz; }; std::vector<sec> secs; const std::uint64_t st = opt + optsz;
for (unsigned i = 0; i < nsec; ++i) { sec s; const std::uint64_t a = st + std::uint64_t(i) * 40;
if (!v.get(a + 8, s.vsize) || !v.get(a + 12, s.va) || !v.get(a + 16, s.rawsz) || !v.get(a + 20, s.raw)) { r.error = "truncated section table"; return r; } secs.push_back(s); }
auto rva = [&](std::uint32_t x, std::uint64_t& out) { for (auto& s : secs) { const std::uint32_t len = std::max(s.vsize, s.rawsz); if (x >= s.va && x - s.va < len) { out = std::uint64_t(x - s.va) + s.raw; return true; } } return false; };
auto walk = [&](unsigned index, std::size_t entry, std::size_t nameAt, bool delay) -> bool {
std::uint32_t dva, dsz; if (!v.get(dirs + std::uint64_t(index) * 8, dva) || !v.get(dirs + std::uint64_t(index) * 8 + 4, dsz)) return true; // no such directory
if (!dva) return true; std::uint64_t base; if (!rva(dva, base)) return false;
for (std::uint64_t o = 0;; o += entry) {
std::uint32_t nm = 0, probe = 0; if (!v.get(base + o + nameAt, nm) || !v.get(base + o, probe)) return false;
if (!nm && (!delay ? true : !probe)) break; if (!nm) break;
std::uint64_t so; std::string s; if (!rva(nm, so) || !v.cstr(so, s, 256)) return false; add(r, s);
} return true; };
if (!walk(1, 20, 12, false) || !walk(13, 32, 4, true)) r.error = "import table is outside the file";
return r;
}
inline result macho_one(const view& v, std::uint64_t base) {
result r; std::uint32_t magic; if (!v.get(base, magic)) { r.error = "truncated Mach-O header"; return r; }
const bool is64 = magic == 0xfeedfacf; if (!is64 && magic != 0xfeedface) { r.error = "not a little-endian Mach-O"; return r; }
std::uint32_t ncmds; if (!v.get(base + 16, ncmds)) { r.error = "truncated Mach-O header"; return r; }
std::uint64_t at = base + (is64 ? 32 : 28);
for (std::uint32_t i = 0; i < ncmds; ++i) {
std::uint32_t cmd, size; if (!v.get(at, cmd) || !v.get(at + 4, size) || size < 8) { r.error = "truncated load commands"; return r; }
if (cmd == 0xc || cmd == 0x80000018 || cmd == 0x8000001f || cmd == 0x80000023 || cmd == 0x20) { // not LC_ID_DYLIB (0xd): that is the file's own name
std::uint32_t nameoff; std::string s;
if (!v.get(at + 8, nameoff) || nameoff >= size || !v.cstr(at + nameoff, s)) { r.error = "bad dylib command"; return r; } add(r, s); }
at += size;
}
return r;
}
inline result macho(const view& v) {
std::uint32_t magic; v.get(0, magic, true);
if (magic != 0xcafebabe && magic != 0xcafebabf) return macho_one(v, 0);
const bool f64 = magic == 0xcafebabf; std::uint32_t n; if (!v.get(4, n, true) || n > 64) { result r; r.error = "bad fat header"; return r; }
result all;
for (std::uint32_t i = 0; i < n; ++i) { const std::uint64_t a = 8 + std::uint64_t(i) * (f64 ? 32 : 20); std::uint64_t off;
if (f64) { if (!v.get(a + 8, off, true)) { all.error = "truncated fat header"; return all; } } else { std::uint32_t o; if (!v.get(a + 8, o, true)) { all.error = "truncated fat header"; return all; } off = o; }
auto one = macho_one(v, off); if (!one.ok()) { all.error = one.error; return all; } for (auto& s : one.names) add(all, s); }
return all;
}
} // namespace detail
inline result needed(const std::string& path) {
std::ifstream in(path, std::ios::binary); if (!in) return {{}, "cannot open " + path};
std::string data((std::istreambuf_iterator<char>(in)), {}); detail::view v{reinterpret_cast<const unsigned char*>(data.data()), data.size()};
if (v.n >= 20 && std::memcmp(v.p, "\x7f""ELF", 4) == 0) return detail::elf(v);
if (v.n >= 2 && v.p[0] == 'M' && v.p[1] == 'Z') return detail::pe(v);
if (v.n >= 8) { std::uint32_t m; v.get(0, m); std::uint32_t mb; v.get(0, mb, true);
if (m == 0xfeedface || m == 0xfeedfacf || mb == 0xcafebabe || mb == 0xcafebabf) return detail::macho(v); }
return {{}, "unrecognised binary format"};
}
}
62 changes: 62 additions & 0 deletions .agents/docs/2026-11-24-rules-qml-spikes/closure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import re, sys, json, subprocess, os
Q = os.path.expanduser("~/.xlings/data/xpkgs/xim-x-qt/6.11.1")
IMP = re.compile(r'^\s*import\s+([A-Za-z_][\w.]*)(?:\s+[\d.]+)?(?:\s+as\s+\w+)?\s*;?\s*$', re.M)
def strip(text):
out=[];i=0
while i<len(text):
if text.startswith('//',i):
while i<len(text) and text[i]!='\n': i+=1
elif text.startswith('/*',i):
j=text.find('*/',i+2); i=len(text) if j<0 else j+2; out.append(' ')
elif text[i]=='"':
j=i+1
while j<len(text) and text[j]!='"': j+= 2 if text[j]=='\\' else 1
out.append('""'); i=j+1
else: out.append(text[i]); i+=1
return ''.join(out)
def file_imports(path):
return IMP.findall(strip(open(path,encoding='utf-8').read()))
def qmldir_follow(uri, own):
rel = uri.replace('.','/')
d = os.path.join(Q,'qml',rel)
f = os.path.join(d,'qmldir')
if not os.path.isfile(f): return None, []
deps=[]
for line in open(f,encoding='utf-8'):
t=line.split()
if not t: continue
if t[0] in ('optional','default') and len(t)>=3 and t[1]=='import': deps.append(t[2]); continue
if t[0]=='import' and len(t)>=2: deps.append(t[1]); continue
if t[0]=='depends' and len(t)>=2: deps.append(t[1])
# the module's own .qml files import further modules (the scanner reads them)
for dp,dns,fns in os.walk(d):
dns[:]=sorted(x for x in dns if not os.path.isfile(os.path.join(dp,x,'qmldir'))) # a nested module is its own module
for fn in sorted(fns):
if fn.endswith('.qml'):
deps.extend(file_imports(os.path.join(dp,fn)))
return rel, deps
def closure(roots, own=()):
seen={}; todo=list(roots)
while todo:
u=todo.pop()
if u in seen or u in own: continue
rel,deps=qmldir_follow(u,own)
if rel is None: seen[u]=None; continue
seen[u]=rel; todo.extend(deps)
return seen
def scanner(qmldir_root):
j=subprocess.run([Q+'/libexec/qmlimportscanner','-rootPath',qmldir_root,'-importPath',Q+'/qml'],capture_output=True,text=True,env={'LD_LIBRARY_PATH':Q+'/lib','LC_ALL':'C.UTF-8'}).stdout
return {e['name']:e.get('relativePath') for e in json.loads(j) if e.get('type')=='module'}
if __name__=='__main__':
root=sys.argv[1]
roots=set()
for dp,_,fs in os.walk(root):
for f in fs:
if f.endswith('.qml'): roots.update(file_imports(os.path.join(dp,f)))
mine=closure(roots)
sc=scanner(root)
mine_set={k for k,v in mine.items() if v is not None}
print("imports:",sorted(roots))
print("mine=%d scanner=%d"%(len(mine_set),len(sc)))
print("scanner-only:",sorted(set(sc)-mine_set))
print("mine-only :",sorted(mine_set-set(sc)))
20 changes: 20 additions & 0 deletions .agents/docs/2026-11-24-rules-qml-spikes/llvm-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Compile, link and run the generated QML sources with clang and the REAL libstdc++ (Linux).
# usage: llvm-check.sh <dir of generated .cpp> <dir of moc/other .cpp> <main.cpp> <include dir of src/>
# PITFALL: mcpp's `clang++.cfg` appends libc++ headers unconditionally, so `clang++ -stdlib=libstdc++`
# silently uses libc++. Use the C driver `clang -x c++ --no-default-config` and prove the runtime first.
set -euo pipefail
GEN=$1; GEN2=$2; MAIN=$3; SRC=$4
LLVM=${LLVM:-$HOME/.mcpp/registry/data/xpkgs/xim-x-llvm/23.1.3}; GCC=$HOME/.mcpp/registry/data/xpkgs/xim-x-gcc/16.1.0
GLD=$HOME/.mcpp/registry/data/xpkgs/xim-x-glibc/2.44.3; LH=$HOME/.mcpp/registry/data/xpkgs/xim-x-linux-headers/5.11.1/include
Q=${QT_ROOT_DIR:-$HOME/.xlings/data/xpkgs/xim-x-qt/6.11.1}
X="--no-default-config -x c++ -std=c++23 -nostdlibinc -nostdinc++ -isystem $GCC/include/c++/16.1.0 -isystem $GCC/include/c++/16.1.0/x86_64-linux-gnu -isystem $GLD/include -isystem $LH"
printf '#include <string>\n#if defined(_LIBCPP_VERSION)\n#error RUNTIME=libc++\n#elif defined(__GLIBCXX__)\n#error RUNTIME=libstdc++\n#endif\n' > /tmp/rt.cpp
$LLVM/bin/clang $X -fsyntax-only /tmp/rt.cpp 2>&1 | grep -q 'RUNTIME=libstdc++' || { echo "not libstdc++"; exit 1; }
INC="-I$Q/include -I$Q/include/QtCore -I$Q/include/QtGui -I$Q/include/QtQml -I$Q/include/QtQuick -I$SRC -fPIC"
D=$(mktemp -d); cd "$D"
for f in $GEN/*.cpp $GEN2/*.cpp $MAIN; do $LLVM/bin/clang $X $INC -O1 -c -Wno-everything "$f" -o "$(basename "$f").o"; done
$LLVM/bin/clang --no-default-config -fuse-ld=lld --gcc-install-dir=$GCC/lib/gcc/x86_64-linux-gnu/16.1.0 -B$GLD/lib64 -L$GLD/lib64 \
-Wl,--dynamic-linker=$GLD/lib64/ld-linux-x86-64.so.2 -Wl,-rpath,$GLD/lib64 *.o -o prog -L$Q/lib -lQt6Quick -lQt6Qml -lQt6Gui -lQt6Core \
-L$GCC/lib64 -lstdc++ -lm -Wl,-rpath,$GCC/lib64 -Wl,-rpath,$Q/lib -Wl,-rpath-link,$Q/lib -Wl,--allow-shlib-undefined
QT_QPA_PLATFORM=offscreen LC_ALL=C.UTF-8 ./prog
11 changes: 11 additions & 0 deletions .agents/docs/2026-11-24-rules-qml-spikes/module-pipeline.Main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import QtQuick
import "Util.js" as U
import com.acme.ui
QtObject {
property Backend b: Backend {}
property QtObject inner: Inner { }
readonly property int viaCpp: b.twice(b.n)
readonly property string viaSingleton: Style.accent
readonly property int viaJs: U.add(40, 2)
readonly property int viaNested: inner.value
}
Loading
Loading