Skip to content

Commit

Permalink
chore: update use async_simple as a dependency (#335)
Browse files Browse the repository at this point in the history
* chore: update use `async_simple` as a dependency

* update

* remove ASYNC_SIMPLE_HAS_NOT_AIO from libasync_simple
  • Loading branch information
4kangjc committed Jul 10, 2023
1 parent 8ccc631 commit 6252e7a
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bazel/support
build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build_options.*
config.log
*.o
build/
build*
build*/
_external/
core.*
\#*\#
Expand All @@ -26,6 +26,7 @@ coro_trace.log
*.log
test.h
bazel-*
!.bazelignore
!.bazelrc
cmake-build-debug
!docs/.vitepress
Expand Down
23 changes: 9 additions & 14 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ load("//bazel/config:copt.bzl", "ASYNC_SIMPLE_COPTS")
uthread_prefix = "async_simple/uthread/internal/"

uthread_srcs = [

] + select({
"//bazel/config:async_simple_with_uthread": [
"async_simple/uthread/internal/thread_impl.h",
"async_simple/uthread/internal/thread.cc",
],
"//conditions:default" : [],
"//conditions:default": [],
}) + select({
"//bazel/config:linux_x86_64": glob([uthread_prefix + "Linux/" + "x86_64/*.S"]),
"//bazel/config:linux_aarch64": glob([uthread_prefix + "Linux/" + "aarch64/*.S"]),
"//bazel/config:linux_ppc64le": glob([uthread_prefix + "Linux/" + "ppc64le/*.S"]),
"//bazel/config:darwin_x86_64": glob([uthread_prefix + "Darwin/" + "x86_64/*.S"]),
"//bazel/config:darwin_aarch64": glob([uthread_prefix + "Darwin/" + "arm64/*.S"]),
"//conditions:default" : [],
"//conditions:default": [],
})

uthread_hdrs = select({
"//bazel/config:async_simple_with_uthread": glob([
"async_simple/uthread/internal/thread.h",
"async_simple/uthread/internal/*.h",
"async_simple/uthread/*.h",
]),
"//conditions:default": [],
Expand All @@ -30,14 +29,14 @@ uthread_hdrs = select({
cc_library(
name = "simple_executors",
hdrs = glob(["async_simple/executors/*.h"]),
linkopts = select({
"//bazel/config:async_simple_has_not_aio": [],
"//conditions:default": ["-laio"],
}),
defines = select({
"//bazel/config:async_simple_has_not_aio": ["ASYNC_SIMPLE_HAS_NOT_AIO"],
"//conditions:default": [],
}),
linkopts = select({
"//bazel/config:async_simple_has_not_aio": [],
"//conditions:default": ["-laio"],
}),
visibility = ["//visibility:public"],
)

Expand All @@ -49,16 +48,12 @@ cc_library(
hdrs = glob([
"async_simple/*.h",
"async_simple/coro/*.h",
"async_simple/util/*.h"
"async_simple/util/*.h",
]) + uthread_hdrs,
copts = ASYNC_SIMPLE_COPTS,
visibility = ["//visibility:public"],
linkopts = select({
"@platforms//os:windows": [],
"//conditions:default": ["-lpthread"],
}),
defines = select({
"//bazel/config:async_simple_has_not_aio": ["ASYNC_SIMPLE_HAS_NOT_AIO"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ bazel build --copt='-O0' --copt='-ggdb' ...
```
- See [this](https://bazel.build/run/build) get more infomation
- ` ...` Indicates recursively scan all targets, recognized as `../..` in `oh-my-zsh`, can be replaced by other `shell` or `bash -c 'commond'` to run, such as `bash -c 'bazel build' ...` or use `bazel build ...:all`
- Use `async_simple` as a dependency, see also [bazel support](bazel/support/README.md)

# Docker Compile Environment
```
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ bazel build --copt='-O0' --copt='-ggdb' ...
```
-[这里](https://bazel.build/run/build)获得`bazel build`的更多信息
- `...`表示递归扫描所有目标,在`oh-my-zsh`中被识别为`../..`,可更换其他`shell`或使用`bash -c 'command.'`运行,例如`bash -c 'bazel build ...'`, 或者使用`bazel build ...:all`
- 使用`async_simple`作为第三方依赖库,也可以看看[bazel support](bazel/support/README.md)

# Docker 编译环境
```
Expand Down
16 changes: 16 additions & 0 deletions bazel/support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
config_setting(
name = "msvc_compiler",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "msvc-cl",
},
)

cc_binary(
name = "hello",
srcs = ["hello.cc"],
copts = select({
":msvc_compiler": ["/std:c++20"],
"//conditions:default": ["-std=c++20"],
}),
deps = ["@com_github_async_simple//:async_simple"],
)
18 changes: 5 additions & 13 deletions bazel/support/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ hello-async_simple/
│   └── hello.cc
└── WORKSPACE.bazel
```
You can find these files in this directory.

*hello.cc:*
```cpp
Expand All @@ -25,21 +26,12 @@ int main() {
});
}
```
This is an example of `async_simple::uthread`. [hello.cc](hello.cc) is an example of `async_simple::Lazy`.
The expected output of this example is `Hello async_simple!`.

*WORKSPACE.bazel*:
*[WORKSPACE.bazel](WORKSPACE.bazel)*:
You can also use the `http_archive` method to download async_simple:
```python
# Use git_repository
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

ASYNC_SIMPLE_COMMID_ID = ""

git_repository(
name = "com_github_async_simple",
commit = ASYNC_SIMPLE_COMMID_ID,
remote = "https://github.com/alibaba/async_simple.git",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Use http_archive
Expand All @@ -58,7 +50,7 @@ load("@com_github_async_simple//bazel/config:deps.bzl", "async_simple_dependenci
async_simple_dependencies()
```

*BUILD.bazel*:
*[BUILD.bazel](BUILD.bazel)*:
```python
cc_binary(
name = "hello",
Expand Down
16 changes: 16 additions & 0 deletions bazel/support/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
workspace(name = "hello_async_simple")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

ASYNC_SIMPLE_COMMID_ID = "8ccc63142b23c6660f61d58f08a151020fa39da0"

git_repository(
name = "com_github_async_simple",
commit = ASYNC_SIMPLE_COMMID_ID,
remote = "https://github.com/alibaba/async_simple.git",
)

# Load async_simple async_simple_dependencies
load("@com_github_async_simple//bazel/config:deps.bzl", "async_simple_dependencies")

async_simple_dependencies()
28 changes: 28 additions & 0 deletions bazel/support/hello.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023, Alibaba Group Holding Limited;
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>
#include "async_simple/coro/Lazy.h"

async_simple::coro::Lazy<std::string> hello() { co_return "Hello World"; }

int main() {
hello().start([](auto&& result) {
if (!result.hasError()) {
std::cout << result.value() << std::endl;
}
});
}

0 comments on commit 6252e7a

Please sign in to comment.