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
# 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
......@@ -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"],
)
......@@ -65,3 +65,25 @@ http_archive(
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"
)
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 @@
#include "brpc/span.pb.h"
namespace bthread {
extern __thread bthread::LocalStorage tls_bls;
extern thread_local bthread::LocalStorage tls_bls;
}
......
......@@ -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
......
......@@ -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*);
......
......@@ -21,6 +21,6 @@
namespace butil {
__thread StringMapThreadLocalTemp tls_stringmap_temp = { false, {} };
thread_local StringMapThreadLocalTemp tls_stringmap_temp = { false, {} };
} // namespace butil
......@@ -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
......
......@@ -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) {
......
......@@ -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();
......
......@@ -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;
......
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