aboutsummaryrefslogtreecommitdiff
path: root/BUILD.bazel
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@google.com>2024-03-20 09:56:14 +1000
committerBoringssl LUCI CQ <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-04-26 22:19:48 +0000
commite2d7f2d625257b2c250ea2f18d3f832add5b43bf (patch)
treea31ca72702b1c2166dd43084991d0c22ba6f0c54 /BUILD.bazel
parent765751395cf12e5842145d56ec339a1a07a1ea53 (diff)
downloadboringssl-e2d7f2d625257b2c250ea2f18d3f832add5b43bf.zip
boringssl-e2d7f2d625257b2c250ea2f18d3f832add5b43bf.tar.gz
boringssl-e2d7f2d625257b2c250ea2f18d3f832add5b43bf.tar.bz2
Add a standalone Bazel build
Now that we can generate build files, we can actually maintain a Bazel build in HEAD, without synthesizing a separate "-with-bazel" branch. (Though we'll still need both for a transition, and until all the other build modes have migrated.) Note this has a slightly different directory structure than the old -with-bazel branch. But the targets are the same and #include <openssl/whatever.h> still works, so hopefully it's compatible. For now, I'm only setting this up with the new bzlmod scheme. Also since pulling in googletest is much less tedious with bzlmod, I've wired up tests and everything. https://bazel.build/external/overview#bzlmod To build, run commands like: bazelisk build ... bazelisk test ... bazelisk run :bssl The thinking is we can also go add this to CI and whatnot. This is also intended to replace the boringssl module in the bazel-central-registry which someone else set up already. To ease the transition, I've seeded the compatibility_level value with theirs. (I think we want to never bump it. Although we don't do SemVer, I think bzlmod's MVS version selection scheme is generally reasonable. Bumping it just introduces hiccups into the update process where projects need to coordinate updates, and we do not want that.) I wasn't clear on what to put in the version field in the tree, so I just went with 0.0.0-dev so we don't have to change it, but it's still vaguely analogous to the versions already in there. As part of this, I've added support for Bazel's runfiles mechanism in crypto/test/test_data.cc. This is completely undocumented and I had to figure out how it works by guessing, but I believe this is the officially supported way to make cc_test(data = ...) work? The official documentation says to use devtools_build::GetDataDependencyFilepath, but that API does not exist in the first place. I've also made it build with C++17 for now, so we can build libpki, but C++14 consumers should still be able to use this module, just not build libpki. To that end, one difference between this and the old module is that we no longer specify the C++ version in the build. From what I can tell, Bazel does *not* want libraries to set the C/C++ version and prefers it only come from the root. Unfortunately, they provide zero tools to effectively manage this. I've followed this pattern for C++ versions, as we can assume that Bazel projects are very aware of their C++ version, but I've explicitly ignored it for the C version. Projects tend not to change ABIs by C version, so it should be fine to set it internally. For context when reviewing, the unreadable MODULE.bazel.lock is automatically generated. I think the idea is that subsequent diffs will be more readable?? Bug: 542 Change-Id: I88f68b2602a75f58cc6d18832a956f01dc054f58 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/67301 Auto-Submit: David Benjamin <davidben@google.com> Commit-Queue: Bob Beck <bbe@google.com> Reviewed-by: Bob Beck <bbe@google.com>
Diffstat (limited to 'BUILD.bazel')
-rw-r--r--BUILD.bazel183
1 files changed, 183 insertions, 0 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 0000000..d3b66ee
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,183 @@
+# Copyright (c) 2024, Google Inc.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+load(
+ ":gen/sources.bzl",
+ "bcm_internal_headers",
+ "bcm_sources",
+ "bcm_sources_asm",
+ "bssl_internal_headers",
+ "bssl_sources",
+ "crypto_headers",
+ "crypto_internal_headers",
+ "crypto_sources",
+ "crypto_sources_asm",
+ "crypto_test_data",
+ "crypto_test_sources",
+ "decrepit_internal_headers",
+ "decrepit_sources",
+ "decrepit_test_sources",
+ "pki_headers",
+ "pki_internal_headers",
+ "pki_sources",
+ "pki_test_data",
+ "pki_test_sources",
+ "ssl_headers",
+ "ssl_internal_headers",
+ "ssl_sources",
+ "ssl_test_sources",
+ "test_support_internal_headers",
+ "test_support_sources",
+ "test_support_sources_asm",
+ "urandom_test_sources",
+)
+load(":util/util.bzl", "bssl_cc_binary", "bssl_cc_library", "bssl_cc_test")
+
+licenses(["notice"])
+
+exports_files(["LICENSE"])
+
+bssl_cc_library(
+ name = "crypto",
+ srcs = bcm_sources + crypto_sources,
+ hdrs = crypto_headers,
+ asm_srcs = bcm_sources_asm + crypto_sources_asm,
+ copts = ["-DBORINGSSL_IMPLEMENTATION"],
+ includes = ["include"],
+ internal_hdrs = bcm_internal_headers + crypto_internal_headers,
+ linkopts = select({
+ "@platforms//os:windows": [
+ "-defaultlib:advapi32.lib",
+ "-defaultlib:ws2_32.lib",
+ ],
+ "//conditions:default": ["-pthread"],
+ }),
+ visibility = ["//visibility:public"],
+)
+
+bssl_cc_library(
+ name = "ssl",
+ srcs = ssl_sources,
+ hdrs = ssl_headers,
+ copts = ["-DBORINGSSL_IMPLEMENTATION"],
+ internal_hdrs = ssl_internal_headers,
+ visibility = ["//visibility:public"],
+ deps = [":crypto_internal"],
+)
+
+bssl_cc_library(
+ name = "test_support",
+ testonly = True,
+ srcs = test_support_sources,
+ asm_srcs = test_support_sources_asm,
+ copts = ["-DBORINGSSL_USE_BAZEL_RUNFILES"],
+ internal_hdrs = test_support_internal_headers,
+ deps = [
+ ":crypto_internal",
+ "@bazel_tools//tools/cpp/runfiles",
+ "@googletest//:gtest",
+ ],
+)
+
+bssl_cc_test(
+ name = "crypto_test",
+ size = "large",
+ srcs = crypto_test_sources,
+ data = crypto_test_data,
+ # crypto_test references assembly symbols directly and thus must be linked
+ # statically.
+ linkstatic = True,
+ shard_count = 32,
+ deps = [
+ ":crypto_internal",
+ ":test_support",
+ "@googletest//:gtest",
+ ],
+)
+
+bssl_cc_test(
+ name = "urandom_test",
+ srcs = urandom_test_sources,
+ deps = [
+ ":crypto_internal",
+ ":test_support",
+ "@googletest//:gtest",
+ ],
+)
+
+bssl_cc_test(
+ name = "ssl_test",
+ srcs = ssl_test_sources,
+ deps = [
+ ":crypto_internal",
+ ":ssl_internal",
+ ":test_support",
+ "@googletest//:gtest",
+ ],
+)
+
+bssl_cc_binary(
+ name = "bssl",
+ srcs = bssl_sources + bssl_internal_headers,
+ visibility = ["//visibility:public"],
+ deps = [
+ ":crypto_internal",
+ ":ssl_internal",
+ ],
+)
+
+# Build, but do not export libdecrepit.
+bssl_cc_library(
+ name = "decrepit",
+ srcs = decrepit_sources,
+ copts = ["-DBORINGSSL_IMPLEMENTATION"],
+ internal_hdrs = decrepit_internal_headers,
+ deps = [
+ ":crypto_internal",
+ ":ssl_internal",
+ ],
+)
+
+bssl_cc_test(
+ name = "decrepit_test",
+ srcs = decrepit_test_sources,
+ deps = [
+ ":crypto_internal",
+ ":decrepit",
+ ":test_support",
+ "@googletest//:gtest",
+ ],
+)
+
+# Build, but do not (yet) export libpki.
+bssl_cc_library(
+ name = "pki",
+ srcs = pki_sources,
+ hdrs = pki_headers,
+ copts = ["-DBORINGSSL_IMPLEMENTATION"],
+ internal_hdrs = pki_internal_headers,
+ deps = [":crypto"],
+)
+
+bssl_cc_test(
+ name = "pki_test",
+ srcs = pki_test_sources,
+ data = pki_test_data,
+ deps = [
+ ":crypto_internal",
+ ":pki",
+ ":test_support",
+ "@googletest//:gtest",
+ ],
+)