Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0dd1fba
Fetching dependencies: the version table read as the installer reads …
Sunrisepeak Dec 4, 2026
45af1fa
Locks: one wait that reports and is bounded, held told from cannot-lo…
Sunrisepeak Dec 4, 2026
5bdf577
mcpp new makes a git repository: --vcs and [new] vcs override it; non…
Sunrisepeak Dec 4, 2026
6d0ba90
test(e2e): a link and a pack under a caller's XLINGS_SUBOS_LD_PATHS k…
Sunrisepeak Nov 27, 2026
385096f
The command line as its own guide: help from the tree, --agent-skill-…
Sunrisepeak Dec 4, 2026
26fc03a
Build programs take the table a toolchain is named by; a link follows…
Sunrisepeak Dec 4, 2026
3b7cf8a
The std module source is taken inside the toolchain's tree and asked …
Sunrisepeak Dec 4, 2026
2e1fa1d
A toolchain named by path takes what it can do from its statement or …
Sunrisepeak Dec 4, 2026
09c7dbb
A library package describes itself: mcpp-package.json, a .pc per leg,…
Sunrisepeak Dec 4, 2026
f18619e
Workspace selections build one configuration at once: a plan is held …
Sunrisepeak Dec 4, 2026
a567552
test(e2e): the fetch-waves case writes its progress frames without pa…
Sunrisepeak Dec 4, 2026
0fe9704
CPS at mcpp's boundary: a library package writes a .cps per leg; a bu…
Sunrisepeak Dec 4, 2026
5a8f425
Unit tests follow the plan locks; the CPS reason titles are docs/50's
Sunrisepeak Dec 4, 2026
ece7819
Fetch waves cover the project's own index; plan-locks is a shape that…
Sunrisepeak Dec 4, 2026
275e96b
The agent sheets as a network; mcpp info; mcpp add writes full identi…
Sunrisepeak Dec 4, 2026
dd7433d
The CPS adapter states why it is an implementation unit from the stru…
Sunrisepeak Dec 4, 2026
60a7958
Version 2026.12.4.1
Sunrisepeak Dec 4, 2026
fc15c6c
CHANGELOG: on Windows a started program is named as mcpp was given it…
Sunrisepeak Dec 4, 2026
cae55c9
The module probe's cache key names its word in a literal of its own
Sunrisepeak Dec 5, 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
1,696 changes: 1,696 additions & 0 deletions .agents/docs/2026-11-27-ecosystem-boundary-design.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion .agents/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ superseded_by: 2026-09-07-....md # when status is superseded
---
```

375 records.
376 records.

## By subject

Expand Down Expand Up @@ -95,6 +95,7 @@ Records that declare one. Everything else is listed by date below.

### ecosystem

- [生态与外部的交界:工具链的事实、二进制库交付物、被启动的外部程序、名字的拼写与共享的状态](2026-11-27-ecosystem-boundary-design.md) — active
- [包的特性作为机器可读的回答:一个目录项,两种来源,三种状态(mcpp#992)](2026-11-21-package-features-query-design.md) — active
- [离线、宿主输入与工具链的缺省:按内容取归档的来源、项目的取齐、宿主输入的声明、工具链的解析与锁、缺省版本的规则(mcpp#988、#989、#990)](2026-11-21-offline-host-inputs-and-toolchain-defaults-design.md) — active
- [生态规则收敛方案:2026.11.18.1 之后十个 issue 的五类成因、七项决定与实施范围](2026-11-19-ecosystem-rule-convergence-design.md) — landed
Expand Down Expand Up @@ -218,6 +219,7 @@ Records that declare one. Everything else is listed by date below.
### 2026-11

- [陈述的闭包、单一读者与六项功能:十四项缺陷的收敛设计](2026-11-27-stated-closure-single-reader-and-feature-designs.md) — landed
- [生态与外部的交界:工具链的事实、二进制库交付物、被启动的外部程序、名字的拼写与共享的状态](2026-11-27-ecosystem-boundary-design.md) — active
- [clang BMI 的截断与私有模块片段判定的收窄](2026-11-26-clang-bmi-cutoff-and-private-fragment-refinement-design.md) — active
- [测试与 CI 一轮的收尾:平台列未命中的刷新条件(mcpp#996)、`i686-windows-msvc` 行、工作区索引与引号键的迁移、索引的全量验证](2026-11-22-test-round-wrap-up-plan.md) — active
- [生态级方案:内核接口的供给与能力,派生状态的核对,存储的引用](2026-11-22-kernel-interface-and-derived-state-ecosystem-design.md) — active
Expand Down
190 changes: 10 additions & 180 deletions .agents/skills/mcpp-usage/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,189 +1,19 @@
---
name: mcpp-usage
description: Use when helping users install, configure, or use mcpp — the C++23 modular build tool. Covers installation, project creation, building, dependency management, toolchain management, workspace setup, packaging, diagnostics, and troubleshooting.
description: Use when helping users install, configure, or use mcpp - the C++23 modular build tool. The usage lives in docs/mcpp-skills and in the binary.
---

# mcpp 基础用法
# mcpp usage

## Overview
How to use mcpp is stated once, in the sheets under
[`docs/mcpp-skills/`](../../../docs/mcpp-skills/mcpp/SKILL.md), which the build renders into
the binary:

mcpp 是一个现代 C++ 模块化构建工具,纯 C++23 模块编写,已实现自举。一条命令安装,`import std` 开箱即用。

- 仓库:https://github.com/mcpp-community/mcpp
- 文档:https://github.com/mcpp-community/mcpp/tree/main/docs
- 包索引:https://github.com/mcpp-community/mcpp-index
- 模块化库:https://github.com/mcpplibs

## Quick Reference

| 命令 | 用途 |
|---|---|
| `mcpp new <name>` | 创建项目 |
| `mcpp build` | 构建 |
| `mcpp run [-- args]` | 构建并运行 |
| `mcpp test [pattern] [-- args]` | 发现并运行 `tests/**/*.cpp` 测试 |
| `mcpp add <pkg>[@ver]` | 添加依赖 |
| `mcpp remove <pkg>` | 移除依赖 |
| `mcpp update [pkg]` | 更新依赖 |
| `mcpp search <keyword>` | 搜索包 |
| `mcpp toolchain list` | 查看工具链 |
| `mcpp toolchain install gcc 16` | 安装工具链 |
| `mcpp pack` | 打包 |
| `mcpp why [toolchain|runtime|deps]` | 解释解析出的构建决策 |
| `mcpp --offline` | 只使用已有本地状态 |
| `mcpp self doctor` | 环境诊断 |
| `mcpp explain <CODE>` | 错误码解释 |

## 安装

```bash
# 推荐;Windows 请在 PowerShell 中运行
xlings install mcpp -y

