Skip to content

Commit 97c07ac

Browse files
committed
feat: Add xmake build system configuration for Atom project
- Introduced xmake build scripts (build.bat, build.sh) for easier project setup and compilation. - Created xmake.lua files for various modules (image, memory, secret, serial) to define build targets and dependencies. - Added example and test configurations to facilitate building and running examples and tests. - Enhanced difflib and uuid modules with additional parameters and improved error handling. - Documented the build process and options in XMAKE_BUILD.md for user guidance.
1 parent c721d40 commit 97c07ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4944
-995
lines changed

XMAKE_BUILD.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Atom xmake构建系统
2+
3+
这个文件夹包含了使用xmake构建Atom库的配置文件。xmake是一个轻量级的跨平台构建系统,可以更简单地构建C/C++项目。
4+
5+
## 安装xmake
6+
7+
在使用本构建系统之前,请先安装xmake:
8+
9+
- 官方网站:<https://xmake.io/>
10+
- GitHub:<https://github.com/xmake-io/xmake>
11+
12+
### Windows安装
13+
14+
```powershell
15+
# 使用PowerShell安装
16+
Invoke-Expression (Invoke-Webrequest 'https://xmake.io/psget.ps1' -UseBasicParsing).Content
17+
```
18+
19+
### Linux/macOS安装
20+
21+
```bash
22+
# 使用bash安装
23+
curl -fsSL https://xmake.io/shget.text | bash
24+
```
25+
26+
## 快速构建
27+
28+
我们提供了简单的构建脚本来简化构建过程:
29+
30+
### Windows
31+
32+
```cmd
33+
# 默认构建(Release模式,静态库)
34+
build.bat
35+
36+
# 构建Debug版本
37+
build.bat --debug
38+
39+
# 构建共享库
40+
build.bat --shared
41+
42+
# 构建Python绑定
43+
build.bat --python
44+
45+
# 构建示例
46+
build.bat --examples
47+
48+
# 构建测试
49+
build.bat --tests
50+
51+
# 查看所有选项
52+
build.bat --help
53+
```
54+
55+
### Linux/macOS
56+
57+
```bash
58+
# 默认构建(Release模式,静态库)
59+
./build.sh
60+
61+
# 构建Debug版本
62+
./build.sh --debug
63+
64+
# 构建共享库
65+
./build.sh --shared
66+
67+
# 构建Python绑定
68+
./build.sh --python
69+
70+
# 构建示例
71+
./build.sh --examples
72+
73+
# 构建测试
74+
./build.sh --tests
75+
76+
# 查看所有选项
77+
./build.sh --help
78+
```
79+
80+
## 手动构建
81+
82+
如果你想手动配置构建选项,可以使用以下命令:
83+
84+
```bash
85+
# 配置项目
86+
xmake config [选项]
87+
88+
# 构建项目
89+
xmake build
90+
91+
# 安装项目
92+
xmake install
93+
```
94+
95+
### 可用的配置选项
96+
97+
- `--build_python=y/n`: 启用/禁用Python绑定构建
98+
- `--shared_libs=y/n`: 构建共享库或静态库
99+
- `--build_examples=y/n`: 启用/禁用示例构建
100+
- `--build_tests=y/n`: 启用/禁用测试构建
101+
- `--enable_ssh=y/n`: 启用/禁用SSH支持
102+
- `-m debug/release`: 设置构建模式
103+
104+
例如:
105+
106+
```bash
107+
xmake config -m debug --build_python=y --shared_libs=y
108+
```
109+
110+
## 项目结构
111+
112+
这个构建系统使用了模块化的设计,每个子目录都有自己的`xmake.lua`文件:
113+
114+
- `xmake.lua`:根配置文件
115+
- `atom/xmake.lua`:主库配置
116+
- `atom/*/xmake.lua`:各模块配置
117+
- `example/xmake.lua`:示例配置
118+
- `tests/xmake.lua`:测试配置
119+
120+
## 自定义安装位置
121+
122+
你可以通过以下方式指定安装位置:
123+
124+
```bash
125+
xmake install -o /path/to/install
126+
```
127+
128+
## 打包
129+
130+
你可以使用xmake的打包功能创建发布包:
131+
132+
```bash
133+
xmake package
134+
```
135+
136+
## 清理构建文件
137+
138+
```bash
139+
xmake clean
140+
```
141+
142+
## 故障排除
143+
144+
如果遇到构建问题,可以尝试以下命令:
145+
146+
```bash
147+
# 清理所有构建文件并重新构建
148+
xmake clean -a
149+
xmake
150+
151+
# 查看详细构建信息
152+
xmake -v
153+
154+
# 更新xmake并重试
155+
xmake update
156+
xmake
157+
```

