Compare commits

..

No commits in common. "f8fc3836dd3e1ceed8704ef51c33e100acfd10dc" and "ec64b17b2719dabdcb070ffd6ff824cb213d53fa" have entirely different histories.

3 changed files with 61 additions and 144 deletions

173
README.md
View file

@ -1,172 +1,117 @@
# Crafter.Build # About
A modern, cross-platform C++ build system designed specifically for C++20 modules. Built with simplicity and flexibility in mind. This is a simple and easy to use C++ build system for Linux designed for use with C++20 modules in mind, it uses JSON based project files.
## Features # Install
- **C++20 Modules Support**: Native support for modern C++ module systems ## Prerequisites:
- **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
lld lld
clang clang
git git
lldb lldb
onetbb onetbb
glslang glslang
vulkan-devel
``` ```
### Build from Source ## Build from source
```bash ```bash
git clone https://forgejo.catcrafts.net/Catcrafts/Crafter.Build.git git clone https://github.com/Catcrafts/Crafter.Build.git
cd Crafter.Build cd Crafter.Build
./build.sh ./build.sh
``` ```
(Optionally add to your PATH for global access) (optionally add to path)
## Getting Started # How to use
### Quickstart Guide ## Quickstart
1. Create a `project.json` file in your project directory: create a ``project.json`` in an empty folder, open it in your preferred text editor.
```json Create a basic project file, with a base configuration and debug and release configuration
```JSON
{ {
"name": "hello-world", "name": "hello-world",
"configurations": [ "configurations": [
{ {
"name": "executable", "name": "base",
"implementations": ["main"], "standard": "c++26",
"source_files": ["main"],
"module_files": [],
"build_dir": "./build",
"output_dir": "./bin"
}, },
{ {
"name": "executable-debug", "name": "debug",
"extends": ["executable"], "extends": ["base"],
"debug": true "optimization_level": "0"
}, }
{
"name": "release",
"extends": ["base"],
"optimization_level": "3"
}
] ]
} }
``` ```
Save and close the file, create a ``main.cpp``
2. Create `main.cpp`:
```cpp ```cpp
#include <print> #include <print>
int main() { int main() {
std::println("Hello World!"); std::println("Hello World!");
} }
``` ```
Save and close, then run ``crafter-build -c debug``. Now you can run the ``hello-world`` executable that has appeared in the ``bin`` folder
3. Build and run: ## CLI arguments
```bash
crafter-build build debug -r
```
## Command Line Interface ``--help`` Displays a help message.
```bash ``-c`` The name of the configuration to build.
# Build a specific configuration
crafter-build build [configuration]
# Run a specific test ``-p`` The path to the project file, defaults to ``project.json``.
crafter-build test [test]
# Run all tests ``-o`` Overrides the output folder.
crafter-build test
# Display help information ``-r`` Runs the executable after building.
crafter-build --help
# Specify project file path (defaults to project.json) ## configuration properties
-p /path/to/project.json ``name`` Name of the configuration.
# Run executable after building ``standard`` C++ standard that this configuration uses, please refer to the [relevant clang documentation](https://clang.llvm.org/cxx_status.html), defaults to ``c++26``.
-r
```
## Test Configuration ``source_files`` All source files of the project ``.cpp`` extension is assumed.
Tests are defined in the `tests` array of your project file. A typical test configuration depends on your main project: ``module_files`` All C++ 20 module files of the project ``.cppm`` extension is assumed.
```json ``additional_files`` Files that will be copied to the output_dir.
"tests": [
{
"name": "should-compile",
"implementations": ["tests/ShouldCompile"],
"dependencies": [
{
"path": "./project.json",
"configuration": "lib-shared"
}
]
}
]
```
### Writing Test Files ``build_dir`` The directory where intermediate files are stored.
Test files must follow a specific format: ``output_dir`` The directory where the output files will be placed.
- 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
Example test implementation: ``type`` The type of the project: ``executable``, ``library``, ``shared-library``, defaults to ``executable``.
```cpp
import std;
using namespace std;
extern "C" { ``extends`` An array of configuration names that this configuration extends, later elements in the array take priority over previous ones.
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;
}
}
```
## Configuration Properties ``optimization_level`` Please refer to the [relevant clang documentation](https://clang.llvm.org/docs/CommandGuide/clang.html#code-generation-options), defaults to ``0``.
### Basic Properties ``dependencies`` An object array of the dependencies of this project, example:
- **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`)
### Dependencies
Both local and git dependencies are supported:
For git dependencies branch and commit are mutually exclusive, if neither is supplied the latest commit on the default branch is chosen
```json ```json
"dependencies": [ "dependencies": [
{ {
"path": "/home/Crafter.Build/project.json", "path":"/home/Crafter.Build/project.json",
"configuration": "debug-lib", "configuration":"debug-lib",
}, "commit":"af7eb61c3d92ab18f6aa6c139ac7211a908a24ee"
}
{ {
"path": "https://github.com/Catcrafts/Crafter.Build.git", "path":"https://github.com/Catcrafts/Crafter.Build.git",
"configuration": "debug-lib", "configuration":"debug-lib",
"branch": "master", "branch":"master"
"commit": "af7eb61c3d92ab18f6aa6c139ac7211a908a24ee"
} }
] ]
``` ```
This will now link the library of Crafter.Build in the configuration you use this in. ``commit`` and ``branch`` are optional parameters, if omitted the latest commit on the default branch is used.
## License ``target`` Clang triplet this configuration uses, please refer to the [relevant clang documentation](https://clang.llvm.org/docs/CrossCompilation.html#target-triple).
This project is licensed under the LGPL v3 License - see the LICENSE file for details. Note: the WASI SDK needs to be installed to compile to webassmbly, and ``$WASI_SDK_PATH`` needs to be set, please refer to the [wasi-sdk installation guide](https://github.com/WebAssembly/wasi-sdk?tab=readme-ov-file#install).

View file

@ -22,16 +22,8 @@ import std;
using namespace Crafter; using namespace Crafter;
namespace fs = std::filesystem; namespace fs = std::filesystem;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if(std::string(argv[1]) == "--help" || std::string(argv[1]) == "help" ) { if(std::string(argv[1]) == "--help") {
std::println("Crafter.Build - A modern build system for C++ projects\n"); std::println("--help\tDisplays this help message.\n-c The name of the configuration to build.\n-p The path to the project file. defualts to project.json\n-o Overrides the output folder.\n-r Runs the executable after building.");
std::println("Usage: crafter-build [command] [options]");
std::println("\nCommands:");
std::println(" build\t\tBuild the project");
std::println(" test\t\tRun project tests");
std::println("\nOptions:");
std::println(" --help\tDisplay this help message");
std::println(" -p PATH\tSpecify the project file path (default: project.json)");
std::println(" -r\t\tRun the built executable after building");
return 0; return 0;
} }
if(argc < 2 && std::string(argv[1]) == "build") { if(argc < 2 && std::string(argv[1]) == "build") {

View file

@ -44,26 +44,6 @@
"configuration":"lib-shared" "configuration":"lib-shared"
} }
] ]
},
{
"name": "example-test",
"implementations": ["tests/ExampleTest"],
"dependencies": [
{
"path":"./project.json",
"configuration":"lib-shared"
}
]
},
{
"name": "test-structure",
"implementations": ["tests/TestStructure"],
"dependencies": [
{
"path":"./project.json",
"configuration":"lib-shared"
}
]
} }
] ]
} }