Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel Build alterations #416

Merged
merged 6 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ Add your fork as a remote:
git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-cpp.git
```

If you haven't, make sure you are loading the submodules required to build OpenTelemetry

```sh
git submodule init
git submodule update
```

Check out a new branch, make modifications and push the branch to your fork:

```sh
Expand Down
79 changes: 6 additions & 73 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@

workspace(name = "io_opentelemetry_cpp")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//bazel:repository.bzl", "opentelemetry_cpp_deps")

# Load gRPC dependency
# Note that this dependency needs to be loaded first due to
# https://github.com/bazelbuild/bazel/issues/6664
http_archive(
name = "com_github_grpc_grpc",
sha256 = "d6277f77e0bb922d3f6f56c0f93292bb4cfabfc3c92b31ee5ccea0e100303612",
strip_prefix = "grpc-1.28.0",
urls = [
"https://github.com/grpc/grpc/archive/v1.28.0.tar.gz",
],
)
# Load our direct dependencies.
opentelemetry_cpp_deps()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on these changes. The root WORKSPACE looks much cleaner now : )


# Load gRPC dependencies after load.
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

grpc_deps()
Expand All @@ -41,73 +33,14 @@ load("@upb//bazel:repository_defs.bzl", "bazel_version_repository")

bazel_version_repository(name = "upb_bazel_version")

# Uses older protobuf version because of
# https://github.com/protocolbuffers/protobuf/issues/7179
http_archive(
name = "com_google_protobuf",
sha256 = "b679cef31102ed8beddc39ecfd6368ee311cbee6f50742f13f21be7278781821",
strip_prefix = "protobuf-3.11.2",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-all-3.11.2.tar.gz",
],
)
# Load protobuf deps

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

new_local_repository(
name = "com_github_opentelemetry_proto",
build_file = "//bazel:opentelemetry_proto.BUILD",
path = "third_party/opentelemetry-proto",
)

# GoogleTest framework.
# Only needed for tests, not to build the OpenTelemetry library.
http_archive(
name = "com_google_googletest",
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
strip_prefix = "googletest-release-1.10.0",
urls = ["https://github.com/google/googletest/archive/release-1.10.0.tar.gz"],
)

# Google Benchmark library.
# Only needed for benchmarks, not to build the OpenTelemetry library.
http_archive(
name = "com_github_google_benchmark",
sha256 = "3c6a165b6ecc948967a1ead710d4a181d7b0fbcaa183ef7ea84604994966221a",
strip_prefix = "benchmark-1.5.0",
urls = ["https://github.com/google/benchmark/archive/v1.5.0.tar.gz"],
)

http_archive(
name = "github_nlohmann_json",
build_file = "//bazel:nlohmann_json.BUILD",
sha256 = "69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf",
urls = [
"https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip",
],
)

# C++ Prometheus Client library.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

http_archive(
name = "com_github_jupp0r_prometheus_cpp",
sha256 = "85ad6fea0f0dcb413104366b7d6109acdb015aff8767945511c5cad8202a28a6",
strip_prefix = "prometheus-cpp-0.9.0",
urls = ["https://github.com/jupp0r/prometheus-cpp/archive/v0.9.0.tar.gz"],
)
# Load prometheus C++ dependencies.

load("@com_github_jupp0r_prometheus_cpp//bazel:repositories.bzl", "prometheus_cpp_repositories")

prometheus_cpp_repositories()

# libcurl - An optional dependency we pull in for tests.
http_archive(
name = "curl",
build_file = "@//bazel:curl.BUILD",
sha256 = "ba98332752257b47b9dea6d8c0ad25ec1745c20424f1dd3ff2c99ab59e97cf91",
strip_prefix = "curl-7.73.0",
urls = ["https://curl.haxx.se/download/curl-7.73.0.tar.gz"],
)
80 changes: 80 additions & 0 deletions bazel/repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def opentelemetry_cpp_deps():
"""Loads dependencies need to compile the opentelemetry-cpp library."""

# Google Benchmark library.
# Only needed for benchmarks, not to build the OpenTelemetry library.
maybe(
native.local_repository,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are consumers of otel-cpp meant to load e.g. benchmark before calling opentelemetry_cpp_deps()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. I need to write the "INSTALLING" section for bazel, but basic gist is if you want to configure your own version/build that you can do so if you load BEFORE calling our macro, but you'll be on your own ensuring the version is compatible with us.

name = "com_github_google_benchmark",
path = "third_party/benchmark",
)

# GoogleTest framework.
# Only needed for tests, not to build the OpenTelemetry library.
maybe(
native.local_repository,
name = "com_google_googletest",
path = "third_party/googletest",
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. We are using google-test and benchmark from submodules directory now : )


# Load gRPC dependency
maybe(
http_archive,
name = "com_github_grpc_grpc",
sha256 = "d6277f77e0bb922d3f6f56c0f93292bb4cfabfc3c92b31ee5ccea0e100303612",
strip_prefix = "grpc-1.28.0",
urls = [
"https://github.com/grpc/grpc/archive/v1.28.0.tar.gz",
],
)

# Uses older protobuf version because of
# https://github.com/protocolbuffers/protobuf/issues/7179
maybe(
http_archive,
name = "com_google_protobuf",
sha256 = "b679cef31102ed8beddc39ecfd6368ee311cbee6f50742f13f21be7278781821",
strip_prefix = "protobuf-3.11.2",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-all-3.11.2.tar.gz",
],
)

# OTLP Protocol definition
maybe(
native.new_local_repository,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems coming from the WORKSPACE file, but still wondering why OTLP protocol definition is native.new_local_repository but others are native.local_repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the difference between something that HAS a bazel-build already, or one where we're adapting it to be a BAZEL workspace.

OTLP does NOT have a bazel build, so we're provding our own build file.

name = "com_github_opentelemetry_proto",
build_file = "//bazel:opentelemetry_proto.BUILD",
path = "third_party/opentelemetry-proto",
)

# JSON library
maybe(
http_archive,
name = "github_nlohmann_json",
build_file = "//bazel:nlohmann_json.BUILD",
sha256 = "69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf",
urls = [
"https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip",
],
)

# C++ Prometheus Client library.
maybe(
native.local_repository,
name = "com_github_jupp0r_prometheus_cpp",
path = "third_party/prometheus-cpp",
)

# libcurl (optional)
maybe(
http_archive,
name = "curl",
build_file = "@//bazel:curl.BUILD",
sha256 = "ba98332752257b47b9dea6d8c0ad25ec1745c20424f1dd3ff2c99ab59e97cf91",
strip_prefix = "curl-7.73.0",
urls = ["https://curl.haxx.se/download/curl-7.73.0.tar.gz"],
)