Skip to content

Commit 8fefdc0

Browse files
authored
build single header releases
1 parent 70870b3 commit 8fefdc0

File tree

16 files changed

+742
-605
lines changed

16 files changed

+742
-605
lines changed

.github/workflows/unit_tests.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
BUILD_TYPE: Debug
1111

1212
jobs:
13-
build:
13+
build_and_test:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
fail-fast: false
@@ -70,3 +70,31 @@ jobs:
7070
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
7171
run: ctest -C ${{env.BUILD_TYPE}}
7272

73+
release:
74+
needs: build_and_test
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v3
78+
with:
79+
submodules: recursive
80+
81+
- name: Configure CMake
82+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
83+
84+
- name: Build
85+
# Build your program with the given configuration
86+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target release
87+
88+
- name: 'Upload Artifact'
89+
uses: actions/upload-artifact@v3
90+
with:
91+
name: cib.hpp
92+
path: build/cib.hpp
93+
94+
- name: Release
95+
uses: softprops/[email protected]
96+
if: startsWith(github.ref, 'refs/tags/')
97+
with:
98+
files: build/cib.hpp
99+
100+

CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,19 @@ target_include_directories(Cib
1616

1717
target_sources(Cib
1818
INTERFACE
19-
${CMAKE_CURRENT_SOURCE_DIR}/include/cib/core.hpp)
19+
${CMAKE_CURRENT_SOURCE_DIR}/include/cib/cib.hpp)
20+
21+
22+
add_custom_command(
23+
DEPENDS
24+
${CMAKE_SOURCE_DIR}/include/cib/*
25+
${CMAKE_SOURCE_DIR}/include/cib/detail/*
26+
COMMAND
27+
python3 ${CMAKE_SOURCE_DIR}/tools/gen_release_header.py ${CMAKE_SOURCE_DIR}/include/cib/cib.hpp > ${CMAKE_BINARY_DIR}/cib.hpp
28+
OUTPUT
29+
${CMAKE_BINARY_DIR}/cib.hpp
30+
)
31+
32+
add_custom_target(release
33+
DEPENDS
34+
${CMAKE_BINARY_DIR}/cib.hpp)

include/cib/builder_meta.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef COMPILE_TIME_INIT_BUILD_BUILDER_META_HPP
2+
#define COMPILE_TIME_INIT_BUILD_BUILDER_META_HPP
3+
4+
5+
#include "detail/compiler.hpp"
6+
7+
#include <utility>
8+
9+
10+
namespace cib {
11+
template<
12+
typename BuilderT,
13+
typename InterfaceT>
14+
struct builder_meta {
15+
BuilderT builder();
16+
InterfaceT interface();
17+
};
18+
19+
namespace traits {
20+
template<typename MetaT>
21+
struct builder {
22+
using type = decltype(std::declval<MetaT>().builder());
23+
};
24+
25+
template<typename MetaT>
26+
using builder_t = typename builder<MetaT>::type;
27+
28+
template<typename MetaT>
29+
CIB_CONSTEXPR builder_t<MetaT> builder_v = {};
30+
31+
template<typename MetaT>
32+
struct interface {
33+
using type = decltype(std::declval<MetaT>().interface());
34+
};
35+
36+
template<typename MetaT>
37+
using interface_t = typename interface<MetaT>::type;
38+
}
39+
}
40+
41+
42+
#endif //COMPILE_TIME_INIT_BUILD_BUILDER_META_HPP

include/cib/built.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef COMPILE_TIME_INIT_BUILD_BUILT_HPP
2+
#define COMPILE_TIME_INIT_BUILD_BUILT_HPP
3+
4+
5+
#include "builder_meta.hpp"
6+
7+
8+
namespace cib {
9+
/**
10+
* Pointer to a concrete built service.
11+
*
12+
* @tparam Tag Type name of the service.
13+
*/
14+
template<typename Tag>
15+
traits::interface_t<Tag> built;
16+
}
17+
18+
19+
#endif //COMPILE_TIME_INIT_BUILD_BUILT_HPP

