Skip to content

Commit 43b26e9

Browse files
committed
feat: mcpp.tools.embed, the first member of the tools half
A rule states how a translation unit is compiled by a compiler mcpp does not drive; it submits an action and the engine schedules it. A tool states something a build program needs that no compiler performs, and does it while build.mcpp runs. `mcpp.tools.embed` writes a data file into a header the program compiles in, as a byte array or a 32-bit word array, with the same reason mcpp.rules.spirv gives for emitting a header rather than a file beside the binary: the program's correctness stops depending on its working directory and `mcpp pack` has nothing further to collect. It does not rewrite an unchanged header. Writing identical bytes would still move the mtime and rebuild every translation unit that includes it, which is what makes the tool safe to call unconditionally from a build program. The fixture activates `tools-embed` alone, so it also asserts that a feature adds exactly its own unit: the manifest names no rule and the build program imports none. Its second run is the measurement the engine fix in mcpp 2026.9.5.4 exists for -- editing the data file must reach the binary -- which is why the workflow pins that version.
1 parent 1cf5075 commit 43b26e9

12 files changed

Lines changed: 309 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
env:
1010
# The mcpp release the consumers build with. Raising it is what admits a
1111
# member that relies on a newer engine; the README states each member's floor.
12-
MCPP_VERSION: 2026.9.5.3
12+
MCPP_VERSION: 2026.9.5.4
1313

1414
jobs:
1515
consumers:
@@ -47,6 +47,21 @@ jobs:
4747
"$MCPP" run | tee run.log
4848
grep -q '^magic=07230203' run.log
4949
50+
# A tool, not a rule: the header is written while the build program runs,
51+
# so there is no action to schedule. The second build is the measurement
52+
# that matters -- editing the data file must reach the binary, which is
53+
# the fast-path comparison mcpp 2026.9.5.4 added and the reason this job
54+
# pins that version.
55+
- name: tools-embed through a consumer
56+
working-directory: tests/embed-consumer
57+
run: |
58+
"$MCPP" run | tee run.log
59+
grep -q '^size=33 sum=3189 text=mcpp.tools.embed fixture payload' run.log
60+
printf 'changed\n' > data/message.txt
61+
"$MCPP" run | tee run2.log
62+
grep -q '^size=8 ' run2.log
63+
git checkout -- data/message.txt
64+
5065
# Compiles the device unit on a machine with no GPU: the clang route
5166
# produces sm_89 code from the payload toolkit. Running it needs a
5267
# device, so the run is of the CPU variant, which the same seam serves.

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
target/
2-
.mcpp/
3-
mcpp.lock
42
compile_commands.json
3+
*.log

mcpp.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sources = ["src/plugins.cppm"]
2323
default = []
2424
rules-cuda = { sources = ["rules/cuda.cppm"] }
2525
rules-spirv = { sources = ["rules/spirv.cppm"] }
26+
tools-embed = { sources = ["tools/embed.cppm"] }
2627

2728
[targets.plugins]
2829
kind = "lib"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"index_repos": [
3+
],
4+
"deps": ["xim:cuda-cccl@12.9.27", "xim:cuda-cudart@12.9.79", "xim:cuda-nvcc@12.9.86", "xim:libcuda-host-link@0.0.1", "xim:libcurand@10.3.10.19"],
5+
"workspace": {
6+
"cuda-cccl": "xim:12.9.27",
7+
"cuda-cudart": "xim:12.9.79",
8+
"cuda-nvcc": "xim:12.9.86",
9+
"libcuda-host-link": "xim:0.0.1",
10+
"libcurand": "xim:10.3.10.19"
11+
},
12+
"lang": "en",
13+
"mirror": "auto"
14+
}

tests/cuda-consumer/mcpp.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Auto-generated by mcpp. Do not edit by hand.
2+
# Records what this build resolved. It does not yet pin future builds:
3+
# index dependencies are re-resolved from their constraints each time.
4+
# dev-dependencies are excluded: only `mcpp test` resolves them, and this
5+
# file must not change depending on which command ran last.
6+
version = 2
7+
8+
[package."compat.cuda-runtime"]
9+
namespace = "compat"
10+
version = "2026.09.05"
11+
source = "index+compat@2026.09.05"
12+
hash = "fnv1a:058be04055328f65"
13+

tests/embed-consumer/build.mcpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import std;
2+
import mcpp;
3+
import mcpp.tools.embed;
4+
5+
int main() {
6+
mcpp::tools::embed::options opt;
7+
opt.name_space = "fixture";
8+
opt.null_terminate = true;
9+
return mcpp::tools::embed::file("data/message.txt", opt) ? 0 : 1;
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mcpp.tools.embed fixture payload

tests/embed-consumer/mcpp.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Fixture: a consumer that activates only `tools-embed`. It proves the second
2+
# half of the collection's naming rule -- a member that is not a rule, imported
3+
# under `mcpp.tools.<x>` -- and that a feature adds exactly its own unit: this
4+
# manifest never names a rule and the build program never imports one.
5+
[package]
6+
name = "embed-consumer"
7+
version = "0.1.0"
8+
description = "Fixture: embeds a data file through mcpp.tools.embed"
9+
10+
[language]
11+
standard = "c++23"
12+
modules = true
13+
import_std = true
14+
15+
[dependencies.mcpp]
16+
plugins = { path = "../..", features = ["tools-embed"], host-module = true }
17+
18+
[targets.embed-consumer]
19+
kind = "bin"
20+
main = "src/main.cpp"

tests/embed-consumer/src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <cstddef>
2+
#include <cstdio>
3+
#include "message_txt.h"
4+
5+
int main() {
6+
unsigned sum = 0;
7+
for (std::size_t i = 0; i < fixture::message_txt_size; ++i) sum += fixture::message_txt[i];
8+
std::printf("size=%zu sum=%u text=%s", fixture::message_txt_size, sum,
9+
reinterpret_cast<const char*>(fixture::message_txt));
10+
return fixture::message_txt[fixture::message_txt_size] == 0 ? 0 : 1;
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"index_repos": [
3+
],
4+
"deps": ["xim:glslang@15.1.0"],
5+
"workspace": {
6+
"glslang": "xim:15.1.0"
7+
},
8+
"lang": "en",
9+
"mirror": "auto"
10+
}

0 commit comments

Comments
 (0)