Skip to content

Commit 0435bcd

Browse files
authored
improved README.md (#32)
1 parent eef8357 commit 0435bcd

File tree

1 file changed

+167
-3
lines changed

1 file changed

+167
-3
lines changed

README.md

Lines changed: 167 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
44
[![Unit Tests](https://github.com/intel/compile-time-init-build/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/intel/compile-time-init-build/actions/workflows/unit_tests.yml)
55

6-
## Overview
7-
8-
*cib* is a C++ header-only library for building embedded firmware with reusable
6+
*cib* is a C++ header-only library for building embedded firmware with reusable
97
components. It implements the compile-time initialization and build pattern.
108
Instead of initializing components and registering callbacks at runtime, this
119
process is executed at compile-time using constexpr or consteval functions.
@@ -16,3 +14,169 @@ component provides **services** and **features** to the build. Component
1614

1715
*cib* is currently in a prerelease state and its API is subject to change.
1816

17+
## Installing / Getting started
18+
19+
*cib* is released as a single header file as well as the zipped github repo.
20+
To get started quickly, download the cib.hpp header from the
21+
[release area](https://github.com/intel/compile-time-init-build/releases):
22+
23+
```shell
24+
wget https://github.com/intel/compile-time-init-build/releases/download/v0.1.0/cib.hpp
25+
```
26+
27+
Another option is to include cib as a
28+
[git submodule](https://github.blog/2016-02-01-working-with-submodules/)
29+
in your repo and add the cib directory in your CMakeLists.txt file:
30+
31+
```cmake
32+
add_subdirectory(lib/compile-time-init-build)
33+
target_link_libraries(your_target PRIVATE Cib)
34+
```
35+
36+
With either of these methods, include the cib.hpp header in your code to use it.
37+
38+
### Hello, world!
39+
40+
Since *cib* is a library for efficiently building firmware through composition
41+
a simple example takes a few more lines than a typical "Hello, world!"
42+
43+
#### core.hpp
44+
The `core` component of this example **exports** the `say_message` **service**. Pay close
45+
attention to the `#include` directives in each file.
46+
```c++
47+
#include <cib/cib.hpp>
48+
49+
struct say_message : public cib::callback_meta<>{};
50+
51+
struct core {
52+
constexpr static auto config =
53+
cib::config(cib::exports<say_message>);
54+
};
55+
```
56+
#### hello_world.hpp
57+
The `hello_world` component **extends** the `say_message` **service** with new
58+
contained in a lambda.
59+
```c++
60+
#include <iostream>
61+
#include <cib/cib.hpp>
62+
63+
struct hello_world {
64+
constexpr static auto config =
65+
cib::config(
66+
cib::extend<say_message>([](){
67+
std::cout << "Hello, world!" << std::endl;
68+
})
69+
);
70+
};
71+
```
72+
#### lazy_dog.hpp
73+
Another component, `lazy_dog` is also extending the `say_message` **service**.
74+
This time it is using a function pointer instead of a lambda. The function
75+
definition of `talk_about_the_dog` could also be placed in a `lazy_dog.cpp`
76+
file if desired.
77+
```c++
78+
#include <iostream>
79+
#include <cib/cib.hpp>
80+
81+
struct lazy_dog {
82+
static void talk_about_the_dog() {
83+
std::cout << "The quick brown fox jumps over the lazy dog." << std::endl;
84+
}
85+
86+
constexpr static auto config =
87+
cib::config(
88+
cib::extend<say_message>(talk_about_the_dog)
89+
);
90+
};
91+
```
92+
#### my_project.hpp
93+
All the components are brought together in the project configuration, `my_project`.
94+
```c++
95+
#include "core.hpp"
96+
#include "hello_world.hpp"
97+
#include "lazy_dog.hpp"
98+
99+
struct my_project {
100+
constexpr static auto config =
101+
cib::components<core, hello_world, lazy_dog>;
102+
};
103+
```
104+
#### main.cpp
105+
The `cib::nexus` brings all the **services** and **features** together. This is
106+
where the compile-time initialization and build process actually occurs.
107+
```c++
108+
#include "my_project.hpp"
109+
110+
cib::nexus<my_project> nexus{};
111+
112+
int main() {
113+
// services can be accessed directly from the nexus...
114+
nexus.service<say_message>();
115+
116+
// ...or they can be accessed anywhere through cib::service
117+
nexus.init();
118+
cib::service<say_message>();
119+
}
120+
```
121+
#### Execution
122+
All of the initialization and registration occurs at compile-time, but the
123+
new functionality is still executed at run-time:
124+
```
125+
shell> ./my_project
126+
Hello, world!
127+
The quick brown fox jumps over the lazy dog.
128+
Hello, world!
129+
The quick brown fox jumps over the lazy dog.
130+
```
131+
132+
### Building
133+
134+
*cib* is built with CMake. The single header is built with the
135+
`release_header` target:
136+
137+
```shell
138+
cmake -B build
139+
cmake --build build -t release_header
140+
ls build/include/cib/ | grep cib.hpp
141+
```
142+
143+
This combines all the *cib* header files in the `include` tree by recursively
144+
including the `#include` directives and ignoring all other macros.
145+
146+
Unit tests are registered with CTest:
147+
148+
```shell
149+
cmake -B build
150+
cmake --build build -t tests
151+
ctest
152+
```
153+
154+
This will build and run all the unit tests with CMake and Catch2.
155+
156+
## Features
157+
158+
* Compose modular firmware systems with high-level abstractions
159+
* Perform registration of components at compile-time
160+
* 🏎 Optimize runtime-performance and memory usage
161+
* 🦺 Catch undefined behavior during initialization
162+
163+
## Contributing
164+
165+
If you'd like to contribute, please fork the repository and use a feature
166+
branch. Pull requests are warmly welcome.
167+
168+
For more details on contributing, please see [CONTRIBUTING.md](CONTRIBUTING.md)
169+
170+
## Links
171+
172+
- Repository: https://github.com/intel/compile-time-init-build/
173+
- Issue tracker: https://github.com/intel/compile-time-init-build/issues
174+
- In case of sensitive bugs like security vulnerabilities, please contact
175+
one or more of the project maintainers directly instead of using issue
176+
tracker. We value your effort to improve the security and privacy of this
177+
project!
178+
179+
## Licensing
180+
181+
The code in this project is licensed under the BSL-1.0 license. See
182+
[LICENSE.md](LICENSE.md) for more details.

0 commit comments

Comments
 (0)