# 或 Unix release 一键脚本(仅 Linux x86_64/aarch64 与 macOS ARM64)
curl -fsSL https://github.com/mcpp-community/mcpp/releases/latest/download/install.sh | bash
```

一键脚本不支持 Windows;Windows 使用 PowerShell 的 xlings 安装命令。安装到
`~/.mcpp/` 后会自动加入 PATH。首次使用时,mcpp 按宿主选择默认工具链并
安装到隔离沙盒:Linux 通常为 GCC,macOS 为 LLVM,Windows 在有可用 MSVC
时为 LLVM,否则为面向 `x86_64-windows-gnu` 的 MinGW-w64 GCC。

## 创建项目

```bash
mcpp new hello && cd hello
mcpp build
mcpp run
```

生成的项目包含最小 manifest 和可立即运行的 smoke test:

```toml
[package]
name = "hello"
version = "0.1.0"
description = "A modular C++23 package"
license = "Apache-2.0"
```

`src/main.cpp` 会自动推断为 binary target,`tests/test_smoke.cpp` 会由
`mcpp test` 自动发现;无需手写 `[targets.hello]`。

## mcpp.toml 配置

### 传统头文件库的模块化封装

`mcpplibs.mwrap.<库名>` 为传统 C/C++ 库提供模块入口;API namespace 保留上游,例如
`import mcpplibs.mwrap.opencv.core;` 后仍使用 `cv::Mat`。包版本对齐上游,封装修订最多追加一个数字尾号。
具体已发布的版本/feature 先查索引,不把文档中的候选库当已发布包。

每个新建或重构的 -m 库提供包自带快捷模板:

```bash
mcpp new vision --template mcpplibs.mwrap.opencv@5.0.0.1
mcpp new --list-templates mcpplibs.mwrap.opencv@5.0.0.1
```

模板语法为 `[namespace.]name[@version][:template]`,只有一个默认模板时可以省略模板名。
包模板中的 `{{self.name}}` 是完整包选择器,应用 `"{{self.name}}"` 作为单个依赖 key,
不要放到另一层 namespace 表下。模板必须实际创建、构建、运行,而不只做字符串检查。

feature 是加法并集;消费者可在依赖声明中使用 `default-features = false` 关闭该边的默认集合,
显式 features 仍会启用,其他依赖边的请求不会被取消。根项目没有 `--no-default-features` 命令行选项。
可选大依赖由包作者显式门控。模块可导入不等于实际后端已启用,窗口/推理/设备能力需分别验证。
宏不能经 import 传递;`.macros` 只提供可保持语义的常量/函数映射,原始宏仍需兼容头。

维护规范与包装流程见 [mcpp-index mwrap 规范](https://github.com/mcpplibs/mcpp-index/blob/main/docs/mwrap.md)。
修改普通消费者项目时按现有包契约使用,不自动替用户迁移其他依赖。

```toml
[package]
name = "myapp"
version = "0.1.0"

