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
39 changes: 35 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
# ── Native build + test ───────────────────────────────────────
Expand All @@ -16,10 +17,19 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++-13
sudo apt-get install -y cmake g++-13 ccache

- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-native-${{ runner.os }}-${{ github.sha }}
restore-keys: ccache-native-${{ runner.os }}-

- name: Configure (Debug)
run: cmake -B build -DCMAKE_CXX_COMPILER=g++-13
run: cmake -B build -DCMAKE_CXX_COMPILER=g++-13 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
CCACHE_MAXSIZE: 256M

- name: Build
run: cmake --build build -j $(nproc)
Expand All @@ -46,14 +56,24 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++-13
sudo apt-get install -y cmake g++-13 ccache

- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-release-${{ runner.os }}-${{ github.sha }}
restore-keys: ccache-release-${{ runner.os }}-

- name: Configure (Release, -Os)
run: >
cmake -B build-release
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER=g++-13
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCFBOX_OPTIMIZE_FOR_SIZE=ON
env:
CCACHE_MAXSIZE: 256M

- name: Build
run: cmake --build build-release -j $(nproc)
Expand Down Expand Up @@ -92,22 +112,32 @@ jobs:
if: matrix.target == 'aarch64'
run: |
sudo apt-get update
sudo apt-get install -y cmake ${{ matrix.compiler_pkg }}
sudo apt-get install -y cmake ${{ matrix.compiler_pkg }} ccache

- name: Install cross-compiler (armhf)
if: matrix.target == 'armhf'
run: |
sudo apt-get update
sudo apt-get install -y ccache
curl -L -o /tmp/arm-toolchain.tar.xz \
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
sudo tar -xJf /tmp/arm-toolchain.tar.xz -C /opt
sudo ln -s /opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf /opt/arm-gnu-toolchain
echo "/opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf/bin" >> "$GITHUB_PATH"

- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-cross-${{ matrix.target }}-${{ github.sha }}
restore-keys: ccache-cross-${{ matrix.target }}-

- name: Cross-compile (dynamic, -Os)
run: |
cmake -B build-${{ matrix.target }} \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/${{ matrix.toolchain }} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCFBOX_OPTIMIZE_FOR_SIZE=ON
cmake --build build-${{ matrix.target }} -j $(nproc)

Expand All @@ -123,6 +153,7 @@ jobs:
cmake -B build-${{ matrix.target }}-static \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/${{ matrix.toolchain }} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCFBOX_OPTIMIZE_FOR_SIZE=ON \
-DCFBOX_STATIC_LINK=ON
cmake --build build-${{ matrix.target }}-static -j $(nproc)
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.26 FATAL_ERROR)

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

# ── Install target ─────────────────────────────────────────────
install(TARGETS cfbox DESTINATION bin)

# ── GTest via CPM (FetchContent) ──────────────────────────────
if(NOT CMAKE_CROSSCOMPILING)
CPMAddPackage(
Expand Down
47 changes: 20 additions & 27 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ A minimalist BusyBox alternative written in modern C++23.
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![C++23](https://img.shields.io/badge/C++23-00599C?logo=cplusplus)](https://en.cppreference.com/w/cpp/23)
[![CMake](https://img.shields.io/badge/CMake-3.26+-064F8C?logo=cmake)](https://cmake.org/)
[![Tests](https://img.shields.io/badge/Tests-331_passing-brightgreen)](tests/)
[![Applets](https://img.shields.io/badge/Applets-109-brightgreen)](src/applets/)
[![Tests](https://img.shields.io/badge/Tests-379_passing-brightgreen)](tests/)
[![Applets](https://img.shields.io/badge/Applets-115-brightgreen)](src/applets/)

## Overview

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.
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.

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

## Size Comparison

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

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

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

## Supported Commands (109)
## Supported Commands (115)

### Text Processing (31)

`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`

### File Operations (19)
### File Operations (22)

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

### Archive & Compression (6)

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

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

### Other (16)
### Other (19)

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

> All applets support `--help` / `--version`

Expand Down Expand Up @@ -137,33 +137,26 @@ cfbox/
│ └── ... # help.hpp, fs_util.hpp, escape.hpp, checksum.hpp
├── src/
│ ├── main.cpp # Dispatch entry
│ └── applets/ # 109 command implementations
│ └── applets/ # 115 command implementations
├── tests/
│ ├── unit/ # GTest unit tests (331 cases)
│ ├── unit/ # GTest unit tests (379 cases)
│ └── integration/ # Shell integration tests (54 scripts)
└── scripts/ # Build, test, install scripts
```

## Next Steps

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

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

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

| Phase | Scope | Status |
|-------|-------|--------|
| **0A** Baseline Inventory | 109-applet catalog, maturity labels, profile assignments, doc drift fixes | Pending |
| **0B** Perf Baseline | Core benchmarks (cat/grep/sed/sort/find/tar/gzip/cp/tail), RSS regression thresholds | Pending |
| **0C** Size Budget | Per-profile size caps, new rescue/container profiles, per-applet delta tracking | Pending |
| **0D** IO Policy | Streaming audit (head/tail/sed/tr/md5sum etc.), large file/pipe/broken pipe tests | Pending |
| **0E** Safety Hardening | Unified numeric parsers, parser fuzz smoke, privileged command isolation tests | Pending |
| **0F** CI & Release | Tiered CI (sanitizer/benchmark/differential/cross/QEMU), reproducible builds, error format spec | Pending |

### Phase 1: Core System (After Phase 0)

New system-level applets: `chmod`, `chown`, `chgrp`, `mount`, `umount`, `chroot`, `dd`, `stty`, plus deepening existing core commands.
| Batch | Commands | Key Additions |
|-------|----------|---------------|
| Batch 1 | `tail`, `cp`, `test`, `ls` | tail -f, cp -a, full POSIX test, ls -R/--color |
| Batch 2 | `grep`, `tar`, `sed`, `sort` | grep -A/-B/-C, tar -z/-v, sed -i, sort -k |
| Batch 3 | `find`, `sh`, `ps`, `df`, `du` | find boolean expressions, sh case/heredoc/functions |

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

Expand Down
47 changes: 20 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![C++23](https://img.shields.io/badge/C++23-00599C?logo=cplusplus)](https://en.cppreference.com/w/cpp/23)
[![CMake](https://img.shields.io/badge/CMake-3.26+-064F8C?logo=cmake)](https://cmake.org/)
[![Tests](https://img.shields.io/badge/Tests-331_passing-brightgreen)](tests/)
[![Applets](https://img.shields.io/badge/Applets-109-brightgreen)](src/applets/)
[![Tests](https://img.shields.io/badge/Tests-379_passing-brightgreen)](tests/)
[![Applets](https://img.shields.io/badge/Applets-115-brightgreen)](src/applets/)

## 概述

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

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

## 体积对比

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

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

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

## 支持的命令(109 个)
## 支持的命令(115 个)

### 文本处理(31 个)

`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`

### 文件操作(19 个)
### 文件操作(22 个)

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

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

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

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

### 其他(16 个)
### 其他(19 个)

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

> 所有 applet 均支持 `--help` / `--version`

Expand Down Expand Up @@ -137,33 +137,26 @@ cfbox/
│ └── ... # help.hpp, fs_util.hpp, escape.hpp, checksum.hpp
├── src/
│ ├── main.cpp # 分发入口
│ └── applets/ # 109 个命令实现
│ └── applets/ # 115 个命令实现
├── tests/
│ ├── unit/ # GTest 单元测试(331 个用例)
│ ├── unit/ # GTest 单元测试(379 个用例)
│ └── integration/ # Shell 集成测试(54 个脚本)
└── scripts/ # 构建、测试、安装脚本
```

## 下一步计划

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

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

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

| 阶段 | 内容 | 状态 |
|------|------|------|
| **0A** 基线盘点 | 109 个 applet 清单、成熟度标注、profile 归属、文档漂移修复 | 待开始 |
| **0B** 性能基线 | 核心命令 benchmark(cat/grep/sed/sort/find/tar/gzip/cp/tail)、RSS 回归阈值 | 待开始 |
| **0C** 体积预算 | 按 profile 设定体积上限、新增 rescue/container profile、每 applet 增量追踪 | 待开始 |
| **0D** IO 策略 | 流式处理审计(head/tail/sed/tr/md5sum 等整改为流式)、大文件/管道/broken pipe 测试 | 待开始 |
| **0E** 安全加固 | 数值解析统一 helper、parser fuzz smoke、特权命令隔离测试 | 待开始 |
| **0F** CI 与发布 | 分层 CI(sanitizer/benchmark/differential/cross/QEMU)、可复现构建、错误格式规范 | 待开始 |

### Phase 1:核心系统(Phase 0 完成后)

新增 `chmod`、`chown`、`chgrp`、`mount`、`umount`、`chroot`、`dd`、`stty` 等系统级 applet,深化核心命令功能。
| 批次 | 命令 | 关键补充 |
|------|------|---------|
| 第一批 | `tail`、`cp`、`test`、`ls` | tail -f、cp -a、全面 POSIX test、ls -R/--color |
| 第二批 | `grep`、`tar`、`sed`、`sort` | grep -A/-B/-C、tar -z/-v、sed -i、sort -k |
| 第三批 | `find`、`sh`、`ps`、`df`、`du` | find 布尔表达式、sh case/heredoc/函数 |

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

Expand Down
Loading