atom/algorithm/xmake.lua

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,64 @@
1-
-- xmake.lua for Atom-Algorithm
2-
-- This project is licensed under the terms of the GPL3 license.
3-
--
4-
-- Project Name: Atom-Algorithm
5-
-- Description: A collection of algorithms
1+
-- filepath: d:\msys64\home\qwdma\Atom\atom\algorithm\xmake.lua
2+
-- xmake configuration for Atom-Algorithm module
63
-- Author: Max Qian
74
-- License: GPL3
85

6+
-- Add standard build modes
7+
add_rules("mode.debug", "mode.release")
8+
9+
-- Project configuration
10+
set_project("atom-algorithm")
11+
set_version("1.0.0")
12+
set_license("GPL3")
13+
14+
-- Define source files (adjust these based on your actual files)
15+
local sources = {} -- Add algorithm source files here
16+
17+
-- Define header files (adjust these based on your actual files)
18+
local headers = {
19+
"*.hpp" -- This will include all hpp files in the directory
20+
}
21+
22+
-- Object Library
23+
target("atom-algorithm_object")
24+
set_kind("object")
25+
26+
-- Add files
27+
if #sources > 0 then
28+
add_files(table.unpack(sources))
29+
end
30+
add_headerfiles(table.unpack(headers))
31+
32+
-- Add include directories
33+
add_includedirs(".", {public = true})
34+
add_includedirs("..", {public = true})
35+
36+
-- Set C++ standard
37+
set_languages("c++20")
38+
target_end()
39+
40+
-- Library target
41+
target("atom-algorithm")
42+
-- Set library type based on parent project option
43+
set_kind(has_config("shared_libs") and "shared" or "static")
44+
45+
-- Add dependencies
46+
add_deps("atom-algorithm_object")
47+
48+
-- Set output directories
49+
set_targetdir("$(buildir)/lib")
50+
set_objectdir("$(buildir)/obj")
51+
52+
-- Install configuration
53+
on_install(function (target)
54+
os.cp(target:targetfile(), path.join(target:installdir(), "lib"))
55+
os.cp("*.hpp", path.join(target:installdir(), "include/atom/algorithm"))
56+
end)
57+
target_end()
58+
59+
-- Remove previous package definition which seems to be unused
60+
-- Uncomment if you actually need this package
61+
--[[
962
package("foo")
1063
add_deps("cmake")
1164
set_sourcedir(path.join(os.scriptdir(), "foo"))
@@ -19,3 +72,4 @@ package("foo")
1972
assert(package:has_cfuncs("add", {includes = "foo.h"}))
2073
end)
2174
package_end()
75+
]]