[targets.myapp]
kind = "bin" # bin / lib / shared; tests are discovered from tests/**/*.cpp
main = "src/main.cpp"

[dev-dependencies]
gtest = "1.15.2" # 仅测试使用;SemVer: ^, ~, 范围, 精确

[toolchain]
default = "gcc@16.1.0"
```

更多配置:https://github.com/mcpp-community/mcpp/blob/main/docs/04-mcpp-toml.md

## 工具链

```bash
mcpp toolchain list # 查看已装
mcpp toolchain install gcc 16 # 装 GCC 16
mcpp toolchain install llvm 20 # 装 LLVM 20
mcpp toolchain default gcc@16.1.0 # 设默认
mcpp build --target x86_64-linux-musl # 需要全静态 Linux 产物时显式选择
```

## 测试结果与按用例运行

`mcpp test --message-format json` 每个测试一条 NDJSON 记录(通过的也带 `run_output`),最后是每个成员的
`summary`。`status` 取 `pass`、`compile_fail`、`run_fail`(`timed_out` 为真即超时)、`not_run`(带 `reason`)、
`built`(`--no-run`);退出码 0 为全部通过,1 为有测试失败,2 为有测试未能运行。

mcpp 的单位是测试程序;用例属于测试框架。按用例运行时,把框架的参数放在 `--` 之后:

```bash
mcpp test unit/math -- --gtest_filter='Math.Adds:Math.Spans' # GoogleTest 只跑这两个用例
mcpp test unit/math -- --gtest_output=json:"$PWD/math-report.json" # 每个用例的结果写成 JSON 报告
mcpp test unit/math --print-launch -- --gtest_filter='Math.Adds' # 只构建,打印启动方式(argv、cwd、环境),供调试器使用
```

读取用例结果时以框架报告为准(GoogleTest 的 `--gtest_output=json`、Catch2 的 `--reporter json`),程序输出中
`[ RUN ] X` 与 `[ OK ] X` / `[ FAILED ] X` 之间是用例 X 的输出。

## 工作空间

```toml
[workspace]
members = ["libs/*", "apps/*"]

[workspace.dependencies]
gtest = "1.15.2"
```

```bash
mcpp build -p member-name # 构建指定成员
mcpp --agent-skill-doc # the root sheet and an index of the commands' sheets
mcpp <command> --agent-skill-doc # one command's sheet
```

## 自定义索引

```toml
[indices]
my-index = "git@gitlab.example.com:team/index.git"
local = { path = "/path/to/index" }

[dependencies.my-index]
internal-lib = "1.0.0"
```

## 常见问题

| 问题 | 解决 |
|---|---|
| 首次构建慢 | 正常,需下载工具链。后续使用缓存 |
| command not found | 重开终端。Unix release 安装脚本应确认 `~/.mcpp/bin` 在当前 shell 的 `PATH` 中;经 xlings 安装则确认 xlings 当前激活的 bin 目录。Windows 不要执行 `source`,重开 PowerShell 后用 `Get-Command mcpp.exe` 验证命令已激活。 |
| 编译错误 | `mcpp clean && mcpp build`,确认 `mcpp toolchain list` |
| 依赖找不到 | `mcpp index update`,确认 `mcpp search <name>` |
| 需要无网络构建 | 使用 `mcpp --offline` 或设置 `MCPP_OFFLINE=1`;缺失的工具链/依赖会直接报错 |

## 问题反馈

1. **项目 Issue**:https://github.com/mcpp-community/mcpp/issues
- 描述复现步骤、期望/实际行为、mcpp 版本和 OS
- 可用 `gh issue create` 提交

2. **社区论坛**:https://forum.d2learn.org/category/20
- 使用疑问和讨论

如果 AI Agent 无法直接创建 Issue,请提示用户手动创建并提供整理好的问题描述。
Install mcpp with `xlings install mcpp -y`, or on Linux and macOS with
`curl -fsSL https://github.com/mcpp-community/mcpp/releases/latest/download/install.sh | bash`.
The user documentation is [`docs/`](../../../docs/README.md).
3 changes: 3 additions & 0 deletions .github/tools/build_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ BUILD=(
# vocabulary, and the example's README records the measured artifacts and
# the emulator run for the binary it describes.
examples/13-platform-targets
# A package another build system installed, read through its CPS
# description by `mcpp::cps_package`: header-only, so the prefix is text.
examples/14-cps/app
)

# `key|reason`.
Expand Down
49 changes: 49 additions & 0 deletions .github/tools/check_stderr_writers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# The narrative stream has one writer (design 2026-11-27, ecosystem boundary §3.11.2 point 4).
#
# A line written to standard error outside mcpp.ui and mcpp.log does not erase the live region
# first and does not redraw it: the region's bookkeeping is one line short, and the line above it
# (a progress bar) stays on the screen. Measured 2026-12-04: the provider's `Source <package>
# <host>` line, written once per download, left one stale progress bar per dependency.
#
# Each file's count of direct writes to standard error is at most its line in
# stderr-writers.baseline, and a file not listed has none. The baseline only falls; the
# fetch, prepare and build paths of the process that draws the live region are not on it.
# The programs ninja starts (compiler supervisors, link-output and the other internal
# commands) write to their own standard error, which the build captures; they are listed.
set -u
cd "$(dirname "$0")/../.."

baseline=.github/tools/stderr-writers.baseline
[ -f "$baseline" ] || { echo "::error::missing $baseline"; exit 1; }

pattern='libc::stderr\(\)|std::cerr|[(,][[:space:]]*stderr[[:space:]]*[,)]|STDERR_FILENO'
current=$(grep -rnE "$pattern" src modules --include='*.cppm' --include='*.cpp' \
| grep -vE '^(src/ui\.cppm|src/ui/[^:]*|modules/log/src/[^:]*|modules/[^/]+/tests/[^:]*):' \
| grep -vE '^[^:]+:[0-9]+:[[:space:]]*//' \
| cut -d: -f1 | sort | uniq -c | awk '{ print $2, $1 }')

