From d10702820672de38ee45c1c8119db83feda0098d Mon Sep 17 00:00:00 2001
From: Michal Rostecki <mrostecki@suse.de>
Date: Fri, 16 Nov 2018 12:50:17 +0100
Subject: [PATCH] bazel: Unbundle dependencies packaged in openSUSE

Unbundle the following libraries:
- Abseil
- BoringSSL
- googletest
- rapidjson
---
 BUILD            | 75 +++++++++++++++++++++++++++++++------
 WORKSPACE        | 13 -------
 googletest.BUILD | 40 --------------------
 rapidjson.BUILD  |  6 ---
 repositories.bzl | 96 ------------------------------------------------
 5 files changed, 63 insertions(+), 167 deletions(-)
 delete mode 100644 googletest.BUILD
 delete mode 100644 rapidjson.BUILD
 delete mode 100644 repositories.bzl

diff --git a/BUILD b/BUILD
index 99ce7b5..817033c 100644
--- a/BUILD
+++ b/BUILD
@@ -4,6 +4,57 @@ package(default_visibility = ["//visibility:public"])
 
 exports_files(["LICENSE"])
 
+cc_library(
+    name = "ssl",
+    hdrs = glob([
+        "thirdparty_build/include/boringssl/**/*.h",
+    ]),
+    copts = ["-I/usr/include/boringssl"],
+    linkopts = ["-lboringssl_crypto", "-lboringssl_decrepit", "-lboringssl_ssl"],
+)
+
+cc_library(
+    name = "abseil_strings",
+    hdrs = glob(["thirdparty_build/include/absl/**/*.h"]),
+    copts = ["-I/usr/include/absl"],
+    linkopts = [
+        "-labsl_base_libbase",
+        "-labsl_base_libthrow_delegate",
+        "-labsl_strings_libinternal",
+        "-labsl_strings_libstr_format_internal",
+        "-labsl_strings_libstrings",
+    ],
+)
+
+cc_library(
+    name = "abseil_time",
+    hdrs = glob(["thirdparty_build/include/absl/**/*.h"]),
+    copts = ["-I/usr/include/absl"],
+    linkopts = [
+        "-labsl_base_libbase",
+        "-labsl_base_libspinlock_wait",
+        "-labsl_numeric_libint128",
+        "-labsl_time_internal_cctz_libcivil_time",
+        "-labsl_time_internal_cctz_libtime_zone",
+        "-labsl_time_libtest_util",
+        "-labsl_time_libtime",
+    ],
+)
+
+cc_library(
+    name = "rapidjson",
+    hdrs = glob(["thirdparty_build/include/rapidjson/**/*.h"]),
+    copts = ["-I/usr/include/rapidjson"],
+    linkopts = [],
+)
+
+cc_library(
+    name = "googletest_main",
+    hdrs = glob(["thirdparty_build/include/gtest/**/*.h"]),
+    copts = ["-I/usr/include/gtest"],
+    linkopts = ["-lgtest", "-lgtest_main"],
+)
+
 cc_library(
     name = "jwt_verify_lib",
     srcs = [
@@ -21,10 +72,10 @@ cc_library(
         "jwt_verify_lib/verify.h",
     ],
     deps = [
-        "//external:abseil_strings",
-        "//external:abseil_time",
-        "//external:rapidjson",
-        "//external:ssl",
+        "abseil_strings",
+        "abseil_time",
+        "rapidjson",
+        "ssl",
     ],
 )
 
@@ -40,7 +91,7 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
 
@@ -56,7 +107,7 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
 
@@ -72,7 +123,7 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
 
@@ -89,7 +140,7 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
 
@@ -106,7 +157,7 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
 
@@ -123,7 +174,7 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
 
@@ -140,7 +191,7 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
 
@@ -157,6 +208,6 @@ cc_test(
     linkstatic = 1,
     deps = [
         ":jwt_verify_lib",
-        "//external:googletest_main",
+        "googletest_main",
     ],
 )
diff --git a/WORKSPACE b/WORKSPACE
index ffd5f49..e69de29 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,13 +0,0 @@
-load(
-    "//:repositories.bzl",
-    "boringssl_repositories",
-    "googletest_repositories",
-    "rapidjson_repositories",
-    "abseil_repositories",
-)
-
-boringssl_repositories()
-googletest_repositories()
-rapidjson_repositories()
-abseil_repositories()
-
diff --git a/googletest.BUILD b/googletest.BUILD
deleted file mode 100644
index 7df7ab7..0000000
--- a/googletest.BUILD
+++ /dev/null
@@ -1,40 +0,0 @@
-
-cc_library(
-    name = "googletest",
-    srcs = [
-        "googletest/src/gtest-all.cc",
-        "googlemock/src/gmock-all.cc",
-    ],
-    hdrs = glob([
-        "googletest/include/**/*.h",
-        "googlemock/include/**/*.h",
-        "googletest/src/*.cc",
-        "googletest/src/*.h",
-        "googlemock/src/*.cc",
-    ]),
-    includes = [
-        "googlemock",
-        "googletest",
-        "googletest/include",
-        "googlemock/include",
-    ],
-    visibility = ["//visibility:public"],
-)
-
-cc_library(
-    name = "googletest_main",
-    srcs = ["googlemock/src/gmock_main.cc"],
-    visibility = ["//visibility:public"],
-    deps = [":googletest"],
-)
-
-cc_library(
-    name = "googletest_prod",
-    hdrs = [
-        "googletest/include/gtest/gtest_prod.h",
-    ],
-    includes = [
-        "googletest/include",
-    ],
-    visibility = ["//visibility:public"],
-)
diff --git a/rapidjson.BUILD b/rapidjson.BUILD
deleted file mode 100644
index c69d99f..0000000
--- a/rapidjson.BUILD
+++ /dev/null
@@ -1,6 +0,0 @@
-cc_library(
-    name = "rapidjson",
-    hdrs = glob(["include/rapidjson/**/*.h"]),
-    includes = ["include"],
-    visibility = ["//visibility:public"],
-)
diff --git a/repositories.bzl b/repositories.bzl
deleted file mode 100644
index 9df179d..0000000
--- a/repositories.bzl
+++ /dev/null
@@ -1,96 +0,0 @@
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-BORINGSSL_COMMIT = "9df0c47bc034d60d73d216cd0e090707b3fbea58"  # same as Envoy
-BORINGSSL_SHA256 = "86d0614bb9e6cb4e6444b83bb1f031755eff4bbe52cd8f4cd5720bb84a7ea9f5"
-
-def boringssl_repositories(bind=True):
-    http_archive(
-        name = "boringssl",
-        strip_prefix = "boringssl-" + BORINGSSL_COMMIT,
-        url = "https://github.com/google/boringssl/archive/" + BORINGSSL_COMMIT + ".tar.gz",
-        sha256 = BORINGSSL_SHA256,
-    )
-
-    if bind:
-        native.bind(
-            name = "ssl",
-            actual = "@boringssl//:ssl",
-        )
-
-GOOGLETEST_COMMIT = "43863938377a9ea1399c0596269e0890b5c5515a"
-GOOGLETEST_SHA256 = "7c8ece456ad588c30160429498e108e2df6f42a30888b3ec0abf5d9792d9d3a0"
-
-def googletest_repositories(bind=True):
-    http_archive(
-        name = "googletest_git",
-        build_file = "//:googletest.BUILD",
-        strip_prefix = "googletest-" + GOOGLETEST_COMMIT,
-        url = "https://github.com/google/googletest/archive/" + GOOGLETEST_COMMIT + ".tar.gz",
-        sha256 = GOOGLETEST_SHA256,
-    )
-
-    if bind:
-        native.bind(
-            name = "googletest",
-            actual = "@googletest_git//:googletest",
-        )
-
-        native.bind(
-            name = "googletest_main",
-            actual = "@googletest_git//:googletest_main",
-        )
-
-        native.bind(
-            name = "googletest_prod",
-            actual = "@googletest_git//:googletest_prod",
-        )
-
-RAPIDJSON_COMMIT = "f54b0e47a08782a6131cc3d60f94d038fa6e0a51"
-RAPIDJSON_SHA256 = "4a76453d36770c9628d7d175a2e9baccbfbd2169ced44f0cb72e86c5f5f2f7cd"
-
-def rapidjson_repositories(bind=True):
-    http_archive(
-        name = "com_github_tencent_rapidjson",
-        build_file = "//:rapidjson.BUILD",
-        strip_prefix = "rapidjson-" + RAPIDJSON_COMMIT,
-        url = "https://github.com/tencent/rapidjson/archive/" + RAPIDJSON_COMMIT + ".tar.gz",
-        sha256 = RAPIDJSON_SHA256,
-    )
-
-    if bind:
-        native.bind(
-            name = "rapidjson",
-            actual = "@com_github_tencent_rapidjson//:rapidjson",
-        )
-
-ABSEIL_COMMIT = "cc8dcd307b76a575d2e3e0958a4fe4c7193c2f68"  # same as Envoy
-ABSEIL_SHA256 = "e35082e88b9da04f4d68094c05ba112502a5063712f3021adfa465306d238c76"
-
-def abseil_repositories(bind=True):
-    http_archive(
-        name = "com_google_absl",
-        strip_prefix = "abseil-cpp-" + ABSEIL_COMMIT,
-        url = "https://github.com/abseil/abseil-cpp/archive/" + ABSEIL_COMMIT + ".tar.gz",
-        sha256 = ABSEIL_SHA256,
-    )
-
-    if bind:
-        native.bind(
-            name = "abseil_strings",
-            actual = "@com_google_absl//absl/strings:strings",
-        )
-        native.bind(
-            name = "abseil_time",
-            actual = "@com_google_absl//absl/time:time",
-        )
-    _cctz_repositories(bind)
-
-CCTZ_COMMIT = "e19879df3a14791b7d483c359c4acd6b2a1cd96b"
-CCTZ_SHA256 = "35d2c6cf7ddef1cf7c1bb054bdf2e8d7778242f6d199591a834c14d224b80c39"
-
-def _cctz_repositories(bind=True):
-    http_archive(
-        name = "com_googlesource_code_cctz",
-        url = "https://github.com/google/cctz/archive/" + CCTZ_COMMIT + ".tar.gz",
-        sha256 = CCTZ_SHA256,
-    )
\ No newline at end of file
-- 
2.20.1

