forked from apache/brpc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bazel third_party support (apache#1996)
* add bazel support * remove bind * update * update * update * update doc * fix rdma bazel build * update
- Loading branch information
Showing
13 changed files
with
1,000 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./example/build_with_bazel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## bRPC 作为Bazel第三方依赖 | ||
1. bRPC 依赖于一些开源库, 但这些库并没有提供bazel支持, 所以需要你手动将一部分依赖加入到你的构建项目中. | ||
2. 将 /example/build_with_bazel/*.BUILD 和 brpc_workspace.bzl 该文件移动到你的项目根目录下, 将 | ||
```c++ | ||
load("@//:brpc_workspace.bzl", "brpc_workspace") | ||
brpc_workspace(); | ||
``` | ||
内容添加到你的WORKSPACE中. | ||
3. 链接请使用 | ||
```c++ | ||
... | ||
deps = [ | ||
"@apache_brpc//:bthread", | ||
"@apache_brpc//:brpc", | ||
"@apache_brpc//:butil", | ||
"@apache_brpc//:bvar", | ||
] | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## bRPC as a Bazel third-party dependency | ||
1. bRPC relies on a number of open source libraries that do not provide bazel support, so you will need to manually add some of these dependencies to your build project. | ||
2. Move the BUILD file /example/build_with_bazel/*.BUILD and brpc_workspace.bzl to the root of your project, and add the contents of | ||
```c++ | ||
load("@//:brpc_workspace.bzl", "brpc_workspace") | ||
brpc_workspace(); | ||
``` | ||
to your WORKSPACE | ||
3. link apache_brpc like: | ||
```c++ | ||
... | ||
deps = [ | ||
"@apache_brpc//:bthread", | ||
"@apache_brpc//:brpc", | ||
"@apache_brpc//:butil", | ||
"@apache_brpc//:bvar", | ||
] | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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. | ||
# | ||
# Thie empty BUILD.bazel file is required to make Bazel treat | ||
# this directory as a package. | ||
|
||
|
||
cc_binary( | ||
name = "test", | ||
srcs = ["test.cc"], | ||
deps = [ | ||
"@apache_brpc//:brpc", | ||
"@apache_brpc//:bthread", | ||
"@apache_brpc//:bvar", | ||
"@apache_brpc//:butil", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
workspace(name = "brpc_test") | ||
|
||
load("@//:brpc_workspace.bzl", "brpc_workspace") | ||
brpc_workspace(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
|
||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
|
||
BAZEL_SKYLIB_VERSION = "1.1.1" # 2021-09-27T17:33:49Z | ||
|
||
BAZEL_SKYLIB_SHA256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d" | ||
|
||
def brpc_workspace(): | ||
http_archive( | ||
name = "bazel_skylib", | ||
sha256 = BAZEL_SKYLIB_SHA256, | ||
urls = [ | ||
"https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = BAZEL_SKYLIB_VERSION), | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = BAZEL_SKYLIB_VERSION), | ||
], | ||
) | ||
|
||
http_archive( | ||
name = "com_google_protobuf", # 2021-10-29T00:04:02Z | ||
build_file = "//:protobuf.BUILD", | ||
patch_cmds = [ | ||
"sed -i protobuf.bzl -re '4,4d;417,508d'", | ||
], | ||
patch_cmds_win = [ | ||
"""$content = Get-Content 'protobuf.bzl' | Where-Object { | ||
-not ($_.ReadCount -ne 4) -and | ||
-not ($_.ReadCount -ge 418 -and $_.ReadCount -le 509) | ||
} | ||
Set-Content protobuf.bzl -Value $content -Encoding UTF8 | ||
""", | ||
], | ||
sha256 = "87407cd28e7a9c95d9f61a098a53cf031109d451a7763e7dd1253abf8b4df422", | ||
strip_prefix = "protobuf-3.19.1", | ||
urls = ["https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.19.1.tar.gz"], | ||
) | ||
|
||
|
||
http_archive( | ||
name = "com_github_google_leveldb", | ||
build_file = "//:leveldb.BUILD", | ||
strip_prefix = "leveldb-a53934a3ae1244679f812d998a4f16f2c7f309a6", | ||
url = "https://github.com/google/leveldb/archive/a53934a3ae1244679f812d998a4f16f2c7f309a6.tar.gz" | ||
) | ||
|
||
|
||
|
||
http_archive( | ||
name = "com_github_madler_zlib", # 2017-01-15T17:57:23Z | ||
build_file = "//:zlib.BUILD", | ||
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", | ||
strip_prefix = "zlib-1.2.11", | ||
urls = [ | ||
"https://downloads.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz", | ||
"https://zlib.net/fossils/zlib-1.2.11.tar.gz", | ||
], | ||
) | ||
|
||
native.new_local_repository( | ||
name = "openssl", | ||
path = "/usr", | ||
build_file = "//:openssl.BUILD", | ||
) | ||
|
||
http_archive( | ||
name = "com_github_gflags_gflags", | ||
strip_prefix = "gflags-46f73f88b18aee341538c0dfc22b1710a6abedef", | ||
url = "https://github.com/gflags/gflags/archive/46f73f88b18aee341538c0dfc22b1710a6abedef.tar.gz", | ||
) | ||
|
||
http_archive( | ||
name = "apache_brpc", | ||
strip_prefix = "incubator-brpc-1.3.0", | ||
url = "https://github.com/apache/incubator-brpc/archive/refs/tags/1.3.0.tar.gz" | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
|
||
config_setting( | ||
name = "darwin", | ||
values = {"cpu": "darwin"}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
SOURCES = ["db/builder.cc", | ||
"db/c.cc", | ||
"db/dbformat.cc", | ||
"db/db_impl.cc", | ||
"db/db_iter.cc", | ||
"db/dumpfile.cc", | ||
"db/filename.cc", | ||
"db/log_reader.cc", | ||
"db/log_writer.cc", | ||
"db/memtable.cc", | ||
"db/repair.cc", | ||
"db/table_cache.cc", | ||
"db/version_edit.cc", | ||
"db/version_set.cc", | ||
"db/write_batch.cc", | ||
"table/block_builder.cc", | ||
"table/block.cc", | ||
"table/filter_block.cc", | ||
"table/format.cc", | ||
"table/iterator.cc", | ||
"table/merger.cc", | ||
"table/table_builder.cc", | ||
"table/table.cc", | ||
"table/two_level_iterator.cc", | ||
"util/arena.cc", | ||
"util/bloom.cc", | ||
"util/cache.cc", | ||
"util/coding.cc", | ||
"util/comparator.cc", | ||
"util/crc32c.cc", | ||
"util/env.cc", | ||
"util/env_posix.cc", | ||
"util/filter_policy.cc", | ||
"util/hash.cc", | ||
"util/histogram.cc", | ||
"util/logging.cc", | ||
"util/options.cc", | ||
"util/status.cc", | ||
"port/port_posix.cc", | ||
"port/port_posix_sse.cc", | ||
"helpers/memenv/memenv.cc", | ||
] | ||
|
||
cc_library( | ||
name = "leveldb", | ||
srcs = SOURCES, | ||
hdrs = glob([ | ||
"helpers/memenv/*.h", | ||
"util/*.h", | ||
"port/*.h", | ||
"port/win/*.h", | ||
"table/*.h", | ||
"db/*.h", | ||
"include/leveldb/*.h" | ||
], | ||
exclude = [ | ||
"**/*test.*", | ||
]), | ||
includes = [ | ||
"include/", | ||
], | ||
copts = [ | ||
"-fno-builtin-memcmp", | ||
"-DLEVELDB_PLATFORM_POSIX=1", | ||
"-DLEVELDB_ATOMIC_PRESENT", | ||
], | ||
defines = [ | ||
"LEVELDB_PLATFORM_POSIX", | ||
] + select({ | ||
":darwin": ["OS_MACOSX"], | ||
"//conditions:default": [], | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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. | ||
|
||
package( | ||
default_visibility=["//visibility:public"] | ||
) | ||
|
||
config_setting( | ||
name = "macos", | ||
values = { | ||
"cpu": "darwin", | ||
}, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
cc_library( | ||
name = "crypto", | ||
srcs = select({ | ||
":macos": ["lib/libcrypto.dylib"], | ||
"//conditions:default": [] | ||
}), | ||
linkopts = select({ | ||
":macos" : [], | ||
"//conditions:default": ["-lcrypto"], | ||
}), | ||
) | ||
|
||
cc_library( | ||
name = "ssl", | ||
hdrs = select({ | ||
":macos": glob(["include/openssl/*.h"]), | ||
"//conditions:default": [] | ||
}), | ||
srcs = select ({ | ||
":macos": ["lib/libssl.dylib"], | ||
"//conditions:default": [] | ||
}), | ||
includes = ["include"], | ||
linkopts = select({ | ||
":macos" : [], | ||
"//conditions:default": ["-lssl"], | ||
}), | ||
deps = [":crypto"] | ||
) |
Oops, something went wrong.