Add WORKSPACE and .bazelrc and make other changes for bazel build.

PiperOrigin-RevId: 428343135
This commit is contained in:
suetfei
2022-02-13 08:50:47 -08:00
committed by Copybara-Service
parent 47072f1f1a
commit 3c8a279829
12 changed files with 203 additions and 373 deletions
+3
View File
@@ -0,0 +1,3 @@
build --action_env=BAZEL_CXXOPTS=-std=c++17
# Definition of --config=memcheck
build:memcheck --strip=never --test_timeout=3600
+20 -5
View File
@@ -26,11 +26,26 @@ git submodule update --init --recursive
```
# Building Nearby, Unit Testing and Sample Apps
We support multiple platforms including Linux, iOS & Windows. The ultimate goal
is to build from source (coming soon!). The offical build system we support is
[bazel] (https://bazel.build). Before that is accomplished, we provide
precompiled libraries as stop-gap solutions. See the following pages for
platform specific instructions.
We support multiple platforms including Linux, iOS & Windows.
## Building for Linux
Currently we support building from source using [bazel] (https://bazel.build). Other BUILD system such as cmake may be added later.
Prerequisites:
1. Bazel
2. clang with support for c++ 17+
3. Openssl libcrypto.so (-lssl;-lcrypto).
To build the Nearby Connection Core library:
```shell
cd src
CC=clang CXX=clang++ bazel build -s --check_visibility=false //connections:core --spawn_strategy=standalone --verbose_failures
```
## iOS
Currently we provide precompiled libraries. See the following page for instructions.
* [iOS](https://github.com/google/nearby/blob/master/docs/ios_build.md)
+155
View File
@@ -0,0 +1,155 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Rule repository, note that it's recommended to use a pinned commit to a released version of the rules
http_archive(
name = "rules_foreign_cc",
strip_prefix = "rules_foreign_cc-0.6.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.6.0.tar.gz",
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
# This sets up some common toolchains for building targets. For more details, please see
# https://github.com/bazelbuild/rules_foreign_cc/tree/main/docs#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()
_ALL_CONTENT = """\
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""
http_archive(
name = "com_google_absl",
strip_prefix = "abseil-cpp-master",
urls = ["https://github.com/abseil/abseil-cpp/archive/master.zip"],
)
# Using a protobuf javalite version that contains @com_google_protobuf_javalite//:javalite_toolchain
http_archive(
name = "com_google_protobuf_javalite",
strip_prefix = "protobuf-javalite",
urls = ["https://github.com/google/protobuf/archive/javalite.zip"],
)
http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-3.17.0",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.17.0.tar.gz"],
)
http_archive(
name = "com_google_protobuf_cc",
strip_prefix = "protobuf-3.17.0",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.17.0.tar.gz"],
)
http_archive(
name = "com_google_protobuf_java",
strip_prefix = "protobuf-3.17.0",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.17.0.tar.gz"],
)
http_archive(
name = "com_google_glog",
sha256 = "f28359aeba12f30d73d9e4711ef356dc842886968112162bc73002645139c39c",
strip_prefix = "glog-0.4.0",
urls = ["https://github.com/google/glog/archive/v0.4.0.tar.gz"],
)
new_local_repository(
name = "com_google_ukey2",
path = "./third_party/ukey2",
build_file_content = _ALL_CONTENT,
)
http_archive(
name = "aappleby_smhasher",
strip_prefix = "smhasher-master",
build_file_content = """
package(default_visibility = ["//visibility:public"])
cc_library(
name = "libmurmur3",
srcs = ["src/MurmurHash3.cpp"],
hdrs = ["src/MurmurHash3.h"],
copts = ["-Wno-implicit-fallthrough"],
licenses = ["unencumbered"], # MurmurHash is explicity public-domain
)""",
urls = ["https://github.com/aappleby/smhasher/archive/master.zip"],
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
# Load common dependencies.
protobuf_deps()
http_archive(
name = "com_google_googletest",
strip_prefix = "googletest-main",
urls = ["https://github.com/google/googletest/archive/main.zip"],
)
http_archive(
name = "com_google_webrtc",
build_file_content = """
package(default_visibility = ["//visibility:public"])
""",
urls = ["https://webrtc.googlesource.com/src/+archive/main.tar.gz"],
)
# gflags needed by glog
http_archive(
name = "com_github_gflags_gflags",
strip_prefix = "gflags-2.2.2",
sha256 = "19713a36c9f32b33df59d1c79b4958434cb005b5b47dc5400a7a4b078111d9b5",
url = "https://github.com/gflags/gflags/archive/v2.2.2.zip",
)
# ----------------------------------------------
# Nisaba: Script processing library from Google:
# ----------------------------------------------
# We depend on some of core C++ libraries from Nisaba and use the fresh code
# from the HEAD. See
# https://github.com/google-research/nisaba
nisaba_version = "main"
http_archive(
name = "com_google_nisaba",
url = "https://github.com/google-research/nisaba/archive/refs/heads/%s.zip" % nisaba_version,
strip_prefix = "nisaba-%s" % nisaba_version,
)
load("@com_google_nisaba//bazel:workspace.bzl", "nisaba_public_repositories")
nisaba_public_repositories()
http_archive(
name = "boringssl", # Must match upstream workspace name.
# Gitiles creates gzip files with an embedded timestamp, so we cannot use
# sha256 to validate the archives. We must rely on the commit hash and
# https. Commits must come from the master-with-bazel branch.
urls = ["https://codeload.github.com/google/boringssl/zip/master-with-bazel"],
strip_prefix = "boringssl-master-with-bazel",
type = "zip",
)
# -------------------------------------------------------------------------
# Protocol buffer matches (should be part of gmock and gtest, but not yet):
# https://github.com/inazarenko/protobuf-matchers
http_archive(
name = "com_github_protobuf_matchers",
urls = ["https://github.com/inazarenko/protobuf-matchers/archive/refs/heads/master.zip"],
strip_prefix = "protobuf-matchers-master",
)
http_archive(
name = "com_googlesource_code_re2",
sha256 = "26155e050b10b5969e986dab35654247a3b1b295e0532880b5a9c13c0a700ceb",
strip_prefix = "re2-2021-06-01",
urls = [
"https://github.com/google/re2/archive/refs/tags/2021-06-01.tar.gz",
],
)
+24
View File
@@ -1,3 +1,5 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +15,28 @@
# limitations under the License.
licenses(["notice"])
cmake(
name = "ukey2",
env = {
"CC": "clang",
"CXX": "clang++",
},
generate_args = [
"-DBYPASS_TESTING=ON", # Set the flags in CMakeLists.txt (ukey2 & its dependencies) here.
"-Dukey2_USE_LOCAL_ABSL=ON",
"-Dukey2_USE_LOCAL_PROTOBUF=ON", # Add -DCMAKE_BUILD_TYPE=Debug for debugger & Valgrind
],
lib_source = "@com_google_ukey2//:all_srcs",
out_static_libs = [
"libproto_device_to_device_messages_cc_proto.a",
"libproto_securegcm_cc_proto.a",
"libproto_securemessage_cc_proto.a",
"libproto_ukey_cc_proto.a",
"libsecuremessage.a",
"libukey2.a",
],
)
cc_library(
name = "internal",
srcs = [
-216
View File
@@ -1,216 +0,0 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
cc_library(
name = "internal",
srcs = [
"base_endpoint_channel.cc",
"base_pcp_handler.cc",
"ble_advertisement.cc",
"ble_endpoint_channel.cc",
"bluetooth_bwu_handler.cc",
"bluetooth_device_name.cc",
"bluetooth_endpoint_channel.cc",
"bwu_manager.cc",
"client_proxy.cc",
"encryption_runner.cc",
"endpoint_channel_manager.cc",
"endpoint_manager.cc",
"injected_bluetooth_device_store.cc",
"internal_payload.cc",
"internal_payload_factory.cc",
"offline_frames.cc",
"offline_frames_validator.cc",
"offline_service_controller.cc",
"p2p_cluster_pcp_handler.cc",
"p2p_point_to_point_pcp_handler.cc",
"p2p_star_pcp_handler.cc",
"payload_manager.cc",
"pcp_manager.cc",
"service_controller_router.cc",
"webrtc_bwu_handler.cc",
"webrtc_endpoint_channel.cc",
"wifi_lan_bwu_handler.cc",
"wifi_lan_endpoint_channel.cc",
"wifi_lan_service_info.cc",
],
hdrs = [
"base_bwu_handler.h",
"base_endpoint_channel.h",
"base_pcp_handler.h",
"ble_advertisement.h",
"ble_endpoint_channel.h",
"bluetooth_bwu_handler.h",
"bluetooth_device_name.h",
"bluetooth_endpoint_channel.h",
"bwu_handler.h",
"bwu_manager.h",
"client_proxy.h",
"encryption_runner.h",
"endpoint_channel.h",
"endpoint_channel_manager.h",
"endpoint_manager.h",
"injected_bluetooth_device_store.h",
"internal_payload.h",
"internal_payload_factory.h",
"offline_frames.h",
"offline_frames_validator.h",
"offline_service_controller.h",
"p2p_cluster_pcp_handler.h",
"p2p_point_to_point_pcp_handler.h",
"p2p_star_pcp_handler.h",
"payload_manager.h",
"pcp.h",
"pcp_handler.h",
"pcp_manager.h",
"service_controller.h",
"service_controller_router.h",
"webrtc_bwu_handler.h",
"webrtc_endpoint_channel.h",
"wifi_lan_bwu_handler.h",
"wifi_lan_endpoint_channel.h",
"wifi_lan_service_info.h",
],
compatible_with = ["//buildenv/target:non_prod"],
copts = ["-DCORE_ADAPTER_DLL"],
defines = ["NO_WEBRTC"],
visibility = [
"//third_party/nearby/connections:__pkg__",
"//third_party/nearby/connections/implementation/fuzzers:__pkg__",
],
deps = [
":message_lite",
"//third_party/absl/base:core_headers",
"//third_party/absl/container:btree",
"//third_party/absl/container:flat_hash_map",
"//third_party/absl/container:flat_hash_set",
"//third_party/absl/functional:bind_front",
"//third_party/absl/memory",
"//third_party/absl/strings",
"//third_party/absl/time",
"//third_party/absl/types:span",
"//third_party/nearby/connections/implementation/proto:offline_wire_formats_portable_proto",
"//third_party/nearby/connections:core_types",
"//third_party/nearby/connections/implementation/mediums",
"//third_party/nearby/connections/implementation/mediums:utils",
"//third_party/nearby/internal/platform/implementation:comm",
"//third_party/nearby/internal/platform:base",
"//third_party/nearby/internal/platform:cancellation_flag",
"//third_party/nearby/internal/platform:error_code_recorder",
"//third_party/nearby/internal/platform:util",
"//third_party/nearby/internal/platform:comm",
"//third_party/nearby/internal/platform:logging",
"//third_party/nearby/internal/platform:types",
"//third_party/nearby/internal/analytics",
"//third_party/nearby/proto:connections_enums_portable_proto",
"//third_party/ukey2",
],
)
cc_library(
name = "message_lite",
hdrs = [
"message_lite.h",
],
compatible_with = ["//buildenv/target:non_prod"],
visibility = [
"//third_party/nearby/connections:__subpackages__",
],
deps = [
"//net/proto2/public:proto2_lite",
],
)
cc_library(
name = "internal_test",
testonly = True,
srcs = [
"offline_simulation_user.cc",
"simulation_user.cc",
],
hdrs = [
"mock_service_controller.h",
"mock_service_controller_router.h",
"offline_simulation_user.h",
"simulation_user.h",
],
defines = ["NO_WEBRTC"],
visibility = [
"//third_party/nearby/connections:__subpackages__",
],
deps = [
":internal",
"//testing/base/public:gunit_for_library_testonly",
"//third_party/absl/functional:bind_front",
"//third_party/absl/strings",
"//third_party/nearby/connections:core_types",
"//third_party/nearby/internal/platform:base",
"//third_party/nearby/internal/platform:test_util",
"//third_party/nearby/internal/platform:types",
],
)
cc_test(
name = "core_internal_test",
size = "small",
timeout = "moderate",
srcs = [
"base_endpoint_channel_test.cc",
"base_pcp_handler_test.cc",
"ble_advertisement_test.cc",
"bluetooth_device_name_test.cc",
"bwu_manager_test.cc",
"client_proxy_test.cc",
"encryption_runner_test.cc",
"endpoint_channel_manager_test.cc",
"endpoint_manager_test.cc",
"injected_bluetooth_device_store_test.cc",
"internal_payload_factory_test.cc",
"offline_frames_test.cc",
"offline_frames_validator_test.cc",
"offline_service_controller_test.cc",
"p2p_cluster_pcp_handler_test.cc",
"payload_manager_test.cc",
"pcp_manager_test.cc",
"service_controller_router_test.cc",
"wifi_lan_service_info_test.cc",
],
defines = ["NO_WEBRTC"],
shard_count = 16,
deps = [
":internal",
":internal_test",
"//testing/base/public:gunit",
"//testing/base/public:gunit_main",
"//third_party/absl/container:flat_hash_set",
"//third_party/absl/strings",
"//third_party/absl/synchronization",
"//third_party/absl/time",
"//third_party/absl/types:span",
"//third_party/nearby/connections/implementation/proto:offline_wire_formats_portable_proto",
"//third_party/nearby/connections:core_types",
"//third_party/nearby/connections/implementation/mediums",
"//third_party/nearby/connections/implementation/mediums:utils",
"//third_party/nearby/internal/platform:base",
"//third_party/nearby/internal/platform:test_util",
"//third_party/nearby/internal/platform/implementation/g3", # build_cleaner: keep
"//third_party/nearby/internal/platform:comm",
"//third_party/nearby/internal/platform:logging",
"//third_party/nearby/internal/platform:types",
"//third_party/nearby/internal/analytics",
"//third_party/nearby/proto:connections_enums_portable_proto",
"//third_party/ukey2",
],
)
@@ -1,113 +0,0 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
cc_library(
name = "mediums",
srcs = [
"ble.cc",
"bluetooth_classic.cc",
"bluetooth_radio.cc",
"mediums.cc",
"uuid.cc",
"webrtc_stub.cc",
"wifi_lan.cc",
],
hdrs = [
"ble.h",
"bluetooth_classic.h",
"bluetooth_radio.h",
"lost_entity_tracker.h",
"mediums.h",
"uuid.h",
"webrtc_stub.h",
"wifi_lan.h",
],
compatible_with = ["//buildenv/target:non_prod"],
defines = ["NO_WEBRTC"],
visibility = [
"//third_party/nearby/connections/implementation:__subpackages__",
],
deps = [
":utils",
"//third_party/absl/container:flat_hash_map",
"//third_party/absl/container:flat_hash_set",
"//third_party/absl/functional:bind_front",
"//third_party/absl/strings",
"//third_party/absl/strings:str_format",
"//third_party/absl/time",
"//third_party/nearby/connections/implementation/proto:offline_wire_formats_portable_proto",
"//third_party/nearby/connections:core_types",
"//third_party/nearby/connections/implementation/mediums/ble_v2",
"//third_party/nearby/internal/platform:base",
"//third_party/nearby/internal/platform:cancellation_flag",
"//third_party/nearby/internal/platform:comm",
"//third_party/nearby/internal/platform:logging",
"//third_party/nearby/internal/platform:types",
"//third_party/nearby/proto/mediums:web_rtc_signaling_frames_cc_proto",
],
)
cc_library(
name = "utils",
srcs = [
"utils.cc",
"webrtc_peer_id.cc",
],
hdrs = [
"utils.h",
"webrtc_peer_id.h",
"webrtc_socket_stub.h",
],
compatible_with = ["//buildenv/target:non_prod"],
defines = ["NO_WEBRTC"],
visibility = [
"//third_party/nearby/connections/implementation:__pkg__",
"//third_party/nearby/connections/implementation/mediums:__pkg__",
],
deps = [
"//third_party/absl/strings",
"//third_party/nearby/connections/implementation/proto:offline_wire_formats_portable_proto",
"//third_party/nearby/internal/platform:base",
"//third_party/nearby/internal/platform:types",
],
)
cc_test(
name = "core_internal_mediums_test",
size = "small",
srcs = [
"ble_test.cc",
"bluetooth_classic_test.cc",
"bluetooth_radio_test.cc",
"lost_entity_tracker_test.cc",
"uuid_test.cc",
"webrtc_peer_id_test.cc",
"wifi_lan_test.cc",
],
defines = ["NO_WEBRTC"],
shard_count = 16,
deps = [
":mediums",
":utils",
"//testing/base/public:gunit_main",
"//third_party/absl/strings",
"//third_party/absl/time",
"//third_party/nearby/internal/platform:base",
"//third_party/nearby/internal/platform:test_util",
"//third_party/nearby/internal/platform/implementation/g3", # build_cleaner: keep
"//third_party/nearby/internal/platform:comm",
"//third_party/nearby/internal/platform:types",
],
)
-2
View File
@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library")
licenses(["notice"])
proto_library(
+1 -24
View File
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//tools/build_defs/cc:cc_fake_binary.bzl", "cc_fake_binary")
licenses(["notice"])
@@ -372,26 +372,3 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)
cc_fake_binary(
name = "thread_check_nocompile",
srcs = ["thread_check_nocompile.cc"],
deps = [
":types",
"@com_google_absl//absl/time",
],
)
py_test(
name = "thread_check_nocompile_test",
size = "large",
srcs = ["thread_check_nocompile_test.py"],
data = ["thread_check_nocompile"],
python_version = "PY3",
srcs_version = "PY3",
tags = ["non_compile_test"],
deps = [
"//testing/pybase",
"//testing/pybase:fake_target_util",
],
)
-2
View File
@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library")
licenses(["notice"])
package(default_visibility = ["//visibility:public"])
-7
View File
@@ -14,8 +14,6 @@
# Proto for Nearby products
load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library")
licenses(["notice"])
package(default_visibility = ["//visibility:public"])
@@ -30,11 +28,6 @@ java_lite_proto_library(
deps = [":connections_enums_proto"],
)
go_proto_library(
name = "connections_enums_go_proto",
deps = [":connections_enums_proto"],
)
java_proto_library(
name = "connections_enums_java_proto",
deps = [":connections_enums_proto"],
-2
View File
@@ -14,8 +14,6 @@
# Proto for Nearby products
load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library")
licenses(["notice"])
package(default_visibility = ["//visibility:public"])
-2
View File
@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", "cc_proto_library")
licenses(["notice"])
package(default_visibility = ["//visibility:public"])