Hacker News 中文摘要

RSS订阅

展示HN:我开发了一款类似Cargo的C/C++构建工具 -- Show HN: I built a Cargo-like build tool for C/C++

文章摘要

Craft是一款轻量级C/C++构建工具,通过简单配置craft.toml文件即可自动生成CMake配置、管理依赖并构建项目,简化了传统C/C++开发中复杂的构建流程。它提供类似Cargo的现代化命令行界面,支持一键创建项目、添加依赖、编译运行等操作,让C/C++开发更高效便捷。

文章总结

Craft:轻量级C/C++构建与工作流工具

项目概述

Craft是一款专为C/C++项目设计的轻量级构建工具,其设计理念类似于Rust的Cargo工具。它通过简化构建流程和依赖管理,解决了传统C/C++开发中需要手动配置CMake和构建系统的痛点。

核心功能

  1. 简化项目配置:只需在craft.toml文件中定义项目,Craft会自动生成CMake配置
  2. 自动化依赖管理:支持通过简单命令添加本地或Git仓库依赖
  3. 项目模板:提供可复用的项目模板,快速初始化新项目
  4. 现代化CLI:提供直观的命令行接口

工作流程

  1. craft.toml中定义项目
  2. Craft自动生成CMakeLists.txt
  3. 自动获取依赖项
  4. 在后台使用CMake构建项目

快速示例

```bash

创建新项目

craft project myapp cd myapp

添加依赖

craft add --git https://github.com/raysan5/raylib.git --links raylib

构建并运行

craft build craft run ```

主要特性

  • 单一配置文件:通过craft.toml定义项目名称、版本、语言标准等
  • 便捷的依赖管理bash craft add --path ../PhysicsEngine # 添加本地依赖 craft add --git https://github.com/raysan5/raylib --tag 5.5 # 添加Git依赖 craft update # 更新所有依赖
  • 项目模板:支持保存自定义模板和内置模板(可执行文件、静态库等)

安装方法

  • macOS/Linuxbash curl -fsSL https://raw.githubusercontent.com/randerson112/craft/main/install.sh | sh
  • Windowspowershell irm https://raw.githubusercontent.com/randerson112/craft/main/install.ps1 | iex 要求:已安装git和cmake

项目结构

典型项目目录: my_app/ ├── craft.toml ├── CMakeLists.txt # 由Craft生成 ├── CMakeLists.extra.cmake # 自定义CMake配置 ├── build/ ├── include/ ├── src/ └── .craft/deps/ # Git依赖项

配置文件说明

craft.toml包含三个主要部分: 1. [project]:项目基本信息(名称、版本、语言标准) 2. [build]:构建配置(类型、包含目录、源目录) 3. [dependencies]:依赖项管理(由Craft自动维护)

注:CMakeLists.txt由Craft自动生成,如需自定义CMake配置,应使用CMakeLists.extra.cmake文件。

Craft是开源项目,欢迎社区贡献。

评论总结

以下是评论内容的总结:

对CMake的批评

  1. CMake复杂难用

    • "Debugging CMAKE build problems made me hate it" (Surac)
    • "CMake is infamously not a build system. It is a build system generator" (forrestthewoods)
  2. 工具链检测问题

    • "cmake's toolchain detection takes a lot of time" (flohofwoe)

替代方案建议

  1. 直接替换CMake

    • "you should be replacing it" (duped)
    • "the solution isn’t to add more layers of crap around cmake, but to replace it" (dima55)
  2. 推荐其他工具

    • "Just switch to bazel" (spwa4)
    • "The least painful C/C++ build tool I’ve used is xmake" (gavinray)

对新工具(Craft)的质疑

  1. 功能局限性

    • "I doubt than < 10,000 lines of C code can cover much of that" (einpoklum)
    • "How does craft handle these 'diamond' patterns" (cherryteastain)
  2. 成熟度问题

    • "This is the first day of releasing it to the public" (randerson_112)

构建系统的普遍问题

  1. 跨平台和嵌入式支持

    • "Any build system that does not support cross-compilation will be de facto banned from the embedded domain" (adev_)
  2. 依赖管理

    • "Provide a way to compile without internet access" (adev_)

AI工具的影响

  1. AI替代传统工具
    • "In the age of AI tools like this are pointless" (kjksf)
    • "maybe it’s time to sunset the format at this point" (littlestymaar)

其他观点

  1. 社区合作

    • "open to the community for development" (randerson_112)
  2. 对AI生成内容的批评

    • "why should I spend any energy looking into your project when all you’re doing is just slinging AI slop around" (thegrim33)

总结显示,评论者对CMake的不满普遍存在,但对新工具的可行性和成熟度持怀疑态度,同时AI工具的出现也引发了关于传统工具未来的讨论。