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
120 changes: 120 additions & 0 deletions .agents/docs/2026-12-01-add-beman-execution-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Add beman.execution 0.3.0

## Source and package shape

Pin the requested upstream tag `v0.3.0` of `bemanproject/execution`
(commit `4547d215acbbd2e5bea06e9fdd0c47c5655961ec`).
The release archive contains C++23 headers and 222 native module units.
The upstream license is `Apache-2.0 WITH LLVM-exception`.

Register two consumption contracts:

- `compat.beman-execution@0.3.0`: upstream's header-only interface,
exposing `*/include` and a generated C anchor for mcpp's library target.
- `beman.execution@0.3.0`: upstream's native `beman.execution` and
`beman.execution.detail` modules, compiling the 221 module units listed by
upstream CMake and the upstream `execution.cpp` translation unit. Set
`BEMAN_HAS_MODULES`, `BEMAN_HAS_IMPORT_STD`, the default parallel backend
and disabled GCD support for package compilation, as in upstream's CMake setup.

No handwritten facade or renamed upstream module is introduced. Examples and
upstream tests are not library sources.

## Module scanner adaptation

Mcpp's M1 scanner forbids imports inside preprocessor conditionals and does not
discover dependencies imported by included headers. Three upstream units have
conditional `import std`; their enabled branch must be selected. The install
hook reads upstream's CMake source list (xlings' restricted Lua has no
`os.files`) and writes adapted module units to `mcpp_generated/`. The original
source and headers remain intact.

The hook gathers module dependencies from each unit and its directly included
upstream headers, strips comments and disabled `#if 0` blocks from dependency
discovery, and inserts explicit imports after the original global-fragment
headers. Keeping that order matters: importing `std` before `<version>` can
produce libstdc++ redefinitions. The module declaration and every subsequent
export remain unchanged. The empty generated-source set invokes the hook on a
fresh installation. No Python or host compiler is required by the hook.

The archive's extra `split.cppm` is not in upstream's CMake target and is not
built; the umbrella unit mentions its import only in a TODO comment.

## Integrity, mirrors and updates

Official archive:
`https://github.com/bemanproject/execution/archive/refs/tags/v0.3.0.tar.gz`

SHA256 (computed twice):
`0d39803334acca5177ce5bde306a4260eed5b4d1df8c690d4cd50144e793ac28`

Linux, macOS and Windows use the same upstream source archive. No verified
GitCode mirror is available; use the permitted plain upstream URL instead of
declaring a speculative CN endpoint.

Both descriptors declare the upstream numeric `v` tag rule and archive URL
for automatic updates. The workflow-pinned updater
`6c0bee2941e36132bc2ac3d1f7edbef8b5790320` reports `up-to-date` at `0.3.0`
for both packages. The initial unauthenticated API request hit GitHub's rate
limit; the authenticated read-only check succeeded.

## Features

Keep the upstream default parallel scheduler backend enabled. The library is
header-only in the compat contract, so its default backend needs no separately
compiled source feature. GCD support remains at upstream's default (off);
adding a libdispatch dependency and platform feature is outside this change.
Exceptions and RTTI retain upstream defaults.

## Consumers

Register `beman-execution` and `beman-execution-module` as workspace members.
Both pin exactly `=0.3.0` and redirect only their own dependency namespace to
this checkout. Each consumer checks transformed values, `when_all`, stopped
completion, exception propagation, stop callback delivery and execution on a
parallel scheduler worker. Any failed condition makes the executable fail.

## Validation environment

Container: `mcpp-index-beman-execution`, based on the locally available
`coio:latest` Arch Linux image. Limit the entire container to four CPUs and
6 GiB RAM, with build concurrency `MCPP_JOBS=2`. Mount the checkout at
`/workspace/mcpp-index`. Use CI-pinned mcpp `2026.11.23.1` and an isolated
home `/opt/mcpp/home`, using the GLOBAL index mirror and GCC `16.2.0`.

Windows bind-mount metadata operations were slow. The complete tracked baseline
and byte-identical candidate files were copied to `/work/mcpp-index` on the
container's Linux filesystem for module verification and the final combined run.
The original mounted checkout retains all changes and validation logs. The
container has a `mcpp` command and persistent shell environment configured.

The Windows checkout has CRLF shell scripts. Run the unchanged shared runner
through `bash <(tr -d '\r' < tests/run_members.sh)` inside the container.

Validation completed on December 1, 2026:

- Both descriptors pass `mcpp xpkg parse`, Lua syntax, mirror URL, package name,
reserved namespace, platform version parity and duplicate-version checks.
- The full index passes Lua syntax and cross-package-reference lint.
- `tests/select_members.py` selects exactly `beman-execution` and
`beman-execution-module`. It also reports existing unrelated upstream manifest
warnings; neither new package is missing a consumer.
- The header consumer passes: `1 passed; 0 failed`.
- A fresh project package store invokes the module install hook and the module
consumer passes: `1 passed; 0 failed`.
- The shared runner then executes both consumers in sequence successfully;
the module package reuses 222 compiled units (221 modules plus execution.cpp).
- Both locks select exactly `0.3.0`; both authenticated updater checks report
`up-to-date`.

