Browse Source

Fix bazel build in macos

testing on 11.0-bigsur
Zhangyi Chen 3 years ago
parent
commit
3feb6d0c2d

+ 3 - 0
.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

+ 9 - 5
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"],
 )
-

+ 26 - 4
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"
+)

+ 41 - 0
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"]
+)

+ 1 - 1
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;
 }
 
 

+ 1 - 1
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

+ 1 - 1
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*);

+ 1 - 1
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

+ 1 - 1
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

+ 3 - 1
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) {

+ 1 - 0
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();

+ 2 - 2
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;