atom/async/eventstack.hpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Description: A thread-safe stack data structure for managing events.
1919
#include <atomic>
2020
#include <concepts>
2121
#include <exception>
22+
#include <functional> // Required for std::function
2223
#include <mutex>
2324
#include <optional>
2425
#include <shared_mutex>
@@ -849,10 +850,18 @@ auto EventStack<T>::getEventsView() const noexcept -> std::span<const T> {
849850
// design for lock-free.
850851
return std::span<const T>();
851852
#else
852-
std::shared_lock lock(mtx_);
853-
// For std::vector<bool>, .data() is deleted, but span can be constructed
854-
// from iterators.
855-
return std::span<const T>(events_.begin(), events_.end());
853+
if constexpr (std::is_same_v<T, bool>) {
854+
// std::vector<bool>::iterator is not a contiguous_iterator in the C++20
855+
// sense, and std::to_address cannot be used to get a bool* for it.
856+
// Thus, std::span cannot be directly constructed from its iterators
857+
// in the typical way that guarantees a view over contiguous bools.
858+
// Returning an empty span to avoid compilation errors and indicate this
859+
// limitation.
860+
return std::span<const T>();
861+
} else {
862+
std::shared_lock lock(mtx_);
863+
return std::span<const T>(events_.begin(), events_.end());
864+
}
856865
#endif
857866
}
858867

@@ -898,23 +907,24 @@ void EventStack<T>::transformEvents(Func&& transformFunc) {
898907
#if ATOM_ASYNC_USE_LOCKFREE
899908
std::vector<T> elements = drainStack();
900909
try {
901-
// For bool, handle std::vector<bool>::reference explicitly if
902-
// transformFunc expects bool&
910+
// Wrap the transformFunc in std::function to help with template
911+
// deduction
912+
std::function<void(T&)> wrapped_func = transformFunc;
903913
if constexpr (std::is_same_v<T, bool>) {
904914
Parallel::for_each(
905915
elements.begin(), elements.end(),
906-
[&transformFunc](
916+
// Capture the std::function by copy for the inner lambda
917+
[wrapped_func_copy = wrapped_func](
907918
typename std::vector<T>::reference event_ref) {
908-
bool val = event_ref; // Convert proxy to bool
909-
transformFunc(val); // Call user function with bool&
910-
// (to a local bool)
919+
bool val = event_ref; // Convert proxy to bool
920+
wrapped_func_copy(val); // Call user function with
921+
// bool& (to a local bool)
911922
event_ref = val; // Assign back from the (potentially
912923
// modified) local bool
913924
});
914925
} else {
915-
Parallel::for_each(
916-
elements.begin(), elements.end(),
917-
transformFunc); // Pass transformFunc as lvalue
926+
Parallel::for_each(elements.begin(), elements.end(),
927+
wrapped_func);
918928
}
919929
} catch (...) {
920930
refillStack(elements); // Refill on error
@@ -923,22 +933,22 @@ void EventStack<T>::transformEvents(Func&& transformFunc) {
923933
refillStack(elements); // Refill after processing
924934
#else
925935
std::unique_lock lock(mtx_);
926-
// For bool, handle std::vector<bool>::reference explicitly if
927-
// transformFunc expects bool&
936+
// Wrap the transformFunc in std::function to help with template
937+
// deduction
938+
std::function<void(T&)> wrapped_func = transformFunc;
928939
if constexpr (std::is_same_v<T, bool>) {
929940
// Manual loop or a Parallel::for_each that handles proxy references
930941
// correctly. Assuming Parallel::for_each might not handle
931942
// std::vector<bool>::reference well with a bool& functor.
932943
for (typename std::vector<T>::reference event_ref : events_) {
933944
bool val = event_ref; // Convert proxy to bool
934-
transformFunc(
945+
wrapped_func(
935946
val); // Call user function with bool& (to a local bool)
936947
event_ref = val; // Assign back from the (potentially modified)
937948
// local bool
938949
}
939950
} else {
940-
Parallel::for_each(events_.begin(), events_.end(),
941-
transformFunc); // Pass transformFunc as lvalue
951+
Parallel::for_each(events_.begin(), events_.end(), wrapped_func);
942952
}
943953
#endif
944954
} catch (const std::exception& e) {

0 commit comments

Comments
 (0)