diff --git a/README.md b/README.md index d3edd14..e084c12 100644 --- a/README.md +++ b/README.md @@ -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 -- **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 +## Prerequisites: +``` lld clang git lldb onetbb glslang -vulkan-devel ``` -### Build from Source +## Build from source ```bash -git clone https://forgejo.catcrafts.net/Catcrafts/Crafter.Build.git +git clone https://github.com/Catcrafts/Crafter.Build.git cd Crafter.Build ./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: -```json +create a ``project.json`` in an empty folder, open it in your preferred text editor. +Create a basic project file, with a base configuration and debug and release configuration +```JSON { "name": "hello-world", "configurations": [ { - "name": "executable", - "implementations": ["main"], + "name": "base", + "standard": "c++26", + "source_files": ["main"], + "module_files": [], + "build_dir": "./build", + "output_dir": "./bin" }, { - "name": "executable-debug", - "extends": ["executable"], - "debug": true - }, + "name": "debug", + "extends": ["base"], + "optimization_level": "0" + } + { + "name": "release", + "extends": ["base"], + "optimization_level": "3" + } ] } ``` - -2. Create `main.cpp`: +Save and close the file, create a ``main.cpp`` ```cpp #include 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: -```bash -crafter-build build debug -r -``` +## CLI arguments -## Command Line Interface +``--help`` Displays a help message. -```bash -# Build a specific configuration -crafter-build build [configuration] +``-c`` The name of the configuration to build. -# Run a specific test -crafter-build test [test] +``-p`` The path to the project file, defaults to ``project.json``. -# Run all tests -crafter-build test +``-o`` Overrides the output folder. -# Display help information -crafter-build --help +``-r`` Runs the executable after building. -# Specify project file path (defaults to project.json) --p /path/to/project.json +## configuration properties +``name`` Name of the configuration. -# Run executable after building --r -``` +``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``. -## 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 -"tests": [ - { - "name": "should-compile", - "implementations": ["tests/ShouldCompile"], - "dependencies": [ - { - "path": "./project.json", - "configuration": "lib-shared" - } - ] - } -] -``` +``additional_files`` Files that will be copied to the output_dir. -### Writing Test Files +``build_dir`` The directory where intermediate files are stored. -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 +``output_dir`` The directory where the output files will be placed. -Example test implementation: -```cpp -import std; -using namespace std; +``type`` The type of the project: ``executable``, ``library``, ``shared-library``, defaults to ``executable``. -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; - } -} -``` +``extends`` An array of configuration names that this configuration extends, later elements in the array take priority over previous ones. -## 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 -- **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 +``dependencies`` An object array of the dependencies of this project, example: ```json "dependencies": [ { - "path": "/home/Crafter.Build/project.json", - "configuration": "debug-lib", - }, + "path":"/home/Crafter.Build/project.json", + "configuration":"debug-lib", + "commit":"af7eb61c3d92ab18f6aa6c139ac7211a908a24ee" + } { - "path": "https://github.com/Catcrafts/Crafter.Build.git", - "configuration": "debug-lib", - "branch": "master", - "commit": "af7eb61c3d92ab18f6aa6c139ac7211a908a24ee" + "path":"https://github.com/Catcrafts/Crafter.Build.git", + "configuration":"debug-lib", + "branch":"master" } ] ``` +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. \ No newline at end of file +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). diff --git a/implementations/main.cpp b/implementations/main.cpp index 287e644..1ea7dac 100644 --- a/implementations/main.cpp +++ b/implementations/main.cpp @@ -22,16 +22,8 @@ import std; using namespace Crafter; namespace fs = std::filesystem; int main(int argc, char* argv[]) { - if(std::string(argv[1]) == "--help" || std::string(argv[1]) == "help" ) { - std::println("Crafter.Build - A modern build system for C++ projects\n"); - 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"); + if(std::string(argv[1]) == "--help") { + 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."); return 0; } if(argc < 2 && std::string(argv[1]) == "build") { diff --git a/project.json b/project.json index 1472628..1afdc27 100644 --- a/project.json +++ b/project.json @@ -44,26 +44,6 @@ "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" - } - ] } ] } \ No newline at end of file