Skip to content

Commit 8091c84

Browse files
committed
release: v0.2.0
1 parent 973ba30 commit 8091c84

File tree

6 files changed

+259
-47
lines changed

6 files changed

+259
-47
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ This project follows a simple versioning strategy:
88
- fixes → patch
99

1010
---
11+
## v0.2.0
12+
13+
### Added
14+
- Add CMakePresets.json for unified configure/build/test workflows (Ninja + MSVC)
15+
- Add examples CMake integration with executable targets
16+
- Add benchmark targets (render, parse, cache)
17+
18+
### Changed
19+
- Refactor cache usage to support non-copyable Template objects
20+
- Switch cache storage to shared immutable template handles
21+
- Improve overall CMake structure with modular subdirectories (tests, examples, benchmarks)
22+
23+
### Fixed
24+
- Fix build failure caused by copying Template containing unique_ptr
25+
- Ensure benchmarks and examples are properly included in root build
26+
1127
## [0.1.1] - fix(cache)
1228
- fix(cache): store compiled templates through shared immutable handles instead of copying non-copyable Template objects
1329

CMakeLists.txt

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ project(template
1212

1313
option(TEMPLATE_BUILD_TESTS "Build template tests" ON)
1414
option(TEMPLATE_BUILD_EXAMPLES "Build template examples" ON)
15-
option(TEMPLATE_BUILD_BENCHMARKS "Build template benchmarks" OFF)
15+
option(TEMPLATE_BUILD_BENCHMARKS "Build template benchmarks" ON)
1616
option(TEMPLATE_INSTALL "Enable install rules" ON)
1717

1818
# ============================================================================
@@ -36,22 +36,22 @@ endif()
3636
# ============================================================================
3737

3838
add_library(template
39+
src/Builtins.cpp
40+
src/Cache.cpp
41+
src/Compiler.cpp
42+
src/Context.cpp
3943
src/Engine.cpp
4044
src/Environment.cpp
41-
src/Template.cpp
42-
src/Value.cpp
43-
src/Context.cpp
4445
src/Error.cpp
45-
src/Loader.cpp
46+
src/Escape.cpp
4647
src/FileSystemLoader.cpp
47-
src/StringLoader.cpp
4848
src/Lexer.cpp
49+
src/Loader.cpp
4950
src/Parser.cpp
50-
src/Compiler.cpp
5151
src/Renderer.cpp
52-
src/Builtins.cpp
53-
src/Escape.cpp
54-
src/Cache.cpp
52+
src/StringLoader.cpp
53+
src/Template.cpp
54+
src/Value.cpp
5555
)
5656

5757
add_library(vix::template ALIAS template)
@@ -69,14 +69,16 @@ target_compile_features(template PUBLIC cxx_std_20)
6969
# ============================================================================
7070

7171
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
72-
target_compile_options(template PRIVATE
73-
-Wall
74-
-Wextra
75-
-Wpedantic
72+
target_compile_options(template
73+
PRIVATE
74+
-Wall
75+
-Wextra
76+
-Wpedantic
7677
)
7778
elseif(MSVC)
78-
target_compile_options(template PRIVATE
79-
/W4
79+
target_compile_options(template
80+
PRIVATE
81+
/W4
8082
)
8183
endif()
8284

@@ -96,23 +98,7 @@ target_compile_definitions(template
9698
# ============================================================================
9799

98100
if(TEMPLATE_BUILD_EXAMPLES)
99-
add_executable(template_basic_render examples/basic_render.cpp)
100-
target_link_libraries(template_basic_render PRIVATE vix::template)
101-
102-
add_executable(template_render_file examples/render_file.cpp)
103-
target_link_libraries(template_render_file PRIVATE vix::template)
104-
105-
add_executable(template_layout_inheritance examples/layout_inheritance.cpp)
106-
target_link_libraries(template_layout_inheritance PRIVATE vix::template)
107-
108-
add_executable(template_includes examples/includes.cpp)
109-
target_link_libraries(template_includes PRIVATE vix::template)
110-
111-
add_executable(template_loops_and_conditions examples/loops_and_conditions.cpp)
112-
target_link_libraries(template_loops_and_conditions PRIVATE vix::template)
113-
114-
add_executable(template_filters examples/filters.cpp)
115-
target_link_libraries(template_filters PRIVATE vix::template)
101+
add_subdirectory(examples)
116102
endif()
117103

118104
# ============================================================================

CMakePresets.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 20,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "dev-ninja",
11+
"displayName": "Dev (Ninja, Debug)",
12+
"generator": "Ninja",
13+
"binaryDir": "${sourceDir}/build-ninja",
14+
"cacheVariables": {
15+
"CMAKE_BUILD_TYPE": "Debug",
16+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
17+
"TEMPLATE_BUILD_TESTS": "ON",
18+
"TEMPLATE_BUILD_EXAMPLES": "ON",
19+
"TEMPLATE_BUILD_BENCHMARKS": "ON",
20+
"TEMPLATE_INSTALL": "ON"
21+
}
22+
},
23+
{
24+
"name": "release",
25+
"displayName": "Release (Ninja, Release)",
26+
"generator": "Ninja",
27+
"binaryDir": "${sourceDir}/build-release",
28+
"cacheVariables": {
29+
"CMAKE_BUILD_TYPE": "Release",
30+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
31+
"TEMPLATE_BUILD_TESTS": "ON",
32+
"TEMPLATE_BUILD_EXAMPLES": "ON",
33+
"TEMPLATE_BUILD_BENCHMARKS": "ON",
34+
"TEMPLATE_INSTALL": "ON"
35+
}
36+
},
37+
{
38+
"name": "dev-msvc",
39+
"displayName": "Dev (MSVC, Release)",
40+
"generator": "Visual Studio 17 2022",
41+
"architecture": {
42+
"value": "x64"
43+
},
44+
"binaryDir": "${sourceDir}/build-msvc",
45+
"cacheVariables": {
46+
"CMAKE_CONFIGURATION_TYPES": "Release",
47+
"TEMPLATE_BUILD_TESTS": "ON",
48+
"TEMPLATE_BUILD_EXAMPLES": "ON",
49+
"TEMPLATE_BUILD_BENCHMARKS": "ON",
50+
"TEMPLATE_INSTALL": "ON"
51+
}
52+
}
53+
],
54+
"buildPresets": [
55+
{
56+
"name": "build-ninja",
57+
"displayName": "Build (ALL, Ninja Debug)",
58+
"configurePreset": "dev-ninja"
59+
},
60+
{
61+
"name": "build-release",
62+
"displayName": "Build (ALL, Ninja Release)",
63+
"configurePreset": "release"
64+
},
65+
{
66+
"name": "build-msvc",
67+
"displayName": "Build (ALL, MSVC)",
68+
"configurePreset": "dev-msvc",
69+
"configuration": "Release"
70+
}
71+
],
72+
"testPresets": [
73+
{
74+
"name": "test-ninja",
75+
"displayName": "Test (Ninja Debug)",
76+
"configurePreset": "dev-ninja",
77+
"output": {
78+
"outputOnFailure": true
79+
}
80+
},
81+
{
82+
"name": "test-release",
83+
"displayName": "Test (Ninja Release)",
84+
"configurePreset": "release",
85+
"output": {
86+
"outputOnFailure": true
87+
}
88+
},
89+
{
90+
"name": "test-msvc",
91+
"displayName": "Test (MSVC Release)",
92+
"configurePreset": "dev-msvc",
93+
"configuration": "Release",
94+
"output": {
95+
"outputOnFailure": true
96+
}
97+
}
98+
]
99+
}

benchmarks/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
cmake_minimum_required(VERSION 3.20)
22

3+
if(NOT TARGET vix::template)
4+
message(FATAL_ERROR "Target vix::template not found")
5+
endif()
6+
37
add_executable(template_render_bench
48
render_bench.cpp
59
)
@@ -26,3 +30,11 @@ target_link_libraries(template_cache_bench
2630
PRIVATE
2731
vix::template
2832
)
33+
34+
set_target_properties(
35+
template_render_bench
36+
template_parse_bench
37+
template_cache_bench
38+
PROPERTIES
39+
FOLDER "benchmarks"
40+
)

benchmarks/cache_bench.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <chrono>
1717
#include <iostream>
1818
#include <map>
19-
#include <optional>
19+
#include <memory>
2020
#include <string>
2121

2222
#include <vix/template/Cache.hpp>
@@ -27,17 +27,19 @@ using namespace vix::template_;
2727
class MemoryCache : public Cache
2828
{
2929
public:
30-
std::optional<Template> get(const std::string &name) const override
30+
TemplatePtr get(const std::string &name) const override
3131
{
3232
const auto it = store_.find(name);
3333
if (it == store_.end())
34-
return std::nullopt;
34+
{
35+
return nullptr;
36+
}
3537
return it->second;
3638
}
3739

38-
void put(const std::string &name, const Template &tpl) override
40+
void put(const std::string &name, TemplatePtr tpl) override
3941
{
40-
store_[name] = tpl;
42+
store_[name] = std::move(tpl);
4143
}
4244

4345
bool erase(const std::string &name) override
@@ -56,37 +58,36 @@ class MemoryCache : public Cache
5658
}
5759

5860
private:
59-
std::map<std::string, Template> store_;
61+
std::map<std::string, TemplatePtr> store_;
6062
};
6163

