Skip to content

Commit

Permalink
Merge pull request #1138 from waruqi/master
Browse files Browse the repository at this point in the history
Improve xmake.lua
  • Loading branch information
Barenboim authored Jan 3, 2023
2 parents 3a55cb9 + 085bcd8 commit 4216034
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/xmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name : run shared
run: |
xmake f --type=shared
xmake f -k shared
xmake -r
xmake -g test
xmake -g tutorial
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ bazel-*
.idea
cmake-build-debug/
workflow-config.cmake

# xmake configs
.xmake
build.xmake
_include
2 changes: 1 addition & 1 deletion benchmark/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set_default(false)

add_deps("workflow")

if not is_os("macosx") then
if not is_plat("macosx") then
add_ldflags("-lrt")
end

Expand Down
5 changes: 2 additions & 3 deletions docs/en/xmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ sudo xmake install

```
// compile static lib
xmake f --type=static
xmake f -k static
xmake -r
```

```
// compile shard lib
xmake f --type=shared
xmake f -k shared
xmake -r
```

Expand All @@ -56,7 +56,6 @@ xmake -r
Command options (Project Configuration):
--workflow_inc=WORKFLOW_INC workflow inc (default: /media/psf/pro/workflow/_include)
--type=TYPE build lib static/shared (default: static)
--upstream=[y|n] build upstream component (default: y)
--consul=[y|n] build consul component
--workflow_lib=WORKFLOW_LIB workflow lib (default: /media/psf/pro/workflow/_lib)
Expand Down
7 changes: 3 additions & 4 deletions docs/xmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ sudo xmake install

```
// 编译静态库
xmake f --type=static
xmake f -k static
xmake -r
```

```
// 编译动态库
xmake f --type=shared
xmake f -k shared
xmake -r
```