rc=0
while read -r file n; do
[ -n "$file" ] || continue
allowed=$(awk -v f="$file" '$1 == f { print $2 }' "$baseline")
if [ -z "$allowed" ]; then
echo "::error::$file writes to standard error directly $n time(s); write through mcpp::ui (status, info, block, error) or mcpp::diag"
rc=1
elif [ "$n" -gt "$allowed" ]; then
echo "::error::$file writes to standard error directly $n times, more than the $allowed of $baseline"
rc=1
elif [ "$n" -lt "$allowed" ]; then
echo "::error::$file writes to standard error directly $n times, fewer than the $allowed of $baseline; lower its line"
rc=1
fi
done <<< "$current"
while read -r file allowed; do
case "$file" in ''|'#'*) continue ;; esac
if ! grep -q "^$file " <<< "$current"; then
echo "::error::$file no longer writes to standard error directly; remove its line from $baseline"
rc=1
fi
done < "$baseline"
[ "$rc" = 0 ] && echo "OK: standard error is written through mcpp.ui and mcpp.log, and $baseline is exact"
exit "$rc"
21 changes: 21 additions & 0 deletions .github/tools/stderr-writers.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# One line per source file that writes to standard error without mcpp.ui or mcpp.log: its count
# (.github/tools/check_stderr_writers.sh). The numbers only fall.
src/build/execute.cppm 47
src/build/schedule/compiler_transaction.cppm 1
src/build/schedule/detach_codegen.cppm 41
src/cli/cmd_build.cppm 53
src/cli/cmd_cache.cppm 1
src/cli/cmd_new.cppm 1
src/cli/cmd_publish.cppm 4
src/cli/cmd_registry.cppm 2
src/cli/cmd_self.cppm 7
src/cli/cmd_toolchain.cppm 1
src/cli/cmd_xpkg.cppm 1
src/cli.cppm 15
src/config.cppm 3
src/doctor.cppm 5
src/fallback/xlings_binary.cppm 4
src/main.cpp 1
src/pack/distribution.cppm 5
src/publish/pipeline.cppm 6
src/run/run.cpp 6
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ jobs:
- name: Check that every warning and note goes through mcpp.diag
run: bash .github/tools/check_diag_sink.sh

- name: Check that standard error is written through mcpp.ui and mcpp.log
run: bash .github/tools/check_stderr_writers.sh

- name: Check that the engine's sources name no more systems than the baseline
run: python3 .github/tools/check_system_names.py

Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ linked document holds.
| [`docs/`](docs/README.md), [`docs/zh/`](docs/zh/README.md) | how to use what mcpp implements | describes the current implementation only; English and Chinese stay in parity |
| [`docs/specs/`](docs/specs/README.md) | semantics and constraints (SPEC-001 to SPEC-016) | RFC 2119 wording; every clause carries its implementation status and the version it holds from |
| [`.agents/docs/`](.agents/docs/README.md) | design records: measurements, decisions, what was refuted | front matter `subject`, `status`; the index is generated (`.github/tools/gen_agents_index.py`) |
| [`.agents/skills/`](.agents/skills/) | procedures: [contributing](.agents/skills/mcpp-contributing/SKILL.md), [docs style](.agents/skills/mcpp-docs-style/SKILL.md), [release](.agents/skills/mcpp-release/SKILL.md), [usage](.agents/skills/mcpp-usage/SKILL.md) | ordered steps with criteria |
| [`.agents/skills/`](.agents/skills/) | procedures: [contributing](.agents/skills/mcpp-contributing/SKILL.md), [docs style](.agents/skills/mcpp-docs-style/SKILL.md), [release](.agents/skills/mcpp-release/SKILL.md), [usage](.agents/skills/mcpp-usage/SKILL.md) (a pointer to [`docs/mcpp-skills/`](docs/mcpp-skills/mcpp/SKILL.md), the sheets `--agent-skill-doc` prints) | ordered steps with criteria |
| [`CHANGELOG.md`](CHANGELOG.md) | one section per release; release.yml publishes it as the release notes | English, Keep a Changelog |

A change of behaviour updates the spec clause, the usage chapter in both languages and the
Expand Down
Loading
Loading