This is an automated email from the ASF dual-hosted git repository.

zychen pushed a commit to branch fix_bazel_on_macos
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git

commit 3feb6d0c2d980f196d6470f232abe2405941b702
Author: Zhangyi Chen <[email protected]>
AuthorDate: Mon Nov 30 15:26:41 2020 +0800

    Fix bazel build in macos
    
    testing on 11.0-bigsur
---
 .bazelrc                             |  3 +++
 BUILD                                | 14 +++++++-----
 WORKSPACE                            | 30 ++++++++++++++++++++++----
 openssl.BUILD                        | 41 ++++++++++++++++++++++++++++++++++++
 src/brpc/span.h                      |  2 +-
 src/bthread/key.cpp                  |  2 +-
 src/bthread/task_group.cpp           |  2 +-
 src/butil/find_cstr.cpp              |  2 +-
 src/butil/find_cstr.h                |  2 +-
 test/baidu_thread_local_unittest.cpp |  4 +++-
 test/bthread_futex_unittest.cpp      |  1 +
 test/file_util_unittest.cc           |  4 ++--
 12 files changed, 90 insertions(+), 17 deletions(-)

diff --git a/.bazelrc b/.bazelrc
index 659b47d..8ae4f0d 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -17,5 +17,8 @@ build --copt -DHAVE_ZLIB=1
 # bazel build with glog
 # build --define=with_glog=true
 build -c opt
+build --incompatible_disable_deprecated_attr_params=false
+build --incompatible_new_actions_api=false
 # unittest 
 test --define=unittest=true
