brpc icon indicating copy to clipboard operation
brpc copied to clipboard

Chore: rework Bazel build system

Open hcoona opened this issue 2 years ago • 20 comments

Totally rewrite the bazel build support.

  1. Support latest version of bazel.

  2. Build all external dependencies (except for mesalink) with bazel.

  3. Support Protobuf 3.19.1 (breaking changes here: https://github.com/protocolbuffers/protobuf/commit/624d29d83306f3ce2c7e092dd44a891e04215e67) image

  4. Support generate compile_commands.json for bazel project.

  5. Rework the options flags & move all of them into //bazel/config

Leave building with mesalink for future. I think maybe all dependencies should link against mesalink instead of openssl.

hcoona avatar Dec 29 '21 08:12 hcoona

Nice job!

Only one question: Will the changes break the compilation of users with old versions of bazel, e.g. 0.25

chenzhangyi avatar Dec 29 '21 09:12 chenzhangyi

@chenzhangyi In short it would break building with bazel 0.25. Many dependencies relying on a higher version of bazel. I didn't verify each of them. However, rules_foreign_cc 0.7.0 requires bazel v4.0.0+ (See https://github.com/bazelbuild/rules_foreign_cc/blob/0.7.0/README.md). We build several external dependencies (openssl, libevent, thrift, ...) with it.

hcoona avatar Dec 29 '21 10:12 hcoona

The protobuf arena changes are still breaking. I'll fix it with GOOGLE_PROTOBUF_VERSION.

hcoona avatar Dec 29 '21 10:12 hcoona

Fixed protobuf compatibility & separate it into another commit.

The failing unit test seems to be unrelated with this change. The only failing unittest is

image

Got it. After installed curl, it passed.

image

hcoona avatar Dec 29 '21 14:12 hcoona

@wwbmmm PTAL

hcoona avatar Jan 09 '22 12:01 hcoona

@wwbmmm PTAL

LGTM

wwbmmm avatar Jan 10 '22 03:01 wwbmmm

Is there something else to make it merged?

hcoona avatar Jan 13 '22 02:01 hcoona

Hi @hcoona , Thank you so much for your contribution! But I have a little concern, some projects may depend on bazel 0.2x, like TensorFlow 1.x, and we have seen some teams using bRPC in TensorFlow. So, maybe we should consider the compatibility issues. cc @chenzhangyi @wwbmmm

lorinlee avatar Jan 14 '22 06:01 lorinlee

@hcoona Can you extract the changes related to “Support Protobuf 3.19.1” into a separate PR so that this part can be merged faster?

wwbmmm avatar Jan 17 '22 05:01 wwbmmm

@wwbmmm Sure, split the protobuf support to https://github.com/apache/incubator-brpc/pull/1679

hcoona avatar Jan 20 '22 14:01 hcoona

@lorinlee @chenzhangyi In bazel philosophy, the final project owner need to take responsibility for all of its dependencies, AKA. specify how to download & build them in WORKSPACE file. For this change, there's nothing special for the BUILD files, so it should works fine building a project depends on brpc with an earlier version of Bazel if the project owner could provide necessary indirect dependencies for bRPC. I'll verify it offline, and ping you guys later few days.

hcoona avatar Jan 20 '22 14:01 hcoona

Do my best to make it compiles with bazel 0.28.0 (0.27.1 failed). See example/build_with_old_bazel. @lorinlee Is this fine enough?

It means that if a user used bRPC in their project, it can compile with bazel 0.28.0 and higher.

hcoona avatar Jan 20 '22 15:01 hcoona

@chenzhangyi @lorinlee ping~

hcoona avatar Jan 26 '22 05:01 hcoona

Would you help merge it?

mapx avatar Feb 26 '22 07:02 mapx

@chenzhangyi Would you help to take a look at it? The user project depending on bRPC would still compile if they are using bazel v0.28.0 and higher. example/build_with_old_bazel verified it.

hcoona avatar Mar 03 '22 03:03 hcoona

ping

mapx avatar May 13 '22 06:05 mapx

@hcoona Hi, Could you upload the newest version if anything has changed since last time?

zyearn avatar Jul 19 '22 21:07 zyearn

@zyearn updated to resolve conflicts & add license headers

hcoona avatar Jul 20 '22 04:07 hcoona

Thanks. I will have a look later.

zyearn avatar Jul 25 '22 21:07 zyearn

Will it be merged soon?

372046933 avatar Aug 04 '22 01:08 372046933

@hcoona please reslove conflicts, thanks.

guodongxiaren avatar Aug 20 '22 06:08 guodongxiaren

@guodongxiaren PTAL

hcoona avatar Aug 23 '22 07:08 hcoona

@zyearn @wwbmmm please review this pull request and check whether it can be merged.

guodongxiaren avatar Aug 23 '22 16:08 guodongxiaren

@zyearn @wwbmmm please review this pull request and check whether it can be merged.

LGTM @zyearn please see if there is any problem to merge it.

wwbmmm avatar Aug 24 '22 03:08 wwbmmm

@zyearn @jamesge please review

guodongxiaren avatar Aug 26 '22 12:08 guodongxiaren

It's a great contribution, and could you please share a related blog or doc for that pr? I think it will be a good learning material and we will post it to our official website, please consider this, thanks a lot.

Huixxi avatar Aug 30 '22 02:08 Huixxi

@zyearn PTAL. I removed bazel/third_party/glog/0001-improvement-copts.patch & rename bazel/third_party/glog/0002-mark-override.patch to a more meaningful name 0001-mark-override-resolve-warning.patch. If you think the example of building with old version of bazel for user is not necessary, I can remove it.

The CI failure cannot be reproduced on my dev environment with GCC 9.4.0 & bazel 4.2.2 by running CC=gcc CXX=g++ PURPOSE=compile-with-bazel-all-options sh build_in_travis_ci.sh. I looked the source code, it shouldn't be such error. Please help to rerun the failed jobs if possible.

hcoona avatar Aug 30 '22 06:08 hcoona

@Huixxi I didn't realize there was any special work. Please look the Bazel official document & some existing repo driven by Bazel. Please raise to me if there was truly something special with details, I can help to find some document about them.

hcoona avatar Aug 30 '22 06:08 hcoona

If you think the example of building with old version of bazel for user is not necessary, I can remove it.

I think the example of building with old version of bazel is useful. No need to remove it.

wwbmmm avatar Aug 30 '22 10:08 wwbmmm

CI is fixed in the latest version. Could you merge master and submit again?

zyearn avatar Aug 30 '22 19:08 zyearn