Crafter.Build/README.md

172 lines
4.1 KiB
Markdown
Raw Normal View History

2025-11-03 17:00:23 +01:00
# Crafter.Build
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
A modern, cross-platform C++ build system designed specifically for C++20 modules. Built with simplicity and flexibility in mind.
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
## Features
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
- **C++20 Modules Support**: Native support for modern C++ module systems
- **JSON-based Configuration**: Easy-to-read project configuration files
- **Multi-Configuration Builds**: Debug and Release builds with customizable settings
- **Dependency Management**: Easy integration with external projects
- **Testing Framework**: Built-in test execution capabilities
## Installation
### Prerequisites
```bash
2025-02-03 22:18:56 +01:00
lld
2025-10-31 16:50:47 +01:00
clang
2024-12-28 22:13:21 +01:00
git
2025-10-31 16:50:47 +01:00
lldb
2025-06-10 00:10:48 +02:00
onetbb
glslang
2025-11-03 17:00:23 +01:00
vulkan-devel
2024-12-28 22:13:21 +01:00
```
2025-02-03 22:18:56 +01:00
2025-11-03 17:00:23 +01:00
### Build from Source
2024-12-28 22:13:21 +01:00
```bash
2025-11-03 17:00:23 +01:00
git clone https://forgejo.catcrafts.net/Catcrafts/Crafter.Build.git
2024-12-28 22:13:21 +01:00
cd Crafter.Build
./build.sh
```
2025-11-03 17:00:23 +01:00
(Optionally add to your PATH for global access)
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
## Getting Started
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
### Quickstart Guide
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
1. Create a `project.json` file in your project directory:
```json
2024-12-28 22:13:21 +01:00
{
"name": "hello-world",
"configurations": [
{
2025-11-03 17:00:23 +01:00
"name": "executable",
"implementations": ["main"],
2024-12-28 22:13:21 +01:00
},
{
2025-11-03 17:00:23 +01:00
"name": "executable-debug",
"extends": ["executable"],
"debug": true
},
2024-12-28 22:13:21 +01:00
]
}
```
2025-11-03 17:00:23 +01:00
2. Create `main.cpp`:
2024-12-28 22:13:21 +01:00
```cpp
#include <print>
int main() {
2025-11-03 17:00:23 +01:00
std::println("Hello World!");
2024-12-28 22:13:21 +01:00
}
```
2025-11-03 17:00:23 +01:00
3. Build and run:
```bash
crafter-build build debug -r
```
## Command Line Interface
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
```bash
# Build a specific configuration
crafter-build build [configuration]
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
# Run a specific test
crafter-build test [test]
2024-12-29 00:51:02 +01:00
2025-11-03 17:00:23 +01:00
# Run all tests
crafter-build test
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
# Display help information
crafter-build --help
2024-12-28 22:13:21 +01:00
2025-11-03 17:00:23 +01:00
# Specify project file path (defaults to project.json)
-p /path/to/project.json
2025-02-03 22:06:54 +01:00
2025-11-03 17:00:23 +01:00
# Run executable after building
-r
```
2025-11-03 17:00:23 +01:00
## Test Configuration
2025-11-03 17:00:23 +01:00
Tests are defined in the `tests` array of your project file. A typical test configuration depends on your main project:
2025-11-03 17:00:23 +01:00
```json
"tests": [
{
"name": "should-compile",
"implementations": ["tests/ShouldCompile"],
"dependencies": [
{
"path": "./project.json",
"configuration": "lib-shared"
}
]
}
]
```
2025-11-03 17:00:23 +01:00
### Writing Test Files
2025-01-02 02:53:39 +01:00
2025-11-03 17:00:23 +01:00
Test files must follow a specific format:
- Export a C-compatible function named `RunTest()`
- The `RunTest()` function must return `nullptr` if the test passes, or a pointer to an error message string if it fails
2025-11-03 17:00:23 +01:00
Example test implementation:
```cpp
import std;
using namespace std;
extern "C" {
string* RunTest() {
// Perform your test logic here
int expected = 42;
int actual = 5 * 8 + 2; // Should equal 42
if (actual != expected) {
return new string("Test failed: expected " + to_string(expected) + ", but got " + to_string(actual));
}
// Return nullptr to indicate success
return nullptr;
}
}
```
2025-11-03 17:00:23 +01:00
## Configuration Properties
2025-02-03 22:06:54 +01:00
2025-11-03 17:00:23 +01:00
### Basic Properties
- **name**: Name of the configuration
- **standard**: C++ standard (default: `c++26`)
- **interfaces**: C++20 module files (`.cppm` extension)
- **implementations**: Source files (`.cpp` extension)
- **additional_files**: Files copied to output directory
- **build_dir**: Directory for intermediate build files (default: `build`)
- **output_dir**: Directory for final output files (default: `bin`)
- **type**: Project type (`executable`, `library`, `shared-library`, default: `executable`)
- **extends**: Array of configuration names to extend, later entries overwrite previous ones
- **debug**: Boolean enabling debug mode (default: `false`)
2025-11-03 17:00:23 +01:00
### Dependencies
Both local and git dependencies are supported:
2025-11-03 17:00:23 +01:00
For git dependencies branch and commit are mutually exclusive, if neither is supplied the latest commit on the default branch is chosen
2024-12-29 20:16:53 +01:00
```json
2024-12-29 20:17:19 +01:00
"dependencies": [
2024-12-29 20:16:53 +01:00
{
2025-11-03 17:00:23 +01:00
"path": "/home/Crafter.Build/project.json",
"configuration": "debug-lib",
},
2025-02-03 22:06:54 +01:00
{
2025-11-03 17:00:23 +01:00
"path": "https://github.com/Catcrafts/Crafter.Build.git",
"configuration": "debug-lib",
"branch": "master",
"commit": "af7eb61c3d92ab18f6aa6c139ac7211a908a24ee"
2025-02-03 22:06:54 +01:00
}
2024-12-29 20:16:53 +01:00
]
```
2025-11-03 17:00:23 +01:00
## License
2025-11-03 17:00:23 +01:00
This project is licensed under the LGPL v3 License - see the LICENSE file for details.