Skip to content

Commit a96ec85

Browse files
Merge pull request #11 from Awesome-Embedded-Learning-Studio/feat/optimize_cfbox
Optimize the CFBox as enter V0.2.0 Stage
2 parents c99a474 + 2893d72 commit a96ec85

124 files changed

Lines changed: 1465 additions & 698 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [main]
66
pull_request:
77
branches: [main]
8+
workflow_dispatch:
89

910
jobs:
1011
# ── Native build + test ───────────────────────────────────────
@@ -16,10 +17,19 @@ jobs:
1617
- name: Install dependencies
1718
run: |
1819
sudo apt-get update
19-
sudo apt-get install -y cmake g++-13
20+
sudo apt-get install -y cmake g++-13 ccache
21+
22+
- name: Restore ccache
23+
uses: actions/cache@v4
24+
with:
25+
path: ~/.ccache
26+
key: ccache-native-${{ runner.os }}-${{ github.sha }}
27+
restore-keys: ccache-native-${{ runner.os }}-
2028

2129
- name: Configure (Debug)
22-
run: cmake -B build -DCMAKE_CXX_COMPILER=g++-13
30+
run: cmake -B build -DCMAKE_CXX_COMPILER=g++-13 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
31+
env:
32+
CCACHE_MAXSIZE: 256M
2333

2434
- name: Build
2535
run: cmake --build build -j $(nproc)
@@ -46,14 +56,24 @@ jobs:
4656
- name: Install dependencies
4757
run: |
4858
sudo apt-get update
49-
sudo apt-get install -y cmake g++-13
59+
sudo apt-get install -y cmake g++-13 ccache
60+
61+
- name: Restore ccache
62+
uses: actions/cache@v4
63+
with:
64+
path: ~/.ccache
65+
key: ccache-release-${{ runner.os }}-${{ github.sha }}
66+
restore-keys: ccache-release-${{ runner.os }}-
5067

5168
- name: Configure (Release, -Os)
5269
run: >
5370
cmake -B build-release
5471
-DCMAKE_BUILD_TYPE=Release
5572
-DCMAKE_CXX_COMPILER=g++-13
73+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
5674
-DCFBOX_OPTIMIZE_FOR_SIZE=ON
75+
env:
76+
CCACHE_MAXSIZE: 256M
5777

5878
- name: Build
5979
run: cmake --build build-release -j $(nproc)
@@ -92,22 +112,32 @@ jobs:
92112
if: matrix.target == 'aarch64'
93113
run: |
94114
sudo apt-get update
95-
sudo apt-get install -y cmake ${{ matrix.compiler_pkg }}
115+
sudo apt-get install -y cmake ${{ matrix.compiler_pkg }} ccache
96116
97117
- name: Install cross-compiler (armhf)
98118
if: matrix.target == 'armhf'
99119
run: |
120+
sudo apt-get update
121+
sudo apt-get install -y ccache
100122
curl -L -o /tmp/arm-toolchain.tar.xz \
101123
https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
102124
sudo tar -xJf /tmp/arm-toolchain.tar.xz -C /opt
103125
sudo ln -s /opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf /opt/arm-gnu-toolchain
104126
echo "/opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf/bin" >> "$GITHUB_PATH"
105127
128+
- name: Restore ccache
129+
uses: actions/cache@v4
130+
with:
131+
path: ~/.ccache
132+
key: ccache-cross-${{ matrix.target }}-${{ github.sha }}
133+
restore-keys: ccache-cross-${{ matrix.target }}-
134+
106135
- name: Cross-compile (dynamic, -Os)
107136
run: |
108137
cmake -B build-${{ matrix.target }} \
109138
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/${{ matrix.toolchain }} \
110139
-DCMAKE_BUILD_TYPE=Release \
140+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
111141
-DCFBOX_OPTIMIZE_FOR_SIZE=ON
112142
cmake --build build-${{ matrix.target }} -j $(nproc)
113143
@@ -123,6 +153,7 @@ jobs:
123153
cmake -B build-${{ matrix.target }}-static \
124154
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/${{ matrix.toolchain }} \
125155
-DCMAKE_BUILD_TYPE=Release \
156+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
126157
-DCFBOX_OPTIMIZE_FOR_SIZE=ON \
127158
-DCFBOX_STATIC_LINK=ON
128159
cmake --build build-${{ matrix.target }}-static -j $(nproc)

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.26 FATAL_ERROR)
22