62-
static Template make_template(const std::string &name)
64+
static TemplatePtr make_template(const std::string &name)
6365
{
64-
return Template(name, RootNode{});
66+
return std::make_shared<Template>(name, RootNode{});
6567
}
6668

6769
int main()
6870
{
6971
MemoryCache cache;
7072

71-
const int entries = 1000;
72-
const int iterations = 100000;
73+
constexpr int entries = 1000;
74+
constexpr int iterations = 100000;
7375

74-
// Fill cache
7576
for (int i = 0; i < entries; ++i)
7677
{
7778
cache.put("tpl_" + std::to_string(i), make_template("tpl"));
7879
}
7980

80-
auto start = std::chrono::high_resolution_clock::now();
81+
const auto start = std::chrono::high_resolution_clock::now();
8182

8283
for (int i = 0; i < iterations; ++i)
8384
{
8485
const std::string key = "tpl_" + std::to_string(i % entries);
85-
auto tpl = cache.get(key);
86+
TemplatePtr tpl = cache.get(key);
8687
(void)tpl;
8788
}
8889

89-
auto end = std::chrono::high_resolution_clock::now();
90+
const auto end = std::chrono::high_resolution_clock::now();
9091

9192
const auto duration =
9293
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);

0 commit comments

Comments
 (0)