Reproduce inside the running container:

```sh
docker exec -it -w /work/mcpp-index mcpp-index-beman-execution bash
mcpp test -p beman-execution
mcpp test -p beman-execution-module
```

Logs are in the mounted checkout's `target/package-validation/` directory,
especially `header-test.log`, `module-test-native.log` and `combined-test.log`.
Windows and macOS runtime tests require their native CI runners.
2 changes: 2 additions & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ members = [
"tests/examples/accesskit",
"tests/examples/asio-module",
"tests/examples/asio-ssl",
"tests/examples/beman-execution",
"tests/examples/beman-execution-module",
"tests/examples/binary_tree-module",
"tests/examples/boost-asio",
"tests/examples/boost-any",
Expand Down
118 changes: 118 additions & 0 deletions pkgs/b/beman.execution.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
-- Upstream v0.3.0: native C++23 module units.
-- No verified CN mirror is available; CN clients fall back to upstream.
package = {
spec = "1",
namespace = "beman",
name = "execution",
description = "Beman P2300 sender/receiver execution library (native modules)",
licenses = {"Apache-2.0 WITH LLVM-exception"},
repo = "https://github.com/bemanproject/execution",
type = "package",
extensions = {
autoupdate = {
tag = "v${version}",
url = "https://github.com/bemanproject/execution/archive/refs/tags/${tag}.tar.gz",
},
},
xpm = {
linux = {
["0.3.0"] = {
url = "https://github.com/bemanproject/execution/archive/refs/tags/v0.3.0.tar.gz",
sha256 = "0d39803334acca5177ce5bde306a4260eed5b4d1df8c690d4cd50144e793ac28",
},
},
macosx = {
["0.3.0"] = {
url = "https://github.com/bemanproject/execution/archive/refs/tags/v0.3.0.tar.gz",
sha256 = "0d39803334acca5177ce5bde306a4260eed5b4d1df8c690d4cd50144e793ac28",
},
},
windows = {
["0.3.0"] = {
url = "https://github.com/bemanproject/execution/archive/refs/tags/v0.3.0.tar.gz",
sha256 = "0d39803334acca5177ce5bde306a4260eed5b4d1df8c690d4cd50144e793ac28",
},
},
},
mcpp = {
language = "c++23",
include_dirs = { "*/include" },
import_std = true,
modules = { "beman.execution", "beman.execution.detail" },
cxxflags = {
"-DBEMAN_HAS_MODULES",
"-DBEMAN_HAS_IMPORT_STD",
"-DBEMAN_EXECUTION_WITH_DEFAULT_PARALLEL_SCHEDULER_BACKEND=1",
"-DBEMAN_EXECUTION_WITH_GCD_SUPPORT=0",
},
-- Generated by install() from upstream; an empty source set triggers
-- the install hook before the module scanner runs.
sources = { "mcpp_generated/*.cppm", "mcpp_generated/execution.cpp" },
targets = { ["beman_execution"] = { kind = "lib" } },
deps = { },
},
}

-- Upstream imports dependencies from headers. M1 scans module units, so make
-- those edges explicit in the global module fragment after the same headers.
-- The original module identities, declarations and export lists are preserved.
import("xim.libxpkg.pkginfo")
import("xim.libxpkg.log")

function install()
local source = "execution-" .. pkginfo.version()
local prefix = pkginfo.install_dir()
os.tryrm(prefix)
os.mkdir(prefix)
local root = path.join(prefix, source)
os.mv(source, root)

os.mkdir(path.join(prefix, "mcpp_generated"))
-- xlings' restricted Lua has no os.files; upstream's CMake file is the
-- authoritative, cross-platform list of module units.
local units, seen = {}, {}
local cmake = io.readfile(path.join(root, "src/beman/execution/CMakeLists.txt"))
for name in cmake:gmatch("([%w_%-]+%.cppm)") do
if not seen[name] then
units[#units + 1] = name
seen[name] = true
end
end
if #units == 0 then
log.error("beman.execution: no upstream module units found")
return false
end
for _, name in ipairs(units) do
local filename = path.join(root, "src/beman/execution", name)
local body = io.readfile(filename)
-- Select the branch enabled by BEMAN_HAS_IMPORT_STD; M1 forbids a
-- lexical import inside conditional preprocessor blocks.
body = body:gsub(
"#ifdef BEMAN_HAS_IMPORT_STD[\r\n]+import std;[\r\n]+#else.-#endif",
"import std;")
local own = body:match("export%s+module%s+([%w_%.]+)")
local imports = {}
local function collect(text)
text = text:gsub("/%*.-%*/", ""):gsub("//[^\r\n]*", "")
text = text:gsub("#if%s+0[\r\n].-#endif", "")
for name in text:gmatch("import%s+([%w_%.]+)%s*;") do
if name ~= own then imports[name] = true end
end
end
collect(body)
for include in body:gmatch("#include%s+<([^>]+)>") do
local header = path.join(root, "include", include)
if os.isfile(header) then collect(io.readfile(header)) end
end
local names = {}
for name in pairs(imports) do names[#names + 1] = name end
table.sort(names)
local lines = {}
for _, name in ipairs(names) do lines[#lines + 1] = "import " .. name .. ";" end
body = body:gsub("export%s+module", table.concat(lines, "\n") .. "\n\nexport module", 1)
io.writefile(path.join(prefix, "mcpp_generated", name), body)
end
os.cp(path.join(root, "src/beman/execution/execution.cpp"),
path.join(prefix, "mcpp_generated/execution.cpp"))
return true
end
49 changes: 49 additions & 0 deletions pkgs/c/compat.beman-execution.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- Upstream v0.3.0: header-only target with a trivial C anchor.
-- No verified CN mirror is available; CN clients fall back to upstream.
package = {
spec = "1",
namespace = "compat",
name = "beman-execution",
description = "Beman P2300 sender/receiver execution library (C++23 headers)",
licenses = {"Apache-2.0 WITH LLVM-exception"},
repo = "https://github.com/bemanproject/execution",
type = "package",
extensions = {
autoupdate = {
tag = "v${version}",
url = "https://github.com/bemanproject/execution/archive/refs/tags/${tag}.tar.gz",
},
},
xpm = {
linux = {
["0.3.0"] = {
url = "https://github.com/bemanproject/execution/archive/refs/tags/v0.3.0.tar.gz",
sha256 = "0d39803334acca5177ce5bde306a4260eed5b4d1df8c690d4cd50144e793ac28",
},
},
macosx = {
["0.3.0"] = {
url = "https://github.com/bemanproject/execution/archive/refs/tags/v0.3.0.tar.gz",
sha256 = "0d39803334acca5177ce5bde306a4260eed5b4d1df8c690d4cd50144e793ac28",
},
},
windows = {
["0.3.0"] = {
url = "https://github.com/bemanproject/execution/archive/refs/tags/v0.3.0.tar.gz",
sha256 = "0d39803334acca5177ce5bde306a4260eed5b4d1df8c690d4cd50144e793ac28",
},
},
},
mcpp = {
language = "c++23",
include_dirs = { "*/include" },
import_std = false,
c_standard = "c11",
generated_files = {
["mcpp_generated/beman_execution_anchor.c"] = "int mcpp_compat_beman_execution_anchor(void) { return 0; }\n",
},
sources = { "mcpp_generated/beman_execution_anchor.c" },
targets = { ["beman_execution_headers"] = { kind = "lib" } },
deps = { },
},
}
9 changes: 9 additions & 0 deletions tests/examples/beman-execution-module/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "beman-execution-module-tests"
version = "0.1.0"

[dependencies.beman]
execution = "=0.3.0"

[indices]
beman = { path = "../../.." }
50 changes: 50 additions & 0 deletions tests/examples/beman-execution-module/tests/execution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import std;
import beman.execution;

namespace ex = beman::execution;

int main() {
bool ok = true;
auto check = [&](bool condition, const char* message) {
if (!condition) {
std::cerr << "FAIL: " << message << '\n';
ok = false;
}
};
auto value = ex::sync_wait(ex::just(20) | ex::then([](int n) { return n * 2 + 2; }));
check(value.has_value() && std::get<0>(*value) == 42, "just/then transforms a value");
auto joined = ex::sync_wait(ex::when_all(ex::just(17), ex::just(25)));
check(joined.has_value() && std::get<0>(*joined) + std::get<1>(*joined) == 42,
"when_all delivers both values");
bool ran = false;
auto stopped = ex::sync_wait(ex::just_stopped()
| ex::then([&] { ran = true; })
| ex::let_stopped([] { return ex::just(-1); }));
check(stopped.has_value() && std::get<0>(*stopped) == -1 && !ran,
"stopped completion skips then and reaches let_stopped");
bool caught = false;
try {
(void)ex::sync_wait(ex::just(0) | ex::then([](int) -> int {
throw std::runtime_error("execution test");
}));
} catch (const std::runtime_error& error) {
caught = std::string_view(error.what()) == "execution test";
}
check(caught, "error completion rethrows the original exception");
ex::inplace_stop_source source;
int callbacks = 0;
{
ex::inplace_stop_callback callback(source.get_token(), [&] { ++callbacks; });
check(!source.stop_requested(), "stop source initially not requested");
check(source.request_stop(), "first stop request succeeds");
check(!source.request_stop(), "second stop request does not repeat");
check(source.get_token().stop_requested() && callbacks == 1, "stop callback runs once");
}
auto main_thread = std::this_thread::get_id();
auto scheduled = ex::sync_wait(ex::schedule(ex::get_parallel_scheduler())
| ex::then([] { return std::this_thread::get_id(); }));
check(scheduled.has_value() && std::get<0>(*scheduled) != main_thread,
"default parallel scheduler executes on a worker");
if (ok) std::cout << "beman.execution 0.3.0 OK\n";
return ok ? 0 : 1;
}
9 changes: 9 additions & 0 deletions tests/examples/beman-execution/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "beman-execution-tests"
version = "0.1.0"

[dependencies.compat]
beman-execution = "=0.3.0"

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