Skip to content

Commit

Permalink
integrate verbm
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolacula committed Jan 27, 2025
1 parent ab78a1f commit 52a1c94
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 416 deletions.
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Diagnostics:
UnusedIncludes: Strict
14 changes: 0 additions & 14 deletions .github/ISSUE_TEMPLATE/sweep-template.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: bump

on:
push:
branches: ["main"]

permissions:
contents: write

jobs:
bump:
runs-on: ubuntu-latest
if: ${{ ! startsWith(github.event.head_commit.message, 'Version bumped') }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0 # we need all history to get tags and analyze commits

- run: |
git config user.name "Maxim Voloshin"
git config user.email "[email protected]"
- name: Install verbm
run: pipx install verbm

- name: Bump version
run: verbm up auto --commit --tag --push
36 changes: 11 additions & 25 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,27 @@ on:
branches: [main]
workflow_dispatch: {}

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v2

# - name: Get version
# run: echo "VERSION=$(python ./version.py get -f vcpkg.json)" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ github.workspace }}/build
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
- name: Install generator
run: |
wget -O gen.zip https://github.com/chocolacula/easy_reflection_cpp/releases/download/3.0.0/er_gen-ubuntu22-x64.zip
unzip gen.zip -d output
chmod +x output/er_gen
mkdir build && cd build &&
cmake ..
-DCMAKE_BUILD_TYPE:STRING=Release
-DENABLE_GENERATOR:STRING=ON
-DLLVM_TARGETS_TO_BUILD:STRING=X86
- name: Build
run: cmake --build ./build -j $(grep -c 'processor' /proc/cpuinfo) -t tests
run: >
cmake --build ./build -j 2
-t er_gen tests
- name: Test
working-directory: ${{ github.workspace }}/build
working-directory: ./build
run: ctest --rerun-failed --output-on-failure
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
.idea
.vs
.cache
.DS_Store

output
cmake-build*
build

example/generated
tests/generated
benchmarks/generated

.DS_Store
16 changes: 1 addition & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ set_policies()

set(CMAKE_TOOLCHAIN_FILE vcpkg/scripts/buildsystems/vcpkg.cmake)

# Get version from vcpkg.json manifest
file(READ "${CMAKE_SOURCE_DIR}/vcpkg.json" VCPKG_MANIFEST_JSON)

string(JSON
VCPKG_MANIFEST_PROJECT_VERSION
ERROR_VARIABLE VCPKG_VERSION_ERROR
GET ${VCPKG_MANIFEST_JSON} "version")

if(VCPKG_VERSION_ERROR)
message(WARNING ${VCPKG_VERSION_ERROR})
set(VCPKG_MANIFEST_PROJECT_VERSION "0.0.0")
endif()

# Enable vcpkg features
option(ENABLE_TESTS "Enable tests" ON)
option(ENABLE_GENERATOR "Enable generator" OFF)
Expand All @@ -35,13 +22,12 @@ if(ENABLE_BENCHMARKS)
endif()

# Setup project
project(easy_reflection VERSION ${VCPKG_MANIFEST_PROJECT_VERSION})
project(easy_reflection VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

include(Dart)
enable_testing()

add_subdirectory(library)
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It parses C++ source code for special attributes. In the most straightforward si
The main idea is to use kinda dynamic typing for some type agnostic operations, like copying or getting the name of a type.
It makes it possible to determine a variable type and do the right job - print, serialize/deserialize.

If you are curious about the details of how it works you can find them in [DEV article](https://dev.to/chocolacula/how-to-write-reflection-for-c-4527).
It's generally a proof of concept, created with the idea that it could be used for many years. If you are curious about the details of how it works, you can find them in [DEV article](https://dev.to/chocolacula/how-to-write-reflection-for-c-4527).

## Features

Expand Down Expand Up @@ -83,5 +83,3 @@ JetBrains for Open Source Support
<a href="https://jb.gg/OpenSourceSupport">
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg" alt="JetBrains Logo" style="width:128px;height:128px;">
</a>


2 changes: 0 additions & 2 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "data/colors.h"
#include "er/reflection/reflection.h"
#include "er/serialization/json.h"
#include "er/serialization/yaml.h"
#include "er/variable/box.h"
#include "generated/reflection.h"
#include "print.h"

Expand Down
18 changes: 8 additions & 10 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ set(SOURCES

add_executable(${PROJECT_NAME} ${SOURCES})

target_compile_definitions(${PROJECT_NAME} PRIVATE VERSION="${PROJECT_VERSION}")

find_path(TCLAP_INCLUDE_DIRS "tclap/Arg.h")
include_directories(${TCLAP_INCLUDE_DIRS})

Expand All @@ -44,18 +42,18 @@ endif()
update_submodule(llvm-project)
apply_patch(../attribute.patch llvm-project)

set(LLVM_ENABLE_RTTI ON)
set(LLVM_INCLUDE_BENCHMARKS OFF)
set(LLVM_ENABLE_PROJECTS "clang")
set(LLVM_ENABLE_RTTI ON CACHE INTERNAL "enable runtime type information")
set(LLVM_INCLUDE_BENCHMARKS OFF CACHE INTERNAL "avoid building benchmarks")
set(LLVM_ENABLE_PROJECTS "clang" CACHE INTERNAL "build llvm with clang")

add_subdirectory(llvm-project/llvm EXCLUDE_FROM_ALL)

include_directories(
llvm-project/llvm/include
${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/include
${CMAKE_CURRENT_BINARY_DIR}/llvm-project/utils/bazel/llvm-project-overlay/llvm/include
llvm-project/clang/include
${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/tools/clang/include)
llvm-project/llvm/include
${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/include
${CMAKE_CURRENT_BINARY_DIR}/llvm-project/utils/bazel/llvm-project-overlay/llvm/include
llvm-project/clang/include
${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/tools/clang/include)

target_link_libraries(${PROJECT_NAME} PRIVATE
clangAST
Expand Down
6 changes: 5 additions & 1 deletion generator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
#include "inja/inja.hpp"
#include "inja/template.hpp"

namespace {
const char* const kVersion = "0.1.0";
} // namespace

int main(int argc, const char** argv) {
TCLAP::CmdLine cmd("Easy Reflection code generator", ' ', VERSION);
TCLAP::CmdLine cmd("Easy Reflection code generator", ' ', kVersion);

Files file_manager;

Expand Down
63 changes: 9 additions & 54 deletions readme/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@ The project consits of two main parts:
- [Reflection library](../library)
- [Code generator](../generator)

The Easy Reflection C++ Generator utilizes **Clang** libraries to analyze C++ source code. By default, these libraries are statically linked to facilitate distribution and provide precompiled binary [releases](https://github.com/chocolacula/easy_reflection_cpp/releases).
The Easy Reflection C++ Generator utilizes **Clang** libraries to analyze C++ source code. To support reflection attributes in the source code, I had to patch `llvm` and link it as a dependency. Therefore, the only option is to build `llvm` from source. Be patient, as this process will not be quick.

Before getting started, you should decide whether to use the precompiled binary release or build the generator manually. If you choose the manual option, configure and build the generator. CMake will handle everything for you.

Once you have the `er_gen` binary, you can start analyzing your project and generating code. To do this, ensure that your project produces a `compile_commands.json` file. If you're using CMake, you can easily enable this by adding the following line to your CMakeLists.txt file:
To analyze your project and generate reflection code, ensure you have a `compile_commands.json` file. If you're using CMake, you can easily enable this by adding the following line to your `CMakeLists.txt` file:

```cmake
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
```

### Troubleshooting

If you encounter errors like `stddef.h` or `stdarg.h` not being found during the generation process, add the following line to your `CMakeLists.txt` file:

```cmake
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
```

### Windows
## Windows

Visual Studio CMake generators do not create `compile_commands.json`. However, you can use [Ninja](https://ninja-build.org/) instead.

Expand All @@ -38,10 +28,6 @@ If you choose the MSVC compiler, additionally install:
- C++ ATL
- Windows SDK

### Docker

This repository includes a `Dockerfile` that sets up an `Ubuntu 22.04` environment, builds the generator, and runs tests on startup.

## Further steps

Another submodule is [vcpkg](https://github.com/microsoft/vcpkg) which manages most of the dependencies, all of them will be installed by CMake automatically.
Expand All @@ -54,45 +40,14 @@ If, for some reason, you want to exclude `simdjson` from the dependencies, you c
-DUSE_SIMD_JSON=OFF
```

## LLVM & Clang dynamic linking

It is not supported officialy but nevertheless it exists.

Replace lines in the end of [CMakeLists.txt](../generator/CMakeLists.txt)

```cmake
find_package(LLVM REQUIRED)
include_directories(${LLVM_INCLUDE_DIR})
link_directories(${LLVM_LIBRARY_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE LLVM clang-cpp)
```

### Linux

You can install libraries from package manager of your distro such as **Ubuntu** or **Arch Linux** or build them from source:

```bash
cd llvm-project/build
## Docker

cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang -DLLVM_ENABLE_RTTI=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCLANG_LINK_CLANG_DYLIB=ON ../llvm
```

### Apple
This repository includes a `Dockerfile` that sets up an `Ubuntu 22.04` environment, builds the generator, and runs tests on startup.

Apple's macOS doesn't have standard Clang libs by default, but happily you can use `brew`.
## Troubleshooting

```bash
brew install llvm
```

Don't forget to specify the path to LLVM.
If you encounter errors like `stddef.h` or `stdarg.h` not being found during the generation process, add the following line to your `CMakeLists.txt` file:

```bash
-DLLVM_DIR=/opt/homebrew/opt/llvm/lib/cmake/llvm
```cmake
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
```

### Windows

Regrettably, MSVC does not support for this feature. However, there is some dark magic with MinGW and Clang you can delve into. Unfortunately, I cannot provide assistance with that particular matter.
42 changes: 0 additions & 42 deletions sweep.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reflection-cpp",
"version": "3.1.0",
"version": "0.1.0",
"default-features": [
"library"
],
Expand Down
Loading

0 comments on commit 52a1c94

Please sign in to comment.