Expand All @@ -58,7 +58,6 @@ xmake -r
Command options (Project Configuration):
--workflow_inc=WORKFLOW_INC workflow inc (default: /media/psf/pro/workflow/_include)
--type=TYPE build lib static/shared (default: static)
--upstream=[y|n] build upstream component (default: y)
--consul=[y|n] build consul component
--workflow_lib=WORKFLOW_LIB workflow lib (default: /media/psf/pro/workflow/_lib)
Expand All @@ -72,4 +71,4 @@ Command options (Project Configuration):
```
xmake f --redis=n --kafka=y --mysql=n
xmake -r
```
```
7 changes: 4 additions & 3 deletions src/client/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ target("client")
set_kind("object")
add_files("*.cc")
remove_files("WFKafkaClient.cc")
if (get_config("mysql") == false) then
if not has_config("mysql") then
remove_files("WFMySQLConnection.cc")
end
if (get_config("consul") == false) then
if not has_config("consul") then
remove_files("WFConsulClient.cc")
end

target("kafka_client")
if (get_config("kafka") == true) then
if has_config("kafka") then
add_files("WFKafkaClient.cc")
set_kind("object")
add_deps("client")
add_packages("zlib", "snappy", "zstd", "lz4")
else
set_kind("phony")
end
7 changes: 4 additions & 3 deletions src/factory/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
target("factory")
add_files("*.cc")
set_kind("object")
if (get_config("mysql") == false) then
if not has_config("mysql") then
remove_files("MySQLTaskImpl.cc")
end
if (get_config("redis") == false) then
if not has_config("redis") then
remove_files("RedisTaskImpl.cc")
end
remove_files("KafkaTaskImpl.cc")

target("kafka_factory")
if (get_config("kafka") == true) then
if has_config("kafka") then
add_files("KafkaTaskImpl.cc")
set_kind("object")
add_cxxflags("-fno-rtti")
add_deps("factory")
add_packages("zlib", "snappy", "zstd", "lz4")
else
set_kind("phony")
end
4 changes: 2 additions & 2 deletions src/manager/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
target("manager")
add_files("*.cc")
set_kind("object")
if (get_config("upstrem") == false) then
if not has_config("upstrem") then
remove_files("UpstreamManager.cc")
end
end
4 changes: 2 additions & 2 deletions src/nameservice/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
target("nameservice")
add_files("*.cc")
set_kind("object")
if (get_config("upstrem") == false) then
if not has_config("upstrem") then
remove_files("WFServiceGovernance.cc", "UpstreamPolicies.cc")
end

11 changes: 6 additions & 5 deletions src/protocol/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target("basic_protocol")
"HttpUtil.cc")

target("mysql_protocol")
if (get_config("mysql") == true) then
if has_config("mysql") then
add_files("mysql_stream.c",
"mysql_parser.c",
"mysql_byteorder.c",
Expand All @@ -24,7 +24,7 @@ target("mysql_protocol")
end

target("redis_protocol")
if (get_config("redis") == true) then
if has_config("redis") then
add_files("redis_parser.c", "RedisMessage.cc")
set_kind("object")
add_deps("basic_protocol")
Expand All @@ -37,7 +37,7 @@ target("protocol")
add_deps("basic_protocol", "mysql_protocol", "redis_protocol")

target("kafka_message")
if (get_config("kafka") == true) then
if has_config("kafka") then
add_files("KafkaMessage.cc")
set_kind("object")
add_cxxflags("-fno-rtti")
Expand All @@ -47,12 +47,13 @@ target("kafka_message")
end

target("kafka_protocol")
if (get_config("kafka") == true) then
if has_config("kafka") then
set_kind("object")
add_files("kafka_parser.c",
"KafkaDataTypes.cc",
"KafkaResult.cc")
add_deps("kafka_message", "protocol")
add_packages("zlib", "snappy", "zstd", "lz4")
else
set_kind("phony")
end
end
4 changes: 2 additions & 2 deletions src/server/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
target("server")
set_kind("object")
add_files("*.cc")
if (get_config("mysql") == false) then
if not has_config("mysql") then
remove_files("WFMySQLServer.cc")
end
end
4 changes: 2 additions & 2 deletions src/util/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ target("util")
remove_files("crc32c.c")

target("kafka_util")
if (get_config("kafka") == true) then
if has_config("kafka") then
set_kind("object")
add_files("crc32c.c")
else
else
set_kind("phony")
end
78 changes: 35 additions & 43 deletions src/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,59 +1,51 @@
includes("**/xmake.lua")

target("workflow")
if (get_config("type") == "static") then
set_kind("static")
else
set_kind("shared")
end
set_kind("$(kind)")
add_deps("algorithm", "client", "factory", "kernel", "manager",
"nameservice", "protocol", "server", "util")

target("wfkafka")
if (get_config("kafka") == true) then
if (get_config("type") == "static") then
set_kind("static")
else
set_kind("shared")
end
if has_config("kafka") then
set_kind("$(kind)")
add_deps("kafka_client", "kafka_factory", "kafka_protocol", "kafka_util", "workflow")
else
set_kind("phony")
end

on_load(function (package)
local include_path = path.join(get_config("workflow_inc"), "workflow")
if (not os.isdir(include_path)) then
os.mkdir(include_path)
end
on_load(function (package)
local include_path = path.join(get_config("workflow_inc"), "workflow")
if (not os.isdir(include_path)) then
os.mkdir(include_path)
end

os.cp(path.join("$(projectdir)", "src/**.h"), include_path)
os.cp(path.join("$(projectdir)", "src/**.inl"), include_path)
end)
os.cp(path.join("$(projectdir)", "src/**.h"), include_path)
os.cp(path.join("$(projectdir)", "src/**.inl"), include_path)
end)

after_build(function (target)
local lib_dir = get_config("workflow_lib")
if (not os.isdir(lib_dir)) then
os.mkdir(lib_dir)
end
if (get_config("type") == "static") then
os.mv(path.join("$(projectdir)", target:targetdir(), "*.a"), lib_dir)
else
os.mv(path.join("$(projectdir)", target:targetdir(), "*.so"), lib_dir)
end
end)
after_build(function (target)
local lib_dir = get_config("workflow_lib")
if (not os.isdir(lib_dir)) then
os.mkdir(lib_dir)
end
if target:is_static() then
os.mv(path.join("$(projectdir)", target:targetdir(), "*.a"), lib_dir)
else
os.mv(path.join("$(projectdir)", target:targetdir(), "*.so"), lib_dir)
end
end)

after_clean(function (target)
os.rm(get_config("workflow_inc"))
os.rm(get_config("workflow_lib"))
os.rm("$(buildir)")
end)
after_clean(function (target)
os.rm(get_config("workflow_inc"))
os.rm(get_config("workflow_lib"))
os.rm("$(buildir)")
end)

on_install(function (package)
os.cp(path.join(get_config("workflow_inc"), "workflow"), path.join(package:installdir(), "include"))
if (get_config("type") == "static") then
os.cp(path.join(get_config("workflow_lib"), "*.a"), path.join(package:installdir(), "lib"))
else
os.cp(path.join(get_config("workflow_lib"), "*.so"), path.join(package:installdir(), "lib"))
end
end)
on_install(function (target)
os.cp(path.join(get_config("workflow_inc"), "workflow"), path.join(target:installdir(), "include"))
if target:is_static() then
os.cp(path.join(get_config("workflow_lib"), "*.a"), path.join(target:installdir(), "lib"))
else
os.cp(path.join(get_config("workflow_lib"), "*.so"), path.join(target:installdir(), "lib"))
end
end)
6 changes: 3 additions & 3 deletions test/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function all_tests()
for _, x in ipairs(os.files("**.cc")) do
local item = {}
local s = path.filename(x)
if ((s == "upstream_unittest.cc" and get_config("upstream") == false) or
(s == "redis_unittest.cc" and get_config("redis") == false) or
(s == "mysql_unittest.cc" and get_config("mysql") == false)) then
if ((s == "upstream_unittest.cc" and not has_config("upstream")) or
(s == "redis_unittest.cc" and not has_config("redis")) or
(s == "mysql_unittest.cc" and not has_config("mysql"))) then
else
table.insert(item, s:sub(1, #s - 3)) -- target
table.insert(item, path.relative(x, ".")) -- source
Expand Down
2 changes: 1 addition & 1 deletion tutorial/tutorial-10-user_defined_protocol/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ target("user_defined_client")
target("client-uds")
set_kind("binary")
add_files("client-uds.cc")
add_deps("user_defined_message")
add_deps("user_defined_message")
12 changes: 6 additions & 6 deletions tutorial/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set_group("tutorial")
set_default(false)

if not is_os("macosx") then
if not is_plat("macosx") then
add_ldflags("-lrt")
end

Expand All @@ -10,10 +10,10 @@ function all_examples()
for _, x in ipairs(os.files("*.cc")) do
local item = {}
local s = path.filename(x)
if((s == "upstream_unittest.cc" and get_config("upstream") == false) or
((s == "tutorial-02-redis_cli.cc" or s == "tutorial-03-wget_to_redis.cc") and get_config("redis") == false) or
(s == "tutorial-12-mysql_cli.cc" and get_config("mysql") == false) or
(s == "tutorial-14-consul_cli.cc" and get_config("consul") == false) or
if ((s == "upstream_unittest.cc" and not has_config("upstream")) or
((s == "tutorial-02-redis_cli.cc" or s == "tutorial-03-wget_to_redis.cc") and not has_config("redis")) or
(s == "tutorial-12-mysql_cli.cc" and not has_config("mysql")) or
(s == "tutorial-14-consul_cli.cc" and not has_config("consul")) or
(s == "tutorial-13-kafka_cli.cc")) then
else
table.insert(item, s:sub(1, #s - 3)) -- target
Expand All @@ -32,7 +32,7 @@ target(example[1])
end

target("tutorial-13-kafka_cli")
if (get_config("kafka") == true) then
if has_config("kafka") then
set_kind("binary")
add_files("tutorial-13-kafka_cli.cc")
add_packages("zlib", "snappy", "zstd", "lz4")
Expand Down
Loading

0 comments on commit 4216034

Please sign in to comment.