brpc icon indicating copy to clipboard operation
brpc copied to clipboard

Add example for build brpc as a third party dependency with bazel?

Open fusying-hwang opened this issue 3 years ago • 1 comments

hey, brpc team, could you guys pls add a example about how to build brpc as an external dependency with bazel build? I didn't find any such instructions online. However, it seems brpc do support bazel build. It would be appreciated if a bazel build example can be provided. Thanks.

fusying-hwang avatar Sep 06 '22 06:09 fusying-hwang

Does this example meet your needs? https://github.com/apache/incubator-brpc/tree/master/example/build_with_old_bazel

wwbmmm avatar Sep 06 '22 06:09 wwbmmm

I want to work on this. Should we add some related documents for this?

fansehep avatar Oct 19 '22 11:10 fansehep

/assign

JadeFlute0127 avatar Nov 07 '22 06:11 JadeFlute0127

I tried to make brpc an external dependency directly. But bazel give me many errors. such as @openssl: can not found.

git_repository(
    name = "apache_brpc",
    branch = "release-1.3",
    remote = "https://github.com/apache/incubator-brpc",
)

a BUILD file like this :

cc_test(
  name = "slice_test",
  srcs = glob([
    "slice_test.cpp",
  ]),
  deps = [
    "@apache_brpc//:bvar",
  ],
 )

Some brpc reliances are in /bazel/third_patry/*, but bazel don't identification them. can give me some help?

fansehep avatar Nov 14 '22 12:11 fansehep

I tried to make brpc an external dependency directly. But bazel give me many errors. such as @openssl: can not found.

git_repository(
    name = "apache_brpc",
    branch = "release-1.3",
    remote = "https://github.com/apache/incubator-brpc",
)

a BUILD file like this :

cc_test(
  name = "slice_test",
  srcs = glob([
    "slice_test.cpp",
  ]),
  deps = [
    "@apache_brpc//:bvar",
  ],
 )

Some brpc reliances are in /bazel/third_patry/*, but bazel don't identification them. can give me some help?

Actually, I end up with not finding a decent way to resolve this. So, basically, what I did was build the brpc library to an .a library first and then just link against that .a file. It's dirty but it actually works. Hope that helps.

fusying-hwang avatar Nov 14 '22 12:11 fusying-hwang

oh, so pity!. how about rewrite the brpc bazel BUILD rules? that we can open a new issue. If other guys can help us. i think it's easy to do it. 😄

fansehep avatar Nov 14 '22 13:11 fansehep

You might need to resort to the BRPC team for help then. Actually I'm persuading my team to use GRPC instead but there's an ex-Baiduer who insists on using BRPC. So that's what I can do for it's shitty bazel build system. :-P

fusying-hwang avatar Nov 14 '22 13:11 fusying-hwang

You might need to resort to the BRPC team for help then. Actually I'm persuading my team to use GRPC instead but there's an ex-Baiduer who insists on using BRPC. So that's what I can do for it's shitty bazel build system. :-P

Yep, if we want to do it. it is really a big problem. Anyway I think bRPC is a superior rpc project. I will try to do the bazel build file rewrite. If someone is interesting in it or can help me. welcome to reach me.

fansehep avatar Nov 14 '22 13:11 fansehep

alright, it turns out to be my problem. They do support building as an external lib from source. My humble bazel knowledge limits my ability to appreciate this project.

custom_http_archive(
    name = "brpc",
    auto_bind = False,
    repository_name = "com_github_brpc_brpc",
    auto_strip = False,
    strip_prefix = "incubator-brpc-1.3.0",
    repo_mapping = {
        "@com_github_google_leveldb": "@com_leveldb",
        "@com_github_gflags_gflags": "@com_gflags",
        "@com_github_madler_zlib": "@net_zlib_zlib_2",
        "@openssl": "@com_openssl",
        "@com_github_google_glog": "@com_glog",
    },
)
native.bind(
    name = "brpc",
    actual = "@com_github_brpc_brpc//:brpc",
)

this is my solution, basically we already had some local names like leveldb, gflags, ... all we need to do is using repo_mapping to map it.

One caveat, we statically linked openssl and in static linkage the order of these two dependencies matter, "@openssl//:crypto", "@openssl//:ssl", I do suggest the BRPC team switch these two lines so that I don't need to patch it.

Hope that helps. And I think this issue can close now.

fusying-hwang avatar Nov 24 '22 08:11 fusying-hwang

it's already resolved close now.

fusying-hwang avatar Nov 24 '22 08:11 fusying-hwang

alright, it turns out to be my problem. They do support building as an external lib from source. My humble bazel knowledge limits my ability to appreciate this project.

custom_http_archive(
    name = "brpc",
    auto_bind = False,
    repository_name = "com_github_brpc_brpc",
    auto_strip = False,
    strip_prefix = "incubator-brpc-1.3.0",
    repo_mapping = {
        "@com_github_google_leveldb": "@com_leveldb",
        "@com_github_gflags_gflags": "@com_gflags",
        "@com_github_madler_zlib": "@net_zlib_zlib_2",
        "@openssl": "@com_openssl",
        "@com_github_google_glog": "@com_glog",
    },
)
native.bind(
    name = "brpc",
    actual = "@com_github_brpc_brpc//:brpc",
)

this is my solution, basically we already had some local names like leveldb, gflags, ... all we need to do is using repo_mapping to map it.

One caveat, we statically linked openssl and in static linkage the order of these two dependencies matter, "@openssl//:crypto", "@openssl//:ssl", I do suggest the BRPC team switch these two lines so that I don't need to patch it.

Hope that helps. And I think this issue can close now.

looks more great than my way.

fansehep avatar Nov 24 '22 08:11 fansehep

alright, it turns out to be my problem. They do support building as an external lib from source. My humble bazel knowledge limits my ability to appreciate this project.

custom_http_archive(
    name = "brpc",
    auto_bind = False,
    repository_name = "com_github_brpc_brpc",
    auto_strip = False,
    strip_prefix = "incubator-brpc-1.3.0",
    repo_mapping = {
        "@com_github_google_leveldb": "@com_leveldb",
        "@com_github_gflags_gflags": "@com_gflags",
        "@com_github_madler_zlib": "@net_zlib_zlib_2",
        "@openssl": "@com_openssl",
        "@com_github_google_glog": "@com_glog",
    },
)
native.bind(
    name = "brpc",
    actual = "@com_github_brpc_brpc//:brpc",
)

this is my solution, basically we already had some local names like leveldb, gflags, ... all we need to do is using repo_mapping to map it.

One caveat, we statically linked openssl and in static linkage the order of these two dependencies matter, "@openssl//:crypto", "@openssl//:ssl", I do suggest the BRPC team switch these two lines so that I don't need to patch it.

Hope that helps. And I think this issue can close now.

Can you provide more details about your build way? I try a demo with the build style, but bazel can not found the custom_http_archive. I want to make the way to the master branch.

fansehep avatar Nov 29 '22 12:11 fansehep

oh, that's my customized http_archive, because I already had those dependencies in my workspace (some other projects already depended on them). but I think you basically need is something like grpc_deps.bzl. You put all those dependencies in this file and when people want to use brpc as an external dependent, all they need to do is put codes like load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") grpc_deps() in their WORKSPACE

fusying-hwang avatar Nov 29 '22 16:11 fusying-hwang

one caveat is that they used a bazel defined variable to control if building with glog or not. I didn't find a good way to pass this variable to brpc when built as an external dependency, so I slapped a patch on it to stipulate the building with glog. If you find a way to solve this, pls let me know. Thanks.

fusying-hwang avatar Nov 29 '22 16:11 fusying-hwang