I built a Cargo-like build tool for C/C++
Craft introduces a Cargo-like build and workflow tool for C/C++, aiming to abstract away the notorious complexities of CMake and dependency management. Developers often wrestle with boilerplate and configuration in C/C++ projects, making this project a welcome attempt at streamlining the experience. The discussion delves deep into the merits of generating CMake versus replacing it, while also comparing Craft to the existing, often cumbersome, ecosystem of C/C++ build tools.
The Lowdown
Craft is a new build and workflow tool designed for C and C++ projects, drawing inspiration from Rust's Cargo. It aims to simplify the notoriously complex build environment of C/C++ by providing a higher-level abstraction over CMake, which is often a source of developer frustration.
Key features and functionalities include:
- Simplified Project Definition: Projects are defined using a
craft.tomlfile, specifying name, version, language, and build type. - Automated CMake Generation: Craft automatically generates
CMakeLists.txtfiles from thecraft.tomlconfiguration, reducing the need for manual CMake scripting. - Dependency Management: It handles adding, removing, and updating dependencies from Git repositories or local Craft projects with simple commands like
craft add. - Workflow Commands: Provides intuitive commands for project creation (
craft project), building (craft build), running (craft run), generating boilerplate files (craft gen), and cleaning (craft clean). - Templating System: Users can save custom project structures as reusable templates, and Craft comes with built-in templates for common project types (executable, static/shared library, header-only).
- Escape Hatch: For advanced or custom CMake configurations not directly supported by Craft, users can add a
CMakeLists.extra.cmakefile that will be included in the generated build system.
Overall, Craft positions itself as a solution to the pain points of C/C++ project setup, dependency handling, and general workflow, striving to offer a more modern and less friction-filled development experience akin to other contemporary language ecosystems.
The Gossip
Installation Insecurity Scrutiny
Many commenters expressed concern about the `curl | sh` installation method, labeling it a potential security nightmare. They noted that while it's common for tools like Cargo/Rustup, it still represents a significant supply chain risk, lacking fine-grained permission control or binary validation. Some wished for a more secure, interactive installer TUI.
CMake Conundrum: Generate or Replace?
A central debate revolved around Craft's strategy of generating CMake files rather than replacing CMake entirely. Critics argued that building a 'meta-meta build system' around CMake merely adds another layer of complexity, inheriting CMake's warts. Proponents, and the author's implied reasoning, suggested that CMake's robustness in handling diverse OSes, compilers, and IDEs, especially Windows/Visual Studio, makes it an unavoidable and valuable, albeit verbose, intermediate step. Some wished for a tool that completely abstracts or replaces CMake.
Ecosystem Comparisons & Complications
Commenters compared Craft to various existing C/C++ build and package management tools like Conan, vcpkg, xmake, Nix flakes, and Bazel. They highlighted the inherent difficulty of the C/C++ build problem due to legacy projects, diverse platforms (embedded, cross-compilation), and complex dependency graphs (diamond problems). Many pointed out specific features of alternatives, such as xmake's modern C++ module support or Conan's ABI compatibility, which Craft would need to address to gain widespread adoption.
The Perennial Pain of Project Setup
There was broad agreement with the author's premise that C/C++ project setup and dependency management are painful. Many shared personal anecdotes of wrestling with `CMakeLists.txt` and `find_package` calls, leading to lost momentum. The sentiment was that any tool that simplifies this process, even if imperfect, is a step in the right direction, though some were skeptical given the long history of attempts in this space.