+test --copt=-g
diff --git a/BUILD b/BUILD
index 9523f58..5482300 100644
--- a/BUILD
+++ b/BUILD
@@ -79,8 +79,8 @@ LINKOPTS = [
     "-lpthread",
     "-ldl",
     "-lz",
-    "-lssl",
-    "-lcrypto",
+    # "-lssl",
+    # "-lcrypto",
 ] + select({
     ":darwin": [
         "-framework CoreFoundation",
@@ -304,6 +304,7 @@ objc_library(
         "src/butil/threading/thread_restrictions.h",
         "src/butil/threading/thread_id_name_manager.h",
         "src/butil/type_traits.h",
+        "src/butil/third_party/murmurhash3/murmurhash3.h",
     ],
     non_arc_srcs = [
         "src/butil/mac/bundle_locations.mm",
@@ -332,8 +333,7 @@ cc_library(
         "src/butil/**/*.h",
         "src/butil/**/*.hpp",
         "src/butil/**/**/*.h",
-        "src/butil/**/**/*.hpp",
-        "src/butil/**/**/**/*.h",
+        "src/butil/**/**/*.hpp", "src/butil/**/**/**/*.h",
         "src/butil/**/**/**/*.hpp",
         "src/butil/third_party/dmg_fp/dtoa.cc",
     ]) + [":config_h"],
@@ -342,8 +342,13 @@ cc_library(
         "@com_github_gflags_gflags//:gflags",
     ] + select({
         ":with_glog": ["@com_github_google_glog//:glog"],
+        "//conditions:default": [],
+    }) + select({
         ":darwin": [":macos_lib"],
         "//conditions:default": [],
+    }) + select({
+        ":darwin": ["//external:ssl_macos"],
+        "//conditions:default": ["//external:ssl"],
     }),
     includes = [
         "src/",
@@ -532,4 +537,3 @@ cc_binary(
     linkopts = LINKOPTS,
     visibility = ["//visibility:public"],
 )
-
diff --git a/WORKSPACE b/WORKSPACE
index e8b03c9..1b5255a 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -34,18 +34,18 @@ http_archive(
   type = "zip",
   url = "https://github.com/protocolbuffers/protobuf/archive/v3.6.1.3.zip";,
 )
-  
+
 http_archive(
     name = "com_github_gflags_gflags",
     strip_prefix = "gflags-46f73f88b18aee341538c0dfc22b1710a6abedef",
     url = 
"https://github.com/gflags/gflags/archive/46f73f88b18aee341538c0dfc22b1710a6abedef.tar.gz";,
 )
- 
+
 bind(
     name = "gflags",
     actual = "@com_github_gflags_gflags//:gflags",
 )
-  
+
 http_archive(
     name = "com_github_google_leveldb",
     build_file = "//:leveldb.BUILD",
@@ -59,9 +59,31 @@ http_archive(
     strip_prefix = "glog-a6a166db069520dbbd653c97c2e5b12e08a8bb26",
     url = 
"https://github.com/google/glog/archive/a6a166db069520dbbd653c97c2e5b12e08a8bb26.tar.gz";
 )
-  
+
 http_archive(
     name = "com_google_googletest",
     strip_prefix = "googletest-0fe96607d85cf3a25ac40da369db62bbee2939a5",
     url = 
"https://github.com/google/googletest/archive/0fe96607d85cf3a25ac40da369db62bbee2939a5.tar.gz";,
 )
+
+new_local_repository(
+    name = "openssl",
+    path = "/usr",
+    build_file = "//:openssl.BUILD",
+)
+
+new_local_repository(
+    name = "openssl_macos",
+    build_file = "//:openssl.BUILD",
+    path = "/usr/local/opt/openssl",
+)
+
+bind(
+    name = "ssl",
+    actual = "@openssl//:ssl"
+)
+
+bind(
+    name = "ssl_macos",
+    actual = "@openssl_macos//:ssl"
+)
diff --git a/openssl.BUILD b/openssl.BUILD
new file mode 100644
index 0000000..7b948e9
--- /dev/null
+++ b/openssl.BUILD
@@ -0,0 +1,41 @@
+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": ["lib/libssl.so"]
+    }),
+    srcs = select ({
+        ":macos": ["lib/libssl.dylib"],
+        "//conditions:default": []
+    }),
+    includes = ["include"],
+    linkopts = select({
+        ":macos" : [],
+        "//conditions:default": ["-lssl"],
+    }),
+    deps = [":crypto"]
+)
diff --git a/src/brpc/span.h b/src/brpc/span.h
index 43ede3d..0777164 100644
--- a/src/brpc/span.h
+++ b/src/brpc/span.h
@@ -34,7 +34,7 @@
 #include "brpc/span.pb.h"
 
 namespace bthread {
-extern __thread bthread::LocalStorage tls_bls;
+extern thread_local bthread::LocalStorage tls_bls;
 }
 
 
diff --git a/src/bthread/key.cpp b/src/bthread/key.cpp
index a4a0840..53f7594 100644
--- a/src/bthread/key.cpp
+++ b/src/bthread/key.cpp
@@ -34,7 +34,7 @@ class KeyTable;
 
 // defined in task_group.cpp
 extern __thread TaskGroup* tls_task_group;
-extern __thread LocalStorage tls_bls;
+extern thread_local LocalStorage tls_bls;
 static __thread bool tls_ever_created_keytable = false;
 
 // We keep thread specific data in a two-level array. The top-level array
diff --git a/src/bthread/task_group.cpp b/src/bthread/task_group.cpp
index 1da6a25..7c41653 100644
--- a/src/bthread/task_group.cpp
+++ b/src/bthread/task_group.cpp
@@ -61,7 +61,7 @@ __thread TaskGroup* tls_task_group = NULL;
 // Sync with TaskMeta::local_storage when a bthread is created or destroyed.
 // During running, the two fields may be inconsistent, use tls_bls as the
 // groundtruth.
-__thread LocalStorage tls_bls = BTHREAD_LOCAL_STORAGE_INITIALIZER;
+thread_local LocalStorage tls_bls = BTHREAD_LOCAL_STORAGE_INITIALIZER;
 
 // defined in bthread/key.cpp
 extern void return_keytable(bthread_keytable_pool_t*, KeyTable*);
diff --git a/src/butil/find_cstr.cpp b/src/butil/find_cstr.cpp
index afa16b5..82b2db9 100644
--- a/src/butil/find_cstr.cpp
+++ b/src/butil/find_cstr.cpp
@@ -21,6 +21,6 @@
 
 namespace butil {
 
-__thread StringMapThreadLocalTemp tls_stringmap_temp = { false, {} };
+thread_local StringMapThreadLocalTemp tls_stringmap_temp = { false, {} };
 
 }  // namespace butil
diff --git a/src/butil/find_cstr.h b/src/butil/find_cstr.h
index 2a215a8..fd99713 100644
--- a/src/butil/find_cstr.h
+++ b/src/butil/find_cstr.h
@@ -95,7 +95,7 @@ struct StringMapThreadLocalTemp {
     }
 };
 
-extern __thread StringMapThreadLocalTemp tls_stringmap_temp;
+extern thread_local StringMapThreadLocalTemp tls_stringmap_temp;
 
 template <typename T, typename C, typename A>
 typename std::map<std::string, T, C, A>::const_iterator
diff --git a/test/baidu_thread_local_unittest.cpp 
b/test/baidu_thread_local_unittest.cpp
index a77abda..7ffe0f5 100644
--- a/test/baidu_thread_local_unittest.cpp
+++ b/test/baidu_thread_local_unittest.cpp
@@ -174,7 +174,9 @@ void fun4(void* arg) {
 }
 
 static void check_result() {
-    ASSERT_EQ("fun4(0)\nfun3(0x2)\nfun2\n", get_oss().str());
+  // Don't use gtest function since this function might be invoked when the 
main
+  // thread quits, instances required by gtest functions are likely destroyed.
+  assert (get_oss().str() == "fun4(0)\nfun3(0x2)\nfun2\n");
 }
 
 TEST_F(BaiduThreadLocalTest, call_order_and_cancel) {
diff --git a/test/bthread_futex_unittest.cpp b/test/bthread_futex_unittest.cpp
index 86e6bb3..0ed5685 100644
--- a/test/bthread_futex_unittest.cpp
+++ b/test/bthread_futex_unittest.cpp
@@ -135,6 +135,7 @@ TEST(FutexTest, futex_wake_many_waiters_perf) {
     printf("N=%lu, futex_wake a thread = %" PRId64 "ns\n", N, tm.n_elapsed() / 
N);
     ASSERT_EQ(N, (size_t)nwakeup);
 
+    sleep(2);
     const size_t REP = 10000;
     nwakeup = 0;
     tm.start();
diff --git a/test/file_util_unittest.cc b/test/file_util_unittest.cc
index 9882fae..a323a72 100644
--- a/test/file_util_unittest.cc
+++ b/test/file_util_unittest.cc
@@ -2131,12 +2131,12 @@ TEST_F(FileUtilTest, TouchFile) {
   // 784915200000000 represents the timestamp of "Wed, 16 Nov 1994, 00:00:00".
   // This timestamp is divisible by one day (in local timezone), to make it 
work
   // on FAT too.
-  Time access_time(784915200000000);
+  auto access_time = Time::FromUTCExploded({1994, 11, 4, 16, 0, 0, 0, 0});
 
   // 784903526000000 represents the timestamp of "Tue, 15 Nov 1994, 12:45:26 
GMT".
   // Note that this timestamp is divisible by two (seconds) - FAT stores
   // modification times with 2s resolution.
-  Time modification_time(784903526000000);
+  auto modification_time = Time::FromUTCExploded({1994, 11, 3, 15, 12, 45, 26, 
0});
 
   ASSERT_TRUE(TouchFile(foobar, access_time, modification_time));
   File::Info file_info;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to