Add support for linking user provided ICU lib This patch adds support for linking a user provided ICU library using the @org_unicode_icuuc//:common target by setting :system_icu to false. Signed-off-by: Dhi Aurrahman <dio@tetrate.io> Change-Id: Ie38f01afb537f7d4cfe7b185b00185e175d0a983
diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000..47b322c --- /dev/null +++ b/.bazelversion
@@ -0,0 +1 @@ +3.4.1
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6ef824 --- /dev/null +++ b/.gitignore
@@ -0,0 +1 @@ +/bazel-*
diff --git a/base/BUILD b/base/BUILD index 74b721d..00c6c91 100644 --- a/base/BUILD +++ b/base/BUILD
@@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. load("//build_config:build_config.bzl", "build_config") +load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( name = "base",
diff --git a/base/strings/BUILD b/base/strings/BUILD index 604cc81..c76b35a 100644 --- a/base/strings/BUILD +++ b/base/strings/BUILD
@@ -2,17 +2,17 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. load("//build_config:build_config.bzl", "build_config") +load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( name = "strings", srcs = [ - "string16.cc", "string_piece.cc", "string_util.cc", "string_util_constants.cc", "utf_string_conversion_utils.cc", "utf_string_conversions.cc", - ], + ] + build_config.strings_srcs, hdrs = [ "char_traits.h", "string16.h", @@ -20,10 +20,9 @@ "string_piece_forward.h", "string_util.h", "string_util_internal.h", - "string_util_posix.h", "utf_string_conversion_utils.h", "utf_string_conversions.h", - ], + ] + build_config.strings_hdrs, copts = build_config.default_copts, visibility = ["//visibility:public"], deps = [
diff --git a/build/BUILD b/build/BUILD index db115d4..79fa1dd 100644 --- a/build/BUILD +++ b/build/BUILD
@@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. load("//build_config:build_config.bzl", "build_config") +load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( name = "build_config",
diff --git a/build_config/BUILD b/build_config/BUILD index 9ce06a8..78ac01d 100644 --- a/build_config/BUILD +++ b/build_config/BUILD
@@ -1 +1,20 @@ -# dummy +load("//build_config:common_settings.bzl", "bool_flag") + +licenses(["notice"]) + +config_setting( + name = "windows_x86_64", + values = {"cpu": "x64_windows"}, +) + +bool_flag( + name = "system_icu", + build_setting_default = True, +) + +config_setting( + name = "with_system_icu", + flag_values = { + ":system_icu": "True", + }, +)
diff --git a/build_config/build_config.bzl b/build_config/build_config.bzl index d5fca65..9357584 100644 --- a/build_config/build_config.bzl +++ b/build_config/build_config.bzl
@@ -1,8 +1,41 @@ -_default_copts = [ - "-std=c++14", - "-fno-strict-aliasing", -] +"""This module provides common build config options""" + +_default_copts = select({ + "//build_config:windows_x86_64": [ + "/std:c++17", + ], + "//conditions:default": [ + "-std=c++17", + "-fno-strict-aliasing", + ], +}) + +_strings_srcs = select({ + "//build_config:windows_x86_64": [], + "//conditions:default": ["string16.cc"], +}) + +_strings_hdrs = select({ + "//build_config:windows_x86_64": ["string_util_win.h"], + "//conditions:default": ["string_util_posix.h"], +}) + +_url_linkopts = select({ + "//build_config:with_system_icu": ["-licuuc"], + "//conditions:default": [], +}) + +_icuuc_deps = select({ + "//build_config:with_system_icu": [], + + # If we don't link against system ICU library, we must provide "@org_unicode_icuuc//:common". + "//conditions:default": ["@org_unicode_icuuc//:common"], +}) build_config = struct( default_copts = _default_copts, + url_linkopts = _url_linkopts, + strings_srcs = _strings_srcs, + strings_hdrs = _strings_hdrs, + icuuc_deps = _icuuc_deps, )
diff --git a/build_config/common_settings.bzl b/build_config/common_settings.bzl new file mode 100644 index 0000000..adbee68 --- /dev/null +++ b/build_config/common_settings.bzl
@@ -0,0 +1,26 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# 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 +# +# http://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. + +"""This is a modified version of +https://github.com/bazelbuild/bazel-skylib/blob/2b38b2f8bd4b8603d610cfc651fcbb299498147f/rules/common_settings.bzl""" + +BuildSettingInfo = provider(fields = ["value"]) + +def _impl(ctx): + return BuildSettingInfo(value = ctx.build_setting_value) + +bool_flag = rule( + implementation = _impl, + build_setting = config.bool(flag = True), +)
diff --git a/test/BUILD b/test/BUILD index 59210a8..16b1a42 100644 --- a/test/BUILD +++ b/test/BUILD
@@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. load("//build_config:build_config.bzl", "build_config") +load("@rules_cc//cc:defs.bzl", "cc_test") cc_test( name = "basic_test",
diff --git a/url/BUILD b/url/BUILD index e9081d9..f2ec8da 100644 --- a/url/BUILD +++ b/url/BUILD
@@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. load("//build_config:build_config.bzl", "build_config") +load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( name = "url", @@ -43,11 +44,11 @@ "url_util.h", ], copts = build_config.default_copts, - linkopts = ["-licuuc"], + linkopts = build_config.url_linkopts, visibility = ["//visibility:public"], deps = [ "//base", "//base/strings", "//polyfills", - ], + ] + build_config.icuuc_deps, )