33
project(CFBox
4-
VERSION 0.0.1
4+
VERSION 0.2.0
55
DESCRIPTION "A Modern C++ Toy Busybox"
66
HOMEPAGE_URL "https://github.com/Awesome-Embedded-Learning-Studio/CFBox"
77
LANGUAGES CXX
@@ -56,6 +56,9 @@ target_include_directories(cfbox PUBLIC include)
5656
target_include_directories(cfbox PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include)
5757
target_link_libraries(cfbox PRIVATE cfbox_compiler_flags)
5858

59+
# ── Install target ─────────────────────────────────────────────
60+
install(TARGETS cfbox DESTINATION bin)
61+
5962
# ── GTest via CPM (FetchContent) ──────────────────────────────
6063
if(NOT CMAKE_CROSSCOMPILING)
6164
CPMAddPackage(

README.en.md

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ A minimalist BusyBox alternative written in modern C++23.
88
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
99
[![C++23](https://img.shields.io/badge/C++23-00599C?logo=cplusplus)](https://en.cppreference.com/w/cpp/23)
1010
[![CMake](https://img.shields.io/badge/CMake-3.26+-064F8C?logo=cmake)](https://cmake.org/)
11-
[![Tests](https://img.shields.io/badge/Tests-331_passing-brightgreen)](tests/)
12-
[![Applets](https://img.shields.io/badge/Applets-109-brightgreen)](src/applets/)
11+
[![Tests](https://img.shields.io/badge/Tests-379_passing-brightgreen)](tests/)
12+
[![Applets](https://img.shields.io/badge/Applets-115-brightgreen)](src/applets/)
1313

1414
## Overview
1515

16-
CFBox is a single-executable Unix utility collection distributed via symbolic links. 109 applets implemented and tested, with a CI pipeline covering native builds, cross-compilation, and QEMU user/system-mode testing. Features configurable CMake builds (per-applet toggles), GNU-style long options, and colored help output.
16+
CFBox is a single-executable Unix utility collection distributed via symbolic links. 115 applets implemented and tested, with a CI pipeline covering native builds, cross-compilation, and QEMU user/system-mode testing. Features configurable CMake builds (per-applet toggles), GNU-style long options, and colored help output.
1717

1818
**Design philosophy:** Simplicity first — Modern C++ (`std::expected`) — Embedded-friendly (cross-compilation, static linking)
1919

2020
## Size Comparison
2121

2222
| Project | Language | Size | Applets | Size/Applet |
2323
|---------|----------|------|---------|-------------|
24-
| **CFBox (size-opt)** | **C++23** | **446 KB** | **109** | **~4.1 KB** |
24+
| **CFBox (size-opt)** | **C++23** | **406 KB** | **115** | **~3.5 KB** |
2525
| Toybox | C | ~500 KB | 238 | ~2.1 KB |
2626
| BusyBox (full) | C | ~1.7 MB | 274 | ~9 KB |
2727
| uutils/coreutils | Rust | ~11 MB | ~100 | ~110 KB |
@@ -50,7 +50,7 @@ cmake -B build
5050
cmake --build build
5151

5252
# Test
53-
ctest --test-dir build --output-on-failure # 331 GTest unit tests
53+
ctest --test-dir build --output-on-failure # 379 GTest unit tests
5454
bash tests/integration/run_all.sh # 54 integration test scripts
5555

5656
# Run via subcommand
@@ -61,15 +61,15 @@ bash tests/integration/run_all.sh # 54 integration test scripts
6161
echo "Hello, World!" # now calls cfbox via symlink
6262
```
6363

64-
## Supported Commands (109)
64+
## Supported Commands (115)
6565

6666
### Text Processing (31)
6767

6868
`echo`, `printf`, `cat`, `head`, `tail`, `wc`, `sort`, `uniq`, `grep`, `sed`, `fold`, `expand`, `cut`, `paste`, `nl`, `comm`, `tr`, `tac`, `rev`, `shuf`, `factor`, `od`, `split`, `seq`, `tsort`, `expr`, `awk`, `diff`, `patch`, `cmp`, `ed`
6969

70-
### File Operations (19)
70+
### File Operations (22)
7171

72-
`mkdir`, `rm`, `cp`, `mv`, `ls`, `find`, `ln`, `touch`, `stat`, `install`, `mktemp`, `truncate`, `du`, `df`, `readlink`, `realpath`, `rmdir`, `link`, `unlink`
72+
`mkdir`, `rm`, `cp`, `mv`, `ls`, `find`, `ln`, `touch`, `stat`, `install`, `mktemp`, `truncate`, `du`, `df`, `readlink`, `realpath`, `rmdir`, `link`, `unlink`, `chmod`, `chown`, `chgrp`
7373

7474
### Archive & Compression (6)
7575

@@ -87,9 +87,9 @@ echo "Hello, World!" # now calls cfbox via symlink
8787

8888
`ps`, `top`, `kill`, `pgrep`/`pkill`, `pidof`, `pstree`, `pmap`, `fuser`, `pwdx`, `sysctl`, `iostat`, `watch`, `nice`, `renice`, `timeout`
8989

90-
### Other (16)
90+
### Other (19)
9191

92-
`true`, `false`, `yes`, `sleep`, `usleep`, `sync`, `nohup`, `cksum`, `md5sum`, `sum`, `hexdump`, `more`, `tee`, `init` (PID 1 initramfs init system), `mkfifo`, `mknod`
92+
`true`, `false`, `yes`, `sleep`, `usleep`, `sync`, `nohup`, `cksum`, `md5sum`, `sum`, `hexdump`, `more`, `tee`, `init` (PID 1 initramfs init system), `mkfifo`, `mknod`, `clear`, `which`, `mountpoint`
9393

9494
> All applets support `--help` / `--version`
9595
@@ -137,33 +137,26 @@ cfbox/
137137
│ └── ... # help.hpp, fs_util.hpp, escape.hpp, checksum.hpp
138138
├── src/
139139
│ ├── main.cpp # Dispatch entry
140-
│ └── applets/ # 109 command implementations
140+
│ └── applets/ # 115 command implementations
141141
├── tests/
142-
│ ├── unit/ # GTest unit tests (331 cases)
142+
│ ├── unit/ # GTest unit tests (379 cases)
143143
│ └── integration/ # Shell integration tests (54 scripts)
144144
└── scripts/ # Build, test, install scripts
145145
```
146146

147147
## Next Steps
148148

149-
Current release: v0.1.0. Upcoming work, in priority order:
149+
Current release: v0.2.0 (Phase 1 Wave 1 + Phase 1.5 code quality review complete). Now entering Phase 2: core command deepening.
150150

151-
### Phase 0: Production Pre-gates (In Progress)
151+
### Phase 2: Core Command Deepening (In Progress)
152152

153-
Before adding new applets, the following quality foundations must be completed:
153+
Deepening existing commands from ~30% to ~70% feature completeness, in batches by operational frequency:
154154

155-
| Phase | Scope | Status |
156-
|-------|-------|--------|
157-
| **0A** Baseline Inventory | 109-applet catalog, maturity labels, profile assignments, doc drift fixes | Pending |
158-
| **0B** Perf Baseline | Core benchmarks (cat/grep/sed/sort/find/tar/gzip/cp/tail), RSS regression thresholds | Pending |
159-
| **0C** Size Budget | Per-profile size caps, new rescue/container profiles, per-applet delta tracking | Pending |
160-
| **0D** IO Policy | Streaming audit (head/tail/sed/tr/md5sum etc.), large file/pipe/broken pipe tests | Pending |
161-
| **0E** Safety Hardening | Unified numeric parsers, parser fuzz smoke, privileged command isolation tests | Pending |
162-
| **0F** CI & Release | Tiered CI (sanitizer/benchmark/differential/cross/QEMU), reproducible builds, error format spec | Pending |
163-
164-
### Phase 1: Core System (After Phase 0)
165-
166-
New system-level applets: `chmod`, `chown`, `chgrp`, `mount`, `umount`, `chroot`, `dd`, `stty`, plus deepening existing core commands.
155+
| Batch | Commands | Key Additions |
156+
|-------|----------|---------------|
157+
| Batch 1 | `tail`, `cp`, `test`, `ls` | tail -f, cp -a, full POSIX test, ls -R/--color |
158+
| Batch 2 | `grep`, `tar`, `sed`, `sort` | grep -A/-B/-C, tar -z/-v, sed -i, sort -k |
159+
| Batch 3 | `find`, `sh`, `ps`, `df`, `du` | find boolean expressions, sh case/heredoc/functions |
167160

168161
> See [document/todo/README.md](document/todo/README.md) for the full roadmap.
169162

README.md

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
99
[![C++23](https://img.shields.io/badge/C++23-00599C?logo=cplusplus)](https://en.cppreference.com/w/cpp/23)
1010
[![CMake](https://img.shields.io/badge/CMake-3.26+-064F8C?logo=cmake)](https://cmake.org/)
11-
[![Tests](https://img.shields.io/badge/Tests-331_passing-brightgreen)](tests/)
12-
[![Applets](https://img.shields.io/badge/Applets-109-brightgreen)](src/applets/)
11+
[![Tests](https://img.shields.io/badge/Tests-379_passing-brightgreen)](tests/)
12+
[![Applets](https://img.shields.io/badge/Applets-115-brightgreen)](src/applets/)
1313

1414
## 概述
1515

16-
CFBox 是一个单一可执行文件的 Unix 工具集,通过符号链接分发。109 个 applet 已实现并通过测试,CI 流水线覆盖原生构建、交叉编译、QEMU 用户/系统模式测试。支持 CMake 配置化构建(per-applet 开关)、GNU 风格长选项、彩色帮助输出。
16+
CFBox 是一个单一可执行文件的 Unix 工具集,通过符号链接分发。115 个 applet 已实现并通过测试,CI 流水线覆盖原生构建、交叉编译、QEMU 用户/系统模式测试。支持 CMake 配置化构建(per-applet 开关)、GNU 风格长选项、彩色帮助输出。
1717

1818
**设计理念:** 简洁优先 — 现代C++(`std::expected`) — 嵌入式友好(交叉编译、静态链接)
1919

2020
## 体积对比
2121

2222
| 项目 | 语言 | 体积 | Applets | 体积/Applet |
2323
|------|------|------|---------|-------------|
24-
| **CFBox (size-opt)** | **C++23** | **446 KB** | **109** | **~4.1 KB** |
24+
| **CFBox (size-opt)** | **C++23** | **406 KB** | **115** | **~3.5 KB** |
2525
| Toybox | C | ~500 KB | 238 | ~2.1 KB |
2626
| BusyBox (full) | C | ~1.7 MB | 274 | ~9 KB |
2727
| uutils/coreutils | Rust | ~11 MB | ~100 | ~110 KB |
@@ -50,7 +50,7 @@ cmake -B build
5050
cmake --build build
5151

5252
# 测试
53-
ctest --test-dir build --output-on-failure # 331 个 GTest 单元测试
53+
ctest --test-dir build --output-on-failure # 379 个 GTest 单元测试
5454
bash tests/integration/run_all.sh # 54 套集成测试脚本
5555

5656
# 通过子命令运行
@@ -61,15 +61,15 @@ bash tests/integration/run_all.sh # 54 套集成测试脚本
6161
echo "Hello, World!" # 通过符号链接调用 cfbox
6262
```
6363

64-
## 支持的命令(109 个)
64+
## 支持的命令(115 个)
6565

6666
### 文本处理(31 个)
6767

6868
`echo`, `printf`, `cat`, `head`, `tail`, `wc`, `sort`, `uniq`, `grep`, `sed`, `fold`, `expand`, `cut`, `paste`, `nl`, `comm`, `tr`, `tac`, `rev`, `shuf`, `factor`, `od`, `split`, `seq`, `tsort`, `expr`, `awk`, `diff`, `patch`, `cmp`, `ed`
6969

70-
### 文件操作(19 个)
70+
### 文件操作(22 个)
7171

72-
`mkdir`, `rm`, `cp`, `mv`, `ls`, `find`, `ln`, `touch`, `stat`, `install`, `mktemp`, `truncate`, `du`, `df`, `readlink`, `realpath`, `rmdir`, `link`, `unlink`
72+
`mkdir`, `rm`, `cp`, `mv`, `ls`, `find`, `ln`, `touch`, `stat`, `install`, `mktemp`, `truncate`, `du`, `df`, `readlink`, `realpath`, `rmdir`, `link`, `unlink`, `chmod`, `chown`, `chgrp`
7373

7474
### 归档与压缩(6 个)
7575

@@ -87,9 +87,9 @@ echo "Hello, World!" # 通过符号链接调用 cfbox
8787

8888
`ps`, `top`, `kill`, `pgrep`/`pkill`, `pidof`, `pstree`, `pmap`, `fuser`, `pwdx`, `sysctl`, `iostat`, `watch`, `nice`, `renice`, `timeout`
8989

90-
### 其他(16 个)
90+
### 其他(19 个)
9191

92-
`true`, `false`, `yes`, `sleep`, `usleep`, `sync`, `nohup`, `cksum`, `md5sum`, `sum`, `hexdump`, `more`, `tee`, `init`(PID 1 initramfs init 系统), `mkfifo`, `mknod`
92+
`true`, `false`, `yes`, `sleep`, `usleep`, `sync`, `nohup`, `cksum`, `md5sum`, `sum`, `hexdump`, `more`, `tee`, `init`(PID 1 initramfs init 系统), `mkfifo`, `mknod`, `clear`, `which`, `mountpoint`
9393

9494
> 所有 applet 均支持 `--help` / `--version`
9595
@@ -137,33 +137,26 @@ cfbox/
137137
│ └── ... # help.hpp, fs_util.hpp, escape.hpp, checksum.hpp
138138
├── src/
139139
│ ├── main.cpp # 分发入口
140-
│ └── applets/ # 109 个命令实现
140+
│ └── applets/ # 115 个命令实现
141141
├── tests/
142-
│ ├── unit/ # GTest 单元测试(331 个用例)
142+
│ ├── unit/ # GTest 单元测试(379 个用例)
143143
│ └── integration/ # Shell 集成测试(54 个脚本)
144144
└── scripts/ # 构建、测试、安装脚本
145145
```
146146

147147
## 下一步计划
148148

149-
当前版本 v0.1.0,下一阶段工作按优先级排列
149+
当前版本 v0.2.0(Phase 1 Wave 1 + Phase 1.5 代码质量审查已完成),进入 Phase 2 核心命令深化
150150

151-
### Phase 0:生产化前置门禁(进行中)
151+
### Phase 2:核心命令深化(进行中)
152152

153-
在新增 applet 之前,必须完成以下质量地基
153+
将现有命令功能深度从 ~30% 提升到 ~70%,按运维频率分批推进
154154

155-
| 阶段 | 内容 | 状态 |
156-
|------|------|------|
157-
| **0A** 基线盘点 | 109 个 applet 清单、成熟度标注、profile 归属、文档漂移修复 | 待开始 |
158-
| **0B** 性能基线 | 核心命令 benchmark(cat/grep/sed/sort/find/tar/gzip/cp/tail)、RSS 回归阈值 | 待开始 |
159-
| **0C** 体积预算 | 按 profile 设定体积上限、新增 rescue/container profile、每 applet 增量追踪 | 待开始 |
160-
| **0D** IO 策略 | 流式处理审计(head/tail/sed/tr/md5sum 等整改为流式)、大文件/管道/broken pipe 测试 | 待开始 |
161-
| **0E** 安全加固 | 数值解析统一 helper、parser fuzz smoke、特权命令隔离测试 | 待开始 |
162-
| **0F** CI 与发布 | 分层 CI(sanitizer/benchmark/differential/cross/QEMU)、可复现构建、错误格式规范 | 待开始 |
163-
164-
### Phase 1:核心系统(Phase 0 完成后)
165-
166-
新增 `chmod``chown``chgrp``mount``umount``chroot``dd``stty` 等系统级 applet,深化核心命令功能。
155+
| 批次 | 命令 | 关键补充 |
156+
|------|------|---------|
157+
| 第一批 | `tail``cp``test``ls` | tail -f、cp -a、全面 POSIX test、ls -R/--color |
158+
| 第二批 | `grep``tar``sed``sort` | grep -A/-B/-C、tar -z/-v、sed -i、sort -k |
159+
| 第三批 | `find``sh``ps``df``du` | find 布尔表达式、sh case/heredoc/函数 |
167160

168161
> 详细路线图见 [document/todo/README.md](document/todo/README.md)
169162

0 commit comments

Comments
 (0)