Commit 3feb6d0c authored by Zhangyi Chen's avatar Zhangyi Chen

Fix bazel build in macos

testing on 11.0-bigsur
parent ce7c45f1
...@@ -17,5 +17,8 @@ build --copt -DHAVE_ZLIB=1 ...@@ -17,5 +17,8 @@ build --copt -DHAVE_ZLIB=1
# bazel build with glog # bazel build with glog
# build --define=with_glog=true # build --define=with_glog=true
build -c opt build -c opt
build --incompatible_disable_deprecated_attr_params=false
build --incompatible_new_actions_api=false
# unittest # unittest
test --define=unittest=true test --define=unittest=true
test --copt=-g
...@@ -79,8 +79,8 @@ LINKOPTS = [ ...@@ -79,8 +79,8 @@ LINKOPTS = [
"-lpthread", "-lpthread",
"-ldl", "-ldl",
"-lz", "-lz",
"-lssl", # "-lssl",
"-lcrypto", # "-lcrypto",
] + select({ ] + select({
":darwin": [ ":darwin": [
"-framework CoreFoundation", "-framework CoreFoundation",
...@@ -304,6 +304,7 @@ objc_library( ...@@ -304,6 +304,7 @@ objc_library(
"src/butil/threading/thread_restrictions.h", "src/butil/threading/thread_restrictions.h",
"src/butil/threading/thread_id_name_manager.h", "src/butil/threading/thread_id_name_manager.h",
"src/butil/type_traits.h", "src/butil/type_traits.h",
"src/butil/third_party/murmurhash3/murmurhash3.h",
], ],
non_arc_srcs = [ non_arc_srcs = [
"src/butil/mac/bundle_locations.mm", "src/butil/mac/bundle_locations.mm",
...@@ -332,8 +333,7 @@ cc_library( ...@@ -332,8 +333,7 @@ cc_library(
"src/butil/**/*.h", "src/butil/**/*.h",
"src/butil/**/*.hpp", "src/butil/**/*.hpp",
"src/butil/**/**/*.h", "src/butil/**/**/*.h",
"src/butil/**/**/*.hpp", "src/butil/**/**/*.hpp", "src/butil/**/**/**/*.h",
"src/butil/**/**/**/*.h",
"src/butil/**/**/**/*.hpp", "src/butil/**/**/**/*.hpp",
"src/butil/third_party/dmg_fp/dtoa.cc", "src/butil/third_party/dmg_fp/dtoa.cc",
]) + [":config_h"], ]) + [":config_h"],
...@@ -342,8 +342,13 @@ cc_library( ...@@ -342,8 +342,13 @@ cc_library(
"@com_github_gflags_gflags//:gflags", "@com_github_gflags_gflags//:gflags",
] + select({ ] + select({
":with_glog": ["@com_github_google_glog//:glog"], ":with_glog": ["@com_github_google_glog//:glog"],
"//conditions:default": [],
}) + select({
":darwin": [":macos_lib"], ":darwin": [":macos_lib"],
"//conditions:default": [], "//conditions:default": [],
}) + select({
":darwin": ["//external:ssl_macos"],
"//conditions:default": ["//external:ssl"],
}), }),
includes = [ includes = [
"src/", "src/",
...@@ -532,4 +537,3 @@ cc_binary( ...@@ -532,4 +537,3 @@ cc_binary(
linkopts = LINKOPTS, linkopts = LINKOPTS,
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
...@@ -34,18 +34,18 @@ http_archive( ...@@ -34,18 +34,18 @@ http_archive(
type = "zip", type = "zip",
url = "https://github.com/protocolbuffers/protobuf/archive/v3.6.1.3.zip", url = "https://github.com/protocolbuffers/protobuf/archive/v3.6.1.3.zip",
) )
http_archive( http_archive(
name = "com_github_gflags_gflags", name = "com_github_gflags_gflags",
strip_prefix = "gflags-46f73f88b18aee341538c0dfc22b1710a6abedef", strip_prefix = "gflags-46f73f88b18aee341538c0dfc22b1710a6abedef",
url = "https://github.com/gflags/gflags/archive/46f73f88b18aee341538c0dfc22b1710a6abedef.tar.gz", url = "https://github.com/gflags/gflags/archive/46f73f88b18aee341538c0dfc22b1710a6abedef.tar.gz",
) )
bind( bind(
name = "gflags", name = "gflags",
actual = "@com_github_gflags_gflags//:gflags", actual = "@com_github_gflags_gflags//:gflags",
) )
http_archive( http_archive(
name = "com_github_google_leveldb", name = "com_github_google_leveldb",
build_file = "//:leveldb.BUILD", build_file = "//:leveldb.BUILD",
...@@ -59,9 +59,31 @@ http_archive( ...@@ -59,9 +59,31 @@ http_archive(
strip_prefix = "glog-a6a166db069520dbbd653c97c2e5b12e08a8bb26", strip_prefix = "glog-a6a166db069520dbbd653c97c2e5b12e08a8bb26",
url = "https://github.com/google/glog/archive/a6a166db069520dbbd653c97c2e5b12e08a8bb26.tar.gz" url = "https://github.com/google/glog/archive/a6a166db069520dbbd653c97c2e5b12e08a8bb26.tar.gz"
) )
http_archive( http_archive(
name = "com_google_googletest", name = "com_google_googletest",
strip_prefix = "googletest-0fe96607d85cf3a25ac40da369db62bbee2939a5", strip_prefix = "googletest-0fe96607d85cf3a25ac40da369db62bbee2939a5",
url = "https://github.com/google/googletest/archive/0fe96607d85cf3a25ac40da369db62bbee2939a5.tar.gz", 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"
)
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"]
)
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "brpc/span.pb.h" #include "brpc/span.pb.h"
namespace bthread { namespace bthread {
extern __thread bthread::LocalStorage tls_bls; extern thread_local bthread::LocalStorage tls_bls;
} }
......
...@@ -34,7 +34,7 @@ class KeyTable; ...@@ -34,7 +34,7 @@ class KeyTable;
// defined in task_group.cpp // defined in task_group.cpp
extern __thread TaskGroup* tls_task_group; 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; static __thread bool tls_ever_created_keytable = false;
// We keep thread specific data in a two-level array. The top-level array // We keep thread specific data in a two-level array. The top-level array
......
...@@ -61,7 +61,7 @@ __thread TaskGroup* tls_task_group = NULL; ...@@ -61,7 +61,7 @@ __thread TaskGroup* tls_task_group = NULL;
// Sync with TaskMeta::local_storage when a bthread is created or destroyed. // 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 // During running, the two fields may be inconsistent, use tls_bls as the
// groundtruth. // groundtruth.
__thread LocalStorage tls_bls = BTHREAD_LOCAL_STORAGE_INITIALIZER; thread_local LocalStorage tls_bls = BTHREAD_LOCAL_STORAGE_INITIALIZER;
// defined in bthread/key.cpp // defined in bthread/key.cpp
extern void return_keytable(bthread_keytable_pool_t*, KeyTable*); extern void return_keytable(bthread_keytable_pool_t*, KeyTable*);
......
...@@ -21,6 +21,6 @@ ...@@ -21,6 +21,6 @@
namespace butil { namespace butil {
__thread StringMapThreadLocalTemp tls_stringmap_temp = { false, {} }; thread_local StringMapThreadLocalTemp tls_stringmap_temp = { false, {} };
} // namespace butil } // namespace butil
...@@ -95,7 +95,7 @@ struct StringMapThreadLocalTemp { ...@@ -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> template <typename T, typename C, typename A>
typename std::map<std::string, T, C, A>::const_iterator typename std::map<std::string, T, C, A>::const_iterator
......
...@@ -174,7 +174,9 @@ void fun4(void* arg) { ...@@ -174,7 +174,9 @@ void fun4(void* arg) {
} }
static void check_result() { 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) { TEST_F(BaiduThreadLocalTest, call_order_and_cancel) {
......
...@@ -135,6 +135,7 @@ TEST(FutexTest, futex_wake_many_waiters_perf) { ...@@ -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); printf("N=%lu, futex_wake a thread = %" PRId64 "ns\n", N, tm.n_elapsed() / N);
ASSERT_EQ(N, (size_t)nwakeup); ASSERT_EQ(N, (size_t)nwakeup);
sleep(2);
const size_t REP = 10000; const size_t REP = 10000;
nwakeup = 0; nwakeup = 0;
tm.start(); tm.start();
......
...@@ -2131,12 +2131,12 @@ TEST_F(FileUtilTest, TouchFile) { ...@@ -2131,12 +2131,12 @@ TEST_F(FileUtilTest, TouchFile) {
// 784915200000000 represents the timestamp of "Wed, 16 Nov 1994, 00:00:00". // 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 // This timestamp is divisible by one day (in local timezone), to make it work
// on FAT too. // 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". // 784903526000000 represents the timestamp of "Tue, 15 Nov 1994, 12:45:26 GMT".
// Note that this timestamp is divisible by two (seconds) - FAT stores // Note that this timestamp is divisible by two (seconds) - FAT stores
// modification times with 2s resolution. // 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)); ASSERT_TRUE(TouchFile(foobar, access_time, modification_time));
File::Info file_info; File::Info file_info;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment