@chengzhao-dev/dsh-cpp-workflow 0.7.6 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/package.json +1 -1
- package/skills/building-cpp/SKILL.md +2 -2
- package/skills/building-cpp/assets/config/.clang-format +8 -8
- package/skills/building-cpp/assets/config/.clang-tidy +0 -4
- package/skills/building-cpp/assets/templates/projects/common/running-build.sh +42 -42
- package/skills/building-cpp/assets/templates/projects/multi/CMakeLists.txt +5 -5
- package/skills/building-cpp/assets/templates/projects/multi/include/greeting.h +1 -4
- package/skills/building-cpp/assets/templates/projects/multi/src/greeting.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/multi/src/main.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/shared-library/CMakeLists.txt +5 -5
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt +8 -8
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/include/greeting.h +1 -4
- package/skills/building-cpp/assets/templates/projects/shared-library/greeting/src/greeting.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/shared-library/src/main.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/single/CMakeLists.txt +3 -3
- package/skills/building-cpp/assets/templates/projects/single/src/main.cpp +4 -4
- package/skills/building-cpp/assets/templates/projects/static-library/CMakeLists.txt +3 -3
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt +8 -8
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/include/greeting.h +1 -4
- package/skills/building-cpp/assets/templates/projects/static-library/greeting/src/greeting.cpp +2 -2
- package/skills/building-cpp/assets/templates/projects/static-library/src/main.cpp +2 -2
- package/skills/building-cpp/references/02-environment.md +4 -4
- package/skills/building-cpp/steps/01-build.md +1 -1
- package/skills/building-cpp/steps/02-tooling.md +2 -2
- package/skills/building-cpp/steps/03-check.md +2 -0
- package/skills/building-cpp/steps/04-vscode.md +1 -1
- package/skills/developing-cpp/SKILL.md +2 -2
- package/skills/developing-cpp/references/comments/02-style.md +3 -2
- package/skills/developing-cpp/references/design/session-layer.md +10 -10
- package/skills/developing-cpp/references/index.md +4 -4
- package/skills/developing-cpp/references/language/glossary/01-language-terms.md +1 -1
- package/skills/developing-cpp/references/layout/01-source-layout.md +1 -1
- package/skills/developing-cpp/references/layout/02-file-template.md +24 -38
- package/skills/developing-cpp/references/layout/03-declaration-order.md +3 -6
- package/skills/developing-cpp/references/naming/01-identifier-names.md +7 -1
- package/skills/developing-cpp/references/style/01-google-cpp-style.md +4 -4
- package/skills/developing-cpp/scripts/checking-comments.mjs +23 -2
- package/skills/developing-cpp/steps/03-declaration.md +1 -1
- package/skills/engineering/SKILL.md +5 -5
- package/skills/engineering/references/cmake/assets/CompileSettings.cmake +100 -100
- package/skills/engineering/references/cmake/assets/LinkSettings.cmake +25 -25
- package/skills/engineering/references/cmake/assets/OutputSettings.cmake +38 -0
- package/skills/engineering/references/cmake/linking/01-libraries.md +1 -1
- package/skills/engineering/references/cmake/modules/01-functions.md +3 -2
- package/skills/engineering/references/cmake/standards/c++11/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++14/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++17/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++20/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/c++23/cmake-snippet.cmake +3 -3
- package/skills/engineering/references/cmake/standards/index.md +2 -2
- package/skills/engineering/references/cmake/standards/versions.md +1 -1
- package/skills/engineering/references/cmake/targets/01-target-rules.md +7 -7
- package/skills/engineering/references/formatting/01-encoding.md +4 -1
- package/skills/engineering/references/formatting/02-clang-format.md +1 -1
- package/skills/engineering/references/formatting/03-clang-tidy.md +2 -2
- package/skills/engineering/references/formatting/04-clangd.md +2 -2
- package/skills/engineering/references/formatting/examples/01-clang-format.md +2 -2
- package/skills/engineering/references/index.md +2 -2
- package/skills/engineering/steps/01-targets.md +3 -3
- package/skills/engineering/steps/02-modules.md +1 -1
- package/skills/engineering/steps/03-check.md +1 -1
- package/templates/cpp-workflow-project/SKILL.md +3 -2
package/README.en.md
CHANGED
|
@@ -66,9 +66,9 @@ Keep one `environment.json` per repository. Its first three environment axes are
|
|
|
66
66
|
| `compiler` | `clang`, `gcc` | One compiler per configuration |
|
|
67
67
|
| `standard` | `c++11`, `c++14`, `c++17`, `c++20`, `c++23` | New projects default to `c++23`; one standard per project |
|
|
68
68
|
|
|
69
|
-
The standard lives in `environment.json` as `standard` and must match the CMake target and compile database; on the CMake side, prefer `engineering`'s `
|
|
69
|
+
The standard lives in `environment.json` as `standard` and must match the CMake target and compile database; on the CMake side, prefer `engineering`'s `set_target_cxx_standard` function. New projects default to C++23; for C++11–C++20, lower `standard`, `cxx_std_*`, `CXX_STANDARD`, and the `.clang-format` parsing level together, not one at a time. Per-standard facilities, tooling, and downgrade tables are in the [standard directory](skills/engineering/references/cmake/standards/index.md); the CMake two-layer declaration is in [01-cxx-standard.md](skills/engineering/references/cmake/standards/01-cxx-standard.md).
|
|
70
70
|
|
|
71
|
-
The generator is always Ninja. Build directories
|
|
71
|
+
The generator is always Ninja. Build directories default to `build/clang/` and `build/gcc/` and are never shared; a project skill may declare a single build directory (this book uses `games/tictactoe/build/`). Analysis tools are always `clang-format`, `clang-tidy`, and `clangd`; GCC mode does not switch to another analyzer.
|
|
72
72
|
|
|
73
73
|
Run the declaration check first, then the live check on the build host. `<skill-dir>` is the installed `building-cpp` directory, not a directory in the target project:
|
|
74
74
|
|
package/README.md
CHANGED
|
@@ -66,9 +66,9 @@ dsh plugin --profile <profile> add github:chengzhao-dev/dsh-cpp-workflow#v0.7.6
|
|
|
66
66
|
| `compiler` | `clang`、`gcc` | 一次配置一个编译器 |
|
|
67
67
|
| `standard` | `c++11`、`c++14`、`c++17`、`c++20`、`c++23` | 新工程默认 `c++23`;一个工程一个标准 |
|
|
68
68
|
|
|
69
|
-
标准写在 `environment.json` 的 `standard`,并同步到 CMake target 和编译数据库;CMake 侧优先调用 `engineering` 提供的 `
|
|
69
|
+
标准写在 `environment.json` 的 `standard`,并同步到 CMake target 和编译数据库;CMake 侧优先调用 `engineering` 提供的 `set_target_cxx_standard` 函数。新工程默认 C++23;C++11–C++20 工程把 `standard`、`cxx_std_*`、`CXX_STANDARD` 和 `.clang-format` 的解析档位一起降级,不要只改一处。每档的设施、工具和降档表见 [标准目录](skills/engineering/references/cmake/standards/index.md),CMake 两层声明见 [01-cxx-standard.md](skills/engineering/references/cmake/standards/01-cxx-standard.md)。
|
|
70
70
|
|
|
71
|
-
生成器固定 Ninja
|
|
71
|
+
生成器固定 Ninja,默认构建目录是 `build/clang/` 与 `build/gcc/`,不共用同一目录;项目技能声明单一构建目录时(本书 `games/tictactoe/build/`)以项目为准。诊断工具固定 `clang-format`、`clang-tidy`、`clangd`;GCC 模式也不换成别的分析器。
|
|
72
72
|
|
|
73
73
|
构建前先跑声明校验,再在构建宿主上跑活动校验。`<skill-dir>` 是插件安装后的 `building-cpp` 目录,不是目标工程里的目录:
|
|
74
74
|
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ metadata:
|
|
|
16
16
|
- **交接**:一次改动同时碰到源码和构建文件时,先开 `developing-cpp` 定行为、边界与实现;需要新增或移动源文件、改库与程序的边界、补测试 target 时,转 `engineering` 把文件写进 CMake;最后回到本技能定工具配置并通过检查。只改函数体、命名、异常或注释且入口命令可运行时,定实现后只开本技能的通过检查。
|
|
17
17
|
- **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。三个环境轴为空、`standard` 非法或组合非法时停在定构建,不猜 WSL、Clang 或构建目录;`standard` 缺失或为空时按默认 `c++23` 继续并提示声明升级;`windows` + `native` 直接拒绝,提示「本版本不能在 Windows 原生壳里构建」,不给补 PowerShell 的路线。
|
|
18
18
|
- **分因**:编译失败时先看诊断指向哪一层。函数体问题回 `developing-cpp` 的定实现;找不到头、链接失败、target 不存在或标准不对转 `engineering` 的对应步骤;没有编译数据库、format/tidy 不在 PATH 或配置不生效留在本技能的定工具配置。
|
|
19
|
-
- **编码**:源码与构建文件用 UTF-8 无 BOM、检出 LF,`.bat` / `.cmd` 用 CRLF,`.clang-format` 写 `LineEnding: LF`;MSVC
|
|
19
|
+
- **编码**:源码与构建文件用 UTF-8 无 BOM、检出 LF,`.bat` / `.cmd` 用 CRLF,`.clang-format` 写 `LineEnding: LF`;MSVC 不是受支持的环境轴;`/utf-8` 配方只留在资产注释里,当前构建仍用 clang/gcc。完整规则见 `../engineering/references/formatting/01-encoding.md`,机器规则以仓库根 `.gitattributes` 与 `.editorconfig` 为准。
|
|
20
20
|
- **编辑器**:工程根已有 `.vscode/` 时按 `steps/04-vscode.md` 接线;从当前目录向上到 git 根都没有 `.vscode/` 时不打开、也不新建。配置、构建、运行和调试都从 CMake Tools 进入,构建仍以 `running-build.sh` 为准。
|
|
21
21
|
|
|
22
22
|
## 三种操作
|
|
@@ -78,7 +78,7 @@ metadata:
|
|
|
78
78
|
|
|
79
79
|
- [ ] 项目 `environment.json` 的三个环境轴齐全且是合法组合,`standard` 在 `c++11`–`c++23` 内;新工程默认 `c++23`,没有靠猜。
|
|
80
80
|
- [ ] 配置命令固定 Ninja 和单一编译器,`build/<compiler>/compile_commands.json` 存在,根 `build/compile_commands.json` 指向当前编译器。
|
|
81
|
-
- [ ] target 契约已经成立:程序 `app
|
|
81
|
+
- [ ] target 契约已经成立:程序 target(模板默认 `app`,本书 `terminal`)、库 target、公共 include、标准与输出目录都已由 `engineering` 写好;本技能没有偷偷改 CMake 来绕过失败。
|
|
82
82
|
- [ ] `clang-format --dry-run --Werror` 与 `clang-tidy` 在项目源码上零告警;只扫描项目源码和项目头。
|
|
83
83
|
- [ ] CTest 全绿,程序从该编译器的构建目录启动;有测试时注册用 `gtest_discover_tests` 或项目既有机制,运行带 `--output-on-failure --no-tests=error`,失败时报告的是具体角色和原因。
|
|
84
84
|
- [ ] 没有改源码语义,没有覆盖已有工程文件,也没有安装或下载任何工具。
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
# C++ 代码排版配置。
|
|
2
2
|
#
|
|
3
|
-
# Google 基线,缩进用
|
|
3
|
+
# Google 基线,缩进用 4 个空格,对齐用空格,列宽 120。
|
|
4
4
|
|
|
5
5
|
# 只处理 C++ 源文件。
|
|
6
6
|
Language: Cpp
|
|
7
|
-
#
|
|
7
|
+
# 只覆盖本文件写出的项,其余沿用预设。
|
|
8
8
|
BasedOnStyle: Google
|
|
9
9
|
# 工具不接受 c++23 取值,改用 Latest 跟随其支持的最高标准。
|
|
10
10
|
Standard: Latest
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# include 保持现有空行分组,组内按 Google 预设排序。
|
|
13
13
|
IncludeBlocks: Preserve
|
|
14
14
|
|
|
15
15
|
# 每行最多 120 列。
|
|
16
16
|
ColumnLimit: 120
|
|
17
|
-
# 一级缩进 4
|
|
17
|
+
# 一级缩进 4 个空格。
|
|
18
18
|
IndentWidth: 4
|
|
19
|
-
# Tab 按 4
|
|
19
|
+
# Tab 按 4 列显示,只用于阅读既有文件。
|
|
20
20
|
TabWidth: 4
|
|
21
|
-
#
|
|
22
|
-
UseTab:
|
|
21
|
+
# 缩进与对齐都用空格,不写 Tab。
|
|
22
|
+
UseTab: Never
|
|
23
23
|
# 续行多缩进 8 个空格。
|
|
24
24
|
ContinuationIndentWidth: 8
|
|
25
25
|
# 访问修饰符不缩进,与 class/struct 左对齐。
|
|
@@ -27,5 +27,5 @@ AccessModifierOffset: -4
|
|
|
27
27
|
# 构造函数初始化列表尽量排在一行。
|
|
28
28
|
PackConstructorInitializers: BinPack
|
|
29
29
|
|
|
30
|
-
# 行尾统一为 LF
|
|
30
|
+
# 行尾统一为 LF。
|
|
31
31
|
LineEnding: LF
|
|
@@ -5,7 +5,6 @@ InheritParentConfig: false
|
|
|
5
5
|
Checks: >
|
|
6
6
|
-*,
|
|
7
7
|
google-*,
|
|
8
|
-
portability-avoid-pragma-once,
|
|
9
8
|
readability-identifier-naming
|
|
10
9
|
|
|
11
10
|
WarningsAsErrors: '*'
|
|
@@ -59,6 +58,3 @@ CheckOptions:
|
|
|
59
58
|
value: lower_case
|
|
60
59
|
- key: readability-identifier-naming.MacroDefinitionCase
|
|
61
60
|
value: UPPER_CASE
|
|
62
|
-
# 包含守卫按 Google 规则以 _H_ 结尾,UPPER_CASE 会把它判成多余下划线。
|
|
63
|
-
- key: readability-identifier-naming.MacroDefinitionIgnoredRegexp
|
|
64
|
-
value: '^[A-Z][A-Z0-9_]*_H_$'
|
|
@@ -3,79 +3,79 @@
|
|
|
3
3
|
# 配置、构建、测试并运行当前 C++11–C++23 工程(默认 C++23)。
|
|
4
4
|
#
|
|
5
5
|
# 用法:./running-build.sh [clang|gcc];省略时用 clang。
|
|
6
|
-
#
|
|
6
|
+
# 程序名与构建目录可用 APP_NAME、BUILD_DIR 覆盖;默认 app 与 build/<compiler>。
|
|
7
7
|
# 编译数据库:build/<compiler>/compile_commands.json。
|
|
8
8
|
# 适用于 Linux、macOS 和 Windows + WSL,不支持 Windows 原生壳。
|
|
9
9
|
|
|
10
10
|
set -euo pipefail
|
|
11
11
|
cd "$(dirname "$0")"
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
APP_NAME="${APP_NAME:-app}"
|
|
14
|
+
BUILD_ROOT="${BUILD_ROOT:-build}"
|
|
15
15
|
|
|
16
16
|
# 解析编译器参数,只接受 clang 与 gcc。
|
|
17
17
|
COMPILER="${1:-clang}"
|
|
18
18
|
case "${COMPILER}" in
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
clang)
|
|
20
|
+
readonly CXX="clang++"
|
|
21
|
+
;;
|
|
22
|
+
gcc)
|
|
23
|
+
readonly CXX="g++"
|
|
24
|
+
;;
|
|
25
|
+
*)
|
|
26
|
+
printf '用法: %s [clang|gcc]\n' "$0" >&2
|
|
27
|
+
exit 2
|
|
28
|
+
;;
|
|
29
29
|
esac
|
|
30
30
|
readonly COMPILER CXX
|
|
31
|
-
|
|
31
|
+
BUILD_DIR="${BUILD_DIR:-${BUILD_ROOT}/${COMPILER}}"
|
|
32
32
|
|
|
33
33
|
# 打印阶段标题。
|
|
34
34
|
header() {
|
|
35
|
-
|
|
35
|
+
printf '\n== %s ==\n' "$1"
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
# 打印错误。
|
|
39
39
|
err() {
|
|
40
|
-
|
|
40
|
+
printf '错误: %s\n' "$1" >&2
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
# 命令失败时打印退出码与命令。
|
|
44
44
|
on_error() {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
local status=$?
|
|
46
|
+
printf '失败(退出码 %s):%s\n' "${status}" "${BASH_COMMAND}" >&2
|
|
47
47
|
}
|
|
48
48
|
trap on_error ERR
|
|
49
49
|
|
|
50
|
-
#
|
|
50
|
+
# 入口:配置、构建、导出编译数据库、测试并运行。
|
|
51
51
|
main() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
header "配置 (${COMPILER})"
|
|
53
|
+
cmake -S . -B "${BUILD_DIR}" -G Ninja \
|
|
54
|
+
-DCMAKE_BUILD_TYPE=Debug \
|
|
55
|
+
-DCMAKE_C_COMPILER="${COMPILER}" \
|
|
56
|
+
-DCMAKE_CXX_COMPILER="${CXX}" \
|
|
57
|
+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
header "构建"
|
|
60
|
+
cmake --build "${BUILD_DIR}"
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
header "编译数据库"
|
|
63
|
+
rm -f "${BUILD_ROOT}/compile_commands.json"
|
|
64
|
+
ln -s "${COMPILER}/compile_commands.json" \
|
|
65
|
+
"${BUILD_ROOT}/compile_commands.json"
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
header "测试"
|
|
68
|
+
if [ -d tests ]; then
|
|
69
|
+
ctest --test-dir "${BUILD_DIR}" --output-on-failure --no-tests=error
|
|
70
|
+
else
|
|
71
|
+
ctest --test-dir "${BUILD_DIR}" --output-on-failure
|
|
72
|
+
fi
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
header "运行 ${APP_NAME}"
|
|
75
|
+
(
|
|
76
|
+
cd "${BUILD_DIR}/bin"
|
|
77
|
+
"./${APP_NAME}"
|
|
78
|
+
)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
main "$@"
|
|
@@ -7,15 +7,15 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
|
7
7
|
enable_testing()
|
|
8
8
|
|
|
9
9
|
add_executable(app
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
src/main.cpp
|
|
11
|
+
src/greeting.cpp
|
|
12
12
|
)
|
|
13
13
|
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
14
14
|
target_compile_features(app PRIVATE cxx_std_23)
|
|
15
15
|
set_target_properties(app PROPERTIES
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
CXX_STANDARD 23
|
|
17
|
+
CXX_STANDARD_REQUIRED ON
|
|
18
|
+
CXX_EXTENSIONS OFF
|
|
19
19
|
)
|
|
20
20
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
21
21
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
#define CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
|
|
1
|
+
#pragma once
|
|
3
2
|
|
|
4
3
|
#include <string>
|
|
5
4
|
|
|
@@ -8,5 +7,3 @@ namespace greeting {
|
|
|
8
7
|
std::string MakeGreeting(const std::string& name);
|
|
9
8
|
|
|
10
9
|
} // namespace greeting
|
|
11
|
-
|
|
12
|
-
#endif // CPP_WORKFLOW_TEMPLATE_MULTI_INCLUDE_GREETING_H_
|
|
@@ -9,9 +9,9 @@ namespace greeting {
|
|
|
9
9
|
|
|
10
10
|
std::string MakeGreeting(const std::string& name) {
|
|
11
11
|
#if __cplusplus >= 202002L
|
|
12
|
-
|
|
12
|
+
return std::format("Hello, {}!", name);
|
|
13
13
|
#else
|
|
14
|
-
|
|
14
|
+
return "Hello, " + name + "!";
|
|
15
15
|
#endif
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -12,16 +12,16 @@ add_subdirectory(greeting)
|
|
|
12
12
|
add_executable(app src/main.cpp)
|
|
13
13
|
target_compile_features(app PRIVATE cxx_std_23)
|
|
14
14
|
set_target_properties(app PROPERTIES
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
CXX_STANDARD 23
|
|
16
|
+
CXX_STANDARD_REQUIRED ON
|
|
17
|
+
CXX_EXTENSIONS OFF
|
|
18
18
|
)
|
|
19
19
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
20
20
|
target_link_libraries(app PRIVATE greeting)
|
|
21
21
|
if(APPLE)
|
|
22
|
-
|
|
22
|
+
set_target_properties(app PROPERTIES BUILD_RPATH "@loader_path/../lib")
|
|
23
23
|
else()
|
|
24
|
-
|
|
24
|
+
set_target_properties(app PROPERTIES BUILD_RPATH "$ORIGIN/../lib")
|
|
25
25
|
endif()
|
|
26
26
|
|
|
27
27
|
add_test(NAME app_smoke COMMAND app)
|
package/skills/building-cpp/assets/templates/projects/shared-library/greeting/CMakeLists.txt
CHANGED
|
@@ -2,14 +2,14 @@ add_library(greeting SHARED src/greeting.cpp)
|
|
|
2
2
|
target_include_directories(greeting PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
3
3
|
target_compile_features(greeting PUBLIC cxx_std_23)
|
|
4
4
|
set_target_properties(greeting PROPERTIES
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
CXX_STANDARD 23
|
|
6
|
+
CXX_STANDARD_REQUIRED ON
|
|
7
|
+
CXX_EXTENSIONS OFF
|
|
8
8
|
)
|
|
9
9
|
target_compile_options(greeting PRIVATE
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
-Wall
|
|
11
|
+
-Wextra
|
|
12
|
+
-Werror
|
|
13
|
+
-Wold-style-cast
|
|
14
|
+
-Wshadow
|
|
15
15
|
)
|
package/skills/building-cpp/assets/templates/projects/shared-library/greeting/include/greeting.h
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
#define CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
1
|
+
#pragma once
|
|
3
2
|
|
|
4
3
|
#include <string>
|
|
5
4
|
|
|
@@ -8,5 +7,3 @@ namespace greeting {
|
|
|
8
7
|
std::string MakeGreeting(const std::string& name);
|
|
9
8
|
|
|
10
9
|
} // namespace greeting
|
|
11
|
-
|
|
12
|
-
#endif // CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
package/skills/building-cpp/assets/templates/projects/shared-library/greeting/src/greeting.cpp
CHANGED
|
@@ -9,9 +9,9 @@ namespace greeting {
|
|
|
9
9
|
|
|
10
10
|
std::string MakeGreeting(const std::string& name) {
|
|
11
11
|
#if __cplusplus >= 202002L
|
|
12
|
-
|
|
12
|
+
return std::format("Hello, {}!", name);
|
|
13
13
|
#else
|
|
14
|
-
|
|
14
|
+
return "Hello, " + name + "!";
|
|
15
15
|
#endif
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -9,9 +9,9 @@ enable_testing()
|
|
|
9
9
|
add_executable(app src/main.cpp)
|
|
10
10
|
target_compile_features(app PRIVATE cxx_std_23)
|
|
11
11
|
set_target_properties(app PROPERTIES
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
CXX_STANDARD 23
|
|
13
|
+
CXX_STANDARD_REQUIRED ON
|
|
14
|
+
CXX_EXTENSIONS OFF
|
|
15
15
|
)
|
|
16
16
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
17
17
|
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
#endif
|
|
6
6
|
|
|
7
7
|
int main() {
|
|
8
|
-
|
|
8
|
+
const std::string name = "C++";
|
|
9
9
|
#if __cplusplus >= 202002L
|
|
10
|
-
|
|
10
|
+
std::cout << std::format("Hello, {}!\n", name);
|
|
11
11
|
#else
|
|
12
|
-
|
|
12
|
+
std::cout << "Hello, " << name << "!\n";
|
|
13
13
|
#endif
|
|
14
|
-
|
|
14
|
+
return 0;
|
|
15
15
|
}
|
|
@@ -12,9 +12,9 @@ add_subdirectory(greeting)
|
|
|
12
12
|
add_executable(app src/main.cpp)
|
|
13
13
|
target_compile_features(app PRIVATE cxx_std_23)
|
|
14
14
|
set_target_properties(app PROPERTIES
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
CXX_STANDARD 23
|
|
16
|
+
CXX_STANDARD_REQUIRED ON
|
|
17
|
+
CXX_EXTENSIONS OFF
|
|
18
18
|
)
|
|
19
19
|
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
20
20
|
target_link_libraries(app PRIVATE greeting)
|
package/skills/building-cpp/assets/templates/projects/static-library/greeting/CMakeLists.txt
CHANGED
|
@@ -2,14 +2,14 @@ add_library(greeting STATIC src/greeting.cpp)
|
|
|
2
2
|
target_include_directories(greeting PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
3
3
|
target_compile_features(greeting PUBLIC cxx_std_23)
|
|
4
4
|
set_target_properties(greeting PROPERTIES
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
CXX_STANDARD 23
|
|
6
|
+
CXX_STANDARD_REQUIRED ON
|
|
7
|
+
CXX_EXTENSIONS OFF
|
|
8
8
|
)
|
|
9
9
|
target_compile_options(greeting PRIVATE
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
-Wall
|
|
11
|
+
-Wextra
|
|
12
|
+
-Werror
|
|
13
|
+
-Wold-style-cast
|
|
14
|
+
-Wshadow
|
|
15
15
|
)
|
package/skills/building-cpp/assets/templates/projects/static-library/greeting/include/greeting.h
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
#define CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
|
1
|
+
#pragma once
|
|
3
2
|
|
|
4
3
|
#include <string>
|
|
5
4
|
|
|
@@ -8,5 +7,3 @@ namespace greeting {
|
|
|
8
7
|
std::string MakeGreeting(const std::string& name);
|
|
9
8
|
|
|
10
9
|
} // namespace greeting
|
|
11
|
-
|
|
12
|
-
#endif // CPP_WORKFLOW_TEMPLATE_GREETING_INCLUDE_GREETING_H_
|
package/skills/building-cpp/assets/templates/projects/static-library/greeting/src/greeting.cpp
CHANGED
|
@@ -9,9 +9,9 @@ namespace greeting {
|
|
|
9
9
|
|
|
10
10
|
std::string MakeGreeting(const std::string& name) {
|
|
11
11
|
#if __cplusplus >= 202002L
|
|
12
|
-
|
|
12
|
+
return std::format("Hello, {}!", name);
|
|
13
13
|
#else
|
|
14
|
-
|
|
14
|
+
return "Hello, " + name + "!";
|
|
15
15
|
#endif
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
| --- | --- | --- |
|
|
10
10
|
| `host` | `windows` / `linux` / `macos` | 编辑器与代理壳所在的系统 |
|
|
11
11
|
| `build_host` | `native` / `wsl` | 编译在哪执行;`wsl` 只对 `host=windows` 合法 |
|
|
12
|
-
| `compiler` | `clang` / `gcc` | 一次只配一个;不支持 MSVC、clang-cl,也不把 C
|
|
12
|
+
| `compiler` | `clang` / `gcc` | 一次只配一个;不支持 MSVC、clang-cl,也不把 C 编译器单独作为一个轴;资产里的 MSVC 分支只供阅读,不进入声明 |
|
|
13
13
|
| `standard` | `c++11` / `c++14` / `c++17` / `c++20` / `c++23` | 一个工程一个标准;新工程默认 `c++23`,旧声明缺字段时也按 `c++23` 处理 |
|
|
14
14
|
|
|
15
15
|
```json
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
- `host=windows` + `build_host=native`:本版本不支持,静态校验直接返回失败。
|
|
41
41
|
- `compiler=msvc`、`compiler=clang-cl`、`compiler=c`。
|
|
42
42
|
|
|
43
|
-
`windows` + `native`
|
|
43
|
+
`windows` + `native` 不再作为「合法但不能构建」的声明保留;CMake 资产里的 MSVC 分支不是受支持的环境,不能据此写 `compiler=msvc`。声明校验直接返回 `ok: false`,`issues` 只有一句「本版本不能在 Windows 原生壳里构建」;不要建议改 WSL,也不要临时写 PowerShell 脚本伪装成已支持。
|
|
44
44
|
|
|
45
45
|
## 工具角色
|
|
46
46
|
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
| 语言服务 | `clangd` | `clangd` |
|
|
53
53
|
| 构建 | `cmake` + `ninja` | `cmake` + `ninja` |
|
|
54
54
|
| 测试 | `ctest` | `ctest` |
|
|
55
|
-
| 程序 |
|
|
55
|
+
| 程序 | 项目技能点名的 target | 同一名字 |
|
|
56
56
|
|
|
57
57
|
工具角色与编译器解耦:GCC 模式下仍用 Clang 的格式化、静态检查和语言服务。不要因为编译器是 GCC 就换成 `gcc-format` 之类不存在的工具。工程确有 C 源时,C 编译器用同一套的 `clang` 或 `gcc`,不能与 C++ 编译器分属两套;`--live` 的 compiler 角色核对的是 C++ 驱动,C 驱动缺失时由 configure 报错。
|
|
58
58
|
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
| gcc | `build/gcc/` | `build/gcc/compile_commands.json` |
|
|
74
74
|
| 当前 | `build/` | `build/compile_commands.json` → 上面之一的符号链接 |
|
|
75
75
|
|
|
76
|
-
一次 configure 只用一个编译器;切换编译器时用另一个目录,不要在同一目录里改 `CMAKE_CXX_COMPILER`
|
|
76
|
+
一次 configure 只用一个编译器;切换编译器时用另一个目录,不要在同一目录里改 `CMAKE_CXX_COMPILER` 后复用缓存。项目技能声明单一构建目录时以项目为准(本书 `games/tictactoe/build/`),此时不建 `build/clang` 与 `build/gcc`,编译数据库仍在 `<build-dir>/compile_commands.json`。
|
|
77
77
|
|
|
78
78
|
## 活动校验
|
|
79
79
|
|
|
@@ -30,7 +30,7 @@ build/
|
|
|
30
30
|
|
|
31
31
|
## 规则
|
|
32
32
|
|
|
33
|
-
- 生成器固定单配置 Ninja,不用 Ninja Multi-Config
|
|
33
|
+
- 生成器固定单配置 Ninja,不用 Ninja Multi-Config:同一源文件会写多条命令,读数据库时容易误选;构建目录固定 `build/clang` 或 `build/gcc`。
|
|
34
34
|
- 一个 configure 只用一个编译器:`-DCMAKE_CXX_COMPILER=clang++` 或 `g++`;确有 C 源时 C 编译器与 C++ 编译器同属一套。
|
|
35
35
|
- `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)` 由 `engineering` 写在顶层;Ninja 下产出 `compile_commands.json`。
|
|
36
36
|
- 输出目录由 `engineering` 统一设到 `build/<compiler>/bin` 与 `build/<compiler>/lib`;本步只核对,不重复设。
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
- `.clangd` 的 `CompilationDatabase` 指向 `build/<compiler>`;切换编译器时同步改,不能留旧目录。**不要写 `-std`**:它会覆盖 `compile_commands.json`,把 C++23 工程降成旧标准;标准只由构建声明和编译数据库决定。
|
|
14
14
|
- `--query-driver` 是 clangd 的命令行参数,写在 `.vscode/settings.json` 的 `clangd.arguments` 里,不是 `.clangd` 的 YAML 键。它告诉 clangd 允许执行哪个编译器驱动来取系统头路径;路径写绝对路径,并与 `environment.json` 的编译器一致。
|
|
15
15
|
- 首次复制时按轴替换三处:`compiler=clang` 用 `CompilationDatabase: build/clang`、`--query-driver=/usr/bin/clang++` 和 `cmake.debugConfig` 的 `MIMode: lldb` / `miDebuggerPath: /usr/bin/lldb`;`compiler=gcc` 用 `build/gcc`、`/usr/bin/g++` 和 `MIMode: gdb` / `/usr/bin/gdb`。只复制模板而不改这三处,GCC 模式会指向错误的数据库、驱动或调试器。原工程已有的 `.clangd` 不覆盖;要改先征得同意。
|
|
16
|
-
- `.clang-format` 保留 `Language: Cpp`、`BasedOnStyle: Google`、`Standard` 和 `LineEnding: LF`:模板资产写 `Latest`;工程按 `environment.json` 声明 C++11–C++20 时,把 `Standard` 改成 `c++NN`(映射见 `../../engineering/references/cmake/standards/index.md`)。`Standard` 不接受 `c++23` 的旧工具会报 `unknown enumerated scalar`;C++23 工程统一写 `Latest`,由工具取它支持的最高标准。缩进与列宽默认
|
|
17
|
-
- `.clang-tidy` 用 `Checks: '-*, google-*,
|
|
16
|
+
- `.clang-format` 保留 `Language: Cpp`、`BasedOnStyle: Google`、`Standard` 和 `LineEnding: LF`:模板资产写 `Latest`;工程按 `environment.json` 声明 C++11–C++20 时,把 `Standard` 改成 `c++NN`(映射见 `../../engineering/references/cmake/standards/index.md`)。`Standard` 不接受 `c++23` 的旧工具会报 `unknown enumerated scalar`;C++23 工程统一写 `Latest`,由工具取它支持的最高标准。缩进与列宽默认 4 个空格、120 列,模板资产显式写 `UseTab: Never`、`TabWidth: 4`、`IndentWidth: 4`、`ContinuationIndentWidth: 8`、`AccessModifierOffset: -4` 与 `ColumnLimit: 120`;工程有自己配置时按工程值执行。包含分块保持 include 现有空行分组,组内顺序交给 Google 预设。需要新规则时先改 `../../developing-cpp/references/style/01-google-cpp-style.md` 并说明理由。
|
|
17
|
+
- `.clang-tidy` 用 `Checks: '-*, google-*, readability-identifier-naming'`,保留 `WarningsAsErrors: '*'` 和 `FormatStyle: file`。`google-*` 覆盖 Google 风格能静态检查的部分;`readability-identifier-naming` 只配项目确实统一的命名项:类型/枚举/别名/模板参数 PascalCase,变量/参数/成员 snake_case,类成员尾随 `_`,结构体成员不尾随,常量 `k` + PascalCase。不要设 `FunctionCase`,Google 允许 `count()` / `set_count()` 这类访问器;不要打开 `portability-avoid-pragma-once`,工程统一用 `#pragma once`,打开会把每个头文件报成问题;不要重新打开 `cppcoreguidelines-*` 整包。
|
|
18
18
|
- `.clang-tidy` 关闭项和例外必须写理由;不要借 `-*` 之后再打开 `cppcoreguidelines-*` 这类非 Google 整族检查。
|
|
19
19
|
- `.vscode/extensions.json` 推荐 clangd、CMake Tools 与 C/C++ 扩展;`.vscode/settings.json` 固定 clangd 参数、CMake 构建目录和 `cmake.debugConfig`。配置、构建、运行和调试只从 CMake Tools 进入,不写 `tasks.json` 或 `launch.json`;C/C++ 扩展只作为 CMake 快速调试的后端,IntelliSense 关闭,避免和 clangd 并行。配置注释用 JSONC 的 `//`,贴在被解释的键上方。
|
|
20
20
|
- 配置文件以标题一行、`#` 一行、一行用途开头;每个键上方一句说明,写这一项控制什么;取值有取舍或偏离预设时再补一句为什么。不写策略说明段,也不指向文档路径。
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
5. **核对产物**:`build/<compiler>/compile_commands.json` 存在;`build/compile_commands.json` 指向当前编译器;`app` 可执行文件在 `build/<compiler>/bin`。对 `app` 跑 `file` 与 `ldd`(macOS 用 `otool -L`),`ldd` 不得出现 `not found`,并做一次最小启动;见 `../../engineering/references/cmake/linking/04-inspect.md`。
|
|
16
16
|
6. **记录结果**:通过时记录编译器版本、构建目录、测试数量;失败时记录命令、退出码、第一条根因诊断。
|
|
17
17
|
|
|
18
|
+
检查命令只写终端输出,不落盘:不要用重定向在仓库根生成 `temp-enc.log` 这类文件。需要留证据时写已忽略的 `temp/`,没有就只引用终端输出。收尾核 `git status --porcelain`,只应剩下本轮有意改动的文件。
|
|
19
|
+
|
|
18
20
|
编码检查与环境校验脚本(`<skill-dir>` 换成插件里 `building-cpp` 的实际目录):
|
|
19
21
|
|
|
20
22
|
```bash
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
| --- | --- | --- |
|
|
9
9
|
| `llvm-vs-code-extensions.vscode-clangd` | 补全、跳转、诊断、格式化 | 配置与构建 |
|
|
10
10
|
| `ms-vscode.cmake-tools` | 配置、构建、运行、调试入口 | 语言服务 |
|
|
11
|
-
| `ms-vscode.cpptools` | 只作为 `CMake: Debug`
|
|
11
|
+
| `ms-vscode.cpptools` | 只作为 `CMake: Debug` 的调试后端;这是对 clangd 默认建议的明确例外 | IntelliSense 与格式化(关闭) |
|
|
12
12
|
|
|
13
13
|
不要同时开两套语言服务;C/C++ 扩展的 IntelliSense 必须关闭,否则会和 clangd 抢编译数据库。
|
|
14
14
|
|
|
@@ -12,7 +12,7 @@ metadata:
|
|
|
12
12
|
## 适用场景
|
|
13
13
|
|
|
14
14
|
- **负责**:类型、函数与文件的行为和契约;声明与实现;命名;异常;源码注释。
|
|
15
|
-
- **不负责**:`CMakeLists.txt` 与 `cmake/` 开 `engineering`;`running-build.sh`、`.clang-*`、`.vscode/`、`environment.json` 开 `building-cpp
|
|
15
|
+
- **不负责**:`CMakeLists.txt` 与 `cmake/` 开 `engineering`;`running-build.sh`、`.clang-*`、`.vscode/`、`environment.json` 开 `building-cpp`,本技能只读其 `standard`;`.qmd`、仓库 README、Python 与其他文档不打开本技能。
|
|
16
16
|
- **交接**:一次改动跨域时按「源码 → engineering → building-cpp」逐段进入,前一段结论落下再开下一段。只改函数体、命名、异常或注释且入口命令可运行时,第 4 步后只开 `building-cpp` 的通过检查;新增或移动源文件、改库与程序的边界、补测试 target 时,完成前必须开 `engineering` 把文件写进 CMake。
|
|
17
17
|
- **前置**:存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`:工程名、库与程序的边界、阶段表、术语增补、入口命令与语言档位。项目技能没写档位才读 `environment.json` 的 `standard`,两者都没有时才用新工程默认 C++23;声明 C++20 的工程里不写 C++23 才有的设施。没有项目技能时门禁不会放出本技能,不猜项目约定。
|
|
18
18
|
- **编码**:源码与构建文件的编码以 `../engineering/references/formatting/01-encoding.md` 为准;行尾与 `.clang-format` 的 `LineEnding` 跟仓库根 `.gitattributes` 与 `.editorconfig`。
|
|
@@ -55,7 +55,7 @@ metadata:
|
|
|
55
55
|
| 会话层、选着与程序边界 | `references/design/session-layer.md`;领域规则见 `references/design/01-project-design.md` |
|
|
56
56
|
| 复杂能力、三方库选型 | `references/design/03-third-party.md` |
|
|
57
57
|
| RAII、资源寿命与析构 | `references/design/02-raii.md` |
|
|
58
|
-
|
|
|
58
|
+
| 文件槽位、头文件去重、声明顺序 | `references/layout/02-file-template.md`、`references/layout/03-declaration-order.md` |
|
|
59
59
|
| 命名与改名 | `references/naming/01-identifier-names.md`;案例在 `references/naming/examples/`;术语在 `references/naming/glossary/` |
|
|
60
60
|
| 声明注释与实现注释 | `references/comments/01-comment-rules.md`(写什么)与 `references/comments/02-style.md`(结构、版式、措辞);案例在 `references/comments/examples/` |
|
|
61
61
|
| 异常规则与异常案例 | `references/exceptions/01-exception-rules.md`;案例在 `references/exceptions/examples/` |
|