Sese Framework
Intro
This is a cross-platform framework for developing fundamental components, used to some extent as a supplement to the standard library. It is positioned similarly to Boost
and folly
with respect to the standard library. The project uses C++ 20 standard and introduces vcpkg as a package manager to help us simplify dependency management issues.
Demo
Builtin logger
Modern formatting style
++
template<>
struct Formatter<Point> {
bool parse(
const std::string &) {
return true; }
void format(FmtCtx &ctx,
const Point &p) {
ctx.builder <<
fmt(
"({},{})", p.x, p.y);
}
};
}
Point point{1, 2};
Logger::info("hello world");
Logger::info(
"a + b = {}",
a +
b);
Logger::info("point {}", point);
2024-06-27T01:43:05.571Z I main.cpp:7 Main:10376> hello world
2024-06-27T01:43:05.572Z I main.cpp:8 Main:10376> a + b = 3
2024-06-27T01:43:05.572Z I main.cpp:9 Main:10376> point (1,2)
HTTP Controller
++
#include <sese/service/http/HttpServer_V3.h>
SESE_CTRL(MyController, std::mutex mutex{};
int times = 0) {
SESE_URL(timers, RequestType::GET,
"/times") {
auto &resp = ctx.getResp();
times += 1;
auto message = "timers = '" + std::to_string(this->times) + "'\n";
resp.getBody().write(message.data(), message.length());
};
SESE_URL(say, RequestType::GET,
"/say?<say>") {
auto &resp = ctx.getResp();
auto words = req.get("say");
auto message = "you say '" + words + "'\n";
resp.getBody().write(message.data(), message.length());
};
}
Inter-Process communication
++
while (true) {
auto messages = channel->read(1);
if (messages.empty()) {
continue;
}
for (auto &&msg: messages) {
if (msg.getDataAsString() == "Exit") {
goto end;
}
}
}
end:
return 0;
channel->write(1, "Hello");
channel->write(2, "Hi");
channel->write(1, "Exit");
Build
For Developers/Contributors
- Configure the development environment
For Windows users, please install and config the vcpkg.
For non-Windows users, vcpkg is likewise available. But at the same time, you can choose to install the dependencies using the native system dependency management tool. We have provided several preset installation scripts.
sudo ./scripts/install_ubuntu_deps.sh
sudo ./scripts/install_fedora_deps.sh
./scripts/install_darwin_deps.sh
- Compilation options
If you have vcpkg configured, you can simply configure the dependencies by setting the toolchain file.
If you're using a system dependency management tool, you'll need to manually add the 'SESE_USE_NATIVE_MANAGER' compilation option after pressing the corresponding dependency.
https://github.com/libsese/sese/blob/4cd74389d7105b71c632070c775a727be8ee413d/CMakeLists.txt#L8-L16
- Compile
Configuring the finished compilation options only requires a regular build, such as:
cmake --build build/linux-debug -- -j 4
For Normal Users
For common users, we recommend using vcpkg to import this dependency, you can refer to our template project to config your project()
- Warning
- Projects can also be installed on ordinary machines as normal projects, but this is not a recommended practice and cannot be supported. If you want to do this, you can refer to the 'Build' > 'For Developers/Contributors' section on dependency management tools.
The main job is to write the project's dependency configuration file, for example:
vcpkg.json
{
"dependencies": [
"sese"
]
}
- Important
- Since the built-in baseline
14b91796a68c87bc8d5cb35911b39287ccb7bd95
, sese has been included in the built-in list. Before this, you needed to create an additional configuration file to import our private registry, just like this:
vcpkg-configuration.json
{
"default-registry": {
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg.git",
"baseline": "c8696863d371ab7f46e213d8f5ca923c4aef2a00"
},
"registries": [
{
"kind": "git",
"repository": "https://github.com/libsese/vcpkg-registry.git",
"baseline": "73268778d5f796f188ca66f71536377b171ee37e",
"packages": [
"sese"
]
}
]
}
If you're not using vcpkg, the above steps are unnecessary.
Testing
We used googletest as our testing framework. Detailed information about our tests can be found in github actions, including the results of various platforms and linux test coverage.
| Platform | Entry | Unit Test | Coverage Test | |–|–|–|–| | Windows | Unit Tests | ✅ | | Linux | Unit Tests | ✅ | ✅ | | macOS | Unit Tests | ✅ |
- Local Testing
- Services on Ubuntu workflow
If you need to run full tests locally, you may need to pay attention to the database side of the test, which requires some additional service and configuration support.
https://github.com/libsese/sese/blob/4cd74389d7105b71c632070c775a727be8ee413d/.github/workflows/ubuntu-22.04-apt.yml#L14-L34
https://github.com/libsese/sese/blob/4cd74389d7105b71c632070c775a727be8ee413d/.github/workflows/ubuntu-22.04-apt.yml#L45-L53
https://github.com/libsese/sese/blob/4cd74389d7105b71c632070c775a727be8ee413d/.github/workflows/ubuntu-22.04-apt.yml#L72-L75
- Deploy services through docker-compose
docker-compose -f ./docker/docker-compose.yml up -d
sqlite3 build/db_test.db < scripts/sqlite_dump.sql
- Generate coverage test reports
Gcovr needs to be installed, either by pip or using the System Package Manager.
mkdir -p build/coverage/html
gcovr
- Note
- Generating coverage test data first requires setting some additional compilation options to generate test data such as gcov format, such as GCC compilation options:
https://github.com/libsese/sese/blob/4cd74389d7105b71c632070c775a727be8ee413d/.github/workflows/ubuntu-22.04-apt.yml#L75
Documents
Documents will be updated automatically with the update of the main branch to making pages.
Document content is automatically generated from code comments, and the docs directory actually houses some of the resources needed to build the document.
Contributors
License