include/cib/callback.hpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#ifndef COMPILE_TIME_INIT_BUILD_CALLBACK_HPP
2+
#define COMPILE_TIME_INIT_BUILD_CALLBACK_HPP
3+
4+
5+
#include "builder_meta.hpp"
6+
#include "detail/meta.hpp"
7+
#include "detail/compiler.hpp"
8+
9+
#include <array>
10+
#include <type_traits>
11+
12+
13+
namespace cib {
14+
/**
15+
* Extension point/builder for simple callbacks.
16+
*
17+
* Modules can add their own callback function to this builder to be executed when
18+
* the builder is executed with the same function arguments.
19+
*
20+
* @tparam Size
21+
* Maximum number of callbacks that may be registered.
22+
*
23+
* @tparam Args
24+
* List of argument types that must be passed into the callback when it is invoked.
25+
*/
26+
template<int Size = 0, typename... Args>
27+
struct callback {
28+
private:
29+
using func_ptr_t = void(*)(Args...);
30+
31+
std::array<func_ptr_t, Size> funcs;
32+
33+
template<typename BuilderValue>
34+
static void run(Args... args) {
35+
CIB_CONSTEXPR auto handlerBuilder = BuilderValue::value;
36+
CIB_CONSTEXPR auto numFuncs = std::integral_constant<int, Size>{};
37+
38+
detail::for_each(numFuncs, [&](auto i){
39+
CIB_CONSTEXPR auto func = handlerBuilder.funcs[i];
40+
func(args...);
41+
});
42+
}
43+
44+
public:
45+
CIB_CONSTEVAL callback() = default;
46+
47+
template<typename PrevFuncsT>
48+
CIB_CONSTEVAL callback(
49+
PrevFuncsT const & prev_funcs,
50+
func_ptr_t new_func
51+
)
52+
: funcs{}
53+
{
54+
for (int i = 0; i < prev_funcs.size(); i++) {
55+
funcs[i] = prev_funcs[i];
56+
}
57+
58+
funcs[Size - 1] = new_func;
59+
}
60+
61+
// cib uses "add(...)" to add features to service builders
62+
CIB_CONSTEVAL auto add(func_ptr_t const & func) const {
63+
return callback<Size + 1, Args...>{funcs, func};
64+
}
65+
66+
/**
67+
* Build and return a function pointer to the implemented callback builder. Used
68+
* by cib library to automatically build an initialized builder. Do not call.
69+
*
70+
* @tparam BuilderValue
71+
* Struct that contains a "static constexpr auto value" field with the initialized
72+
* builder.
73+
*
74+
* @return
75+
* Function pointer to callback builder.
76+
*/
77+
template<typename BuilderValue>
78+
[[nodiscard]] CIB_CONSTEVAL static auto build() {
79+
return run<BuilderValue>;
80+
}
81+
};
82+
83+
template<typename... Args>
84+
struct callback_meta :
85+
public cib::builder_meta<
86+
callback<0, Args...>,
87+
void(*)(Args...)>
88+
{};
89+
}
90+
91+
92+
#endif //COMPILE_TIME_INIT_BUILD_CALLBACK_HPP

include/cib/cib.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef COMPILE_TIME_INIT_BUILD_CIB_HPP
2+
#define COMPILE_TIME_INIT_BUILD_CIB_HPP
3+
4+
5+
/*
6+
* Boost Software License - Version 1.0 - August 17th, 2003
7+
*
8+
* Permission is hereby granted, free of charge, to any person or organization
9+
* obtaining a copy of the software and accompanying documentation covered by
10+
* this license (the "Software") to use, reproduce, display, distribute,
11+
* execute, and transmit the Software, and to prepare derivative works of the
12+
* Software, and to permit third-parties to whom the Software is furnished to
13+
* do so, all subject to the following:
14+
*
15+
* The copyright notices in the Software and this entire statement, including
16+
* the above license grant, this restriction and the following disclaimer,
17+
* must be included in all copies of the Software, in whole or in part, and
18+
* all derivative works of the Software, unless such copies or derivative
19+
* works are solely in the form of machine-executable object code generated by
20+
* a source language processor.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25+
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26+
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28+
* DEALINGS IN THE SOFTWARE.
29+
*/
30+
31+
32+
/*
33+
* cib - Compile-time Initialization and Build
34+
* https://github.com/intel/compile-time-init-build
35+
*/
36+
37+
38+
#include "callback.hpp"
39+
#include "nexus.hpp"
40+
#include "built.hpp"
41+
#include "config.hpp"
42+
#include "detail/compiler.hpp"
43+
#include "detail/meta.hpp"
44+
#include "builder_meta.hpp"
45+
46+
47+
#endif //COMPILE_TIME_INIT_BUILD_CIB_HPP

0 commit comments

Comments
 (0)