From ac931fb96d8f1b0b6c8187eb05f0ac712c678ad3 Mon Sep 17 00:00:00 2001 From: Donald Filimon Date: Sun, 6 Jul 2025 10:05:17 -0400 Subject: [PATCH] Ignore build directories --- .gitignore | 2 ++ CONTRIBUTING.md | 10 ++++++++++ README.md | 3 +++ cell_framework/CMakeLists.txt | 35 ++++++++++++++++++++++++++++++++++ cell_framework/Cell/Core.cpp | 11 +++++++++++ cell_framework/Cell/Core.ixx | 14 ++++++++++++++ cell_framework/README.md | 27 ++++++++++++++++++++++++++ cell_framework/main.cpp | 7 +++++++ scripts/generate_headers.cmake | 10 ++++++++++ 9 files changed, 119 insertions(+) create mode 100644 CONTRIBUTING.md create mode 100644 cell_framework/CMakeLists.txt create mode 100644 cell_framework/Cell/Core.cpp create mode 100644 cell_framework/Cell/Core.ixx create mode 100644 cell_framework/README.md create mode 100644 cell_framework/main.cpp create mode 100644 scripts/generate_headers.cmake diff --git a/.gitignore b/.gitignore index af614f13b..71396f911 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ **/*.DS_Store **/*.zig-cache +# Ignore build directories +*/build/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..14458c274 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contributing + +Please write clear commit messages that briefly describe the changes. +For example: + +``` +Add Cell framework example using C++23 modules +``` + +Commit messages like "Applying previous commit" should be avoided. diff --git a/README.md b/README.md index 3dae2b346..c33b2a3ac 100644 --- a/README.md +++ b/README.md @@ -30,3 +30,6 @@ To predict a probability with the trained model: zig run local_ml.zig -- predict model.txt 1.2 3.4 ``` + +### Cell Framework Example +This repository now includes a demonstration of the Cell framework using modern C++23 modules. See `cell_framework/README.md` for build instructions. diff --git a/cell_framework/CMakeLists.txt b/cell_framework/CMakeLists.txt new file mode 100644 index 000000000..7253c3852 --- /dev/null +++ b/cell_framework/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.26) +project(CellFramework LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 1) + +# Directory for generated headers +set(GENERATED_INCLUDE_DIR ${CMAKE_BINARY_DIR}/include) +file(MAKE_DIRECTORY ${GENERATED_INCLUDE_DIR}) + +add_custom_target(generate_headers + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_headers.cmake + BYPRODUCTS ${GENERATED_INCLUDE_DIR}/Cell/Core.hpp + VERBATIM +) + +add_library(CellCore) + +target_sources(CellCore + PUBLIC + FILE_SET cxx_modules TYPE CXX_MODULES FILES + ${CMAKE_CURRENT_SOURCE_DIR}/Cell/Core.ixx + FILE_SET cxx_modules TYPE CXX_MODULES FILES + ${CMAKE_CURRENT_SOURCE_DIR}/Cell/Core.cpp +) + +target_include_directories(CellCore PUBLIC ${GENERATED_INCLUDE_DIR}) + +add_dependencies(CellCore generate_headers) + +add_executable(cell_app main.cpp) + +target_link_libraries(cell_app PRIVATE CellCore) + +add_dependencies(cell_app generate_headers) diff --git a/cell_framework/Cell/Core.cpp b/cell_framework/Cell/Core.cpp new file mode 100644 index 000000000..a0ed2f418 --- /dev/null +++ b/cell_framework/Cell/Core.cpp @@ -0,0 +1,11 @@ +module; +#include + +module Cell.Core; + +namespace Cell { + void Engine::run() { + std::cout << "Cell Engine running!" << std::endl; + std::cout << "2 + 2 = " << add(2, 2) << std::endl; + } +} diff --git a/cell_framework/Cell/Core.ixx b/cell_framework/Cell/Core.ixx new file mode 100644 index 000000000..609ae65a7 --- /dev/null +++ b/cell_framework/Cell/Core.ixx @@ -0,0 +1,14 @@ +export module Cell.Core; + +export import ; + +export namespace Cell { + inline int add(int a, int b) { + return a + b; + } + + class Engine { + public: + void run(); + }; +} diff --git a/cell_framework/README.md b/cell_framework/README.md new file mode 100644 index 000000000..f4518f423 --- /dev/null +++ b/cell_framework/README.md @@ -0,0 +1,27 @@ +# Cell Framework Example with C++23 Modules + +This example demonstrates the Cell framework using a modules-first design. +The build system uses CMake 3.26+ with the experimental C++ module API and +automatically generates traditional headers from module interface files. + +## Prerequisites + +- CMake 3.26 or newer +- A C++23 compiler with module support (Clang 18+ or equivalent) + +## Building + +```bash +mkdir build && cd build +cmake .. +cmake --build . +./cell_app +``` + +CMake should be invoked from a separate `build` directory to keep +generated files isolated from the source tree. + +During configuration, module interfaces located in the `Cell/` directory are +converted into headers under `build/include/Cell`. These generated headers +allow interoperability with code that still relies on the traditional `#include` +mechanism. diff --git a/cell_framework/main.cpp b/cell_framework/main.cpp new file mode 100644 index 000000000..239dbf731 --- /dev/null +++ b/cell_framework/main.cpp @@ -0,0 +1,7 @@ +import Cell.Core; + +int main() { + Cell::Engine engine; + engine.run(); + return 0; +} diff --git a/scripts/generate_headers.cmake b/scripts/generate_headers.cmake new file mode 100644 index 000000000..5c8ae44a2 --- /dev/null +++ b/scripts/generate_headers.cmake @@ -0,0 +1,10 @@ +# Simple header generation from module interface files +file(GLOB MODULE_FILES "${CMAKE_CURRENT_LIST_DIR}/../cell_framework/Cell/*.ixx") +foreach(MFILE ${MODULE_FILES}) + get_filename_component(MNAME ${MFILE} NAME_WE) + set(HEADER "${GENERATED_INCLUDE_DIR}/Cell/${MNAME}.hpp") + file(MAKE_DIRECTORY "${GENERATED_INCLUDE_DIR}/Cell") + file(READ ${MFILE} CONTENTS) + string(REGEX REPLACE "export module ([A-Za-z0-9_.]+);" "#pragma once\n// Generated from module \1" CONTENTS "${CONTENTS}") + file(WRITE ${HEADER} "${CONTENTS}") +endforeach()