summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2023-02-13 14:24:05 -0800
committerYifan Hong <elsk@google.com>2023-03-06 21:31:07 -0800
commite53f2dbd07b9401d979dd7d03599ebc8a8ce0d69 (patch)
tree5ffb1c63d21348bf4d92663fc06bfa7ac69f18b4
parent93413a8ed0b1232d82bfdd0ea92b996dc4a89bbf (diff)
downloadbuild-tools-e53f2dbd07b9401d979dd7d03599ebc8a8ce0d69.tar.gz
kleaf: add cc_import / cc_library targets.
... That a host library can depend on. Bug: 228238975 Include-Buildifier-Warnings: enabled Change-Id: I70e3d848a3bdf8bab1847ee2d595001de84b38f3
-rw-r--r--BUILD.bazel18
-rw-r--r--cc.bzl54
2 files changed, 71 insertions, 1 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index df3d7a4..71dd246 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -1,3 +1,7 @@
+load(":cc.bzl", "import_libraries")
+
+_SHARED_LIBS = glob(["linux-x86/lib64/*.so"])
+
filegroup(
name = "linux-x86",
srcs = glob(["linux-x86/**"]),
@@ -6,7 +10,19 @@ filegroup(
filegroup(
name = "linux-x86-libs",
- srcs = glob(["linux-x86/lib64/*.so"]),
+ srcs = _SHARED_LIBS,
+ visibility = ["//visibility:public"],
+)
+
+import_libraries(
+ name = "linux_x86_imported_libs",
+ hdrs = glob(["linux-x86/include/**/*.h"]),
+ shared_libraries = _SHARED_LIBS,
+ strip_include_prefix = "linux-x86/include",
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//cpu:x86_64",
+ ],
visibility = ["//visibility:public"],
)
diff --git a/cc.bzl b/cc.bzl
new file mode 100644
index 0000000..bbfd29d
--- /dev/null
+++ b/cc.bzl
@@ -0,0 +1,54 @@
+# Copyright (C) 2023 The Android Open Source Project
+#
+# 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.
+
+"""CC rules for this package."""
+
+def import_libraries(
+ name,
+ hdrs,
+ strip_include_prefix,
+ shared_libraries,
+ **kwargs):
+ """Define a cc_library from a list of prebuilts.
+
+ Args:
+ name: name of the target.
+ hdrs: The list of header files published by this library to be directly included by
+ sources in dependent rules.
+ strip_include_prefix: The prefix to strip from the paths of the headers of this rule.
+ shared_libraries: A list of dynamic library files.
+
+ This cannot be a `filegroup`; it must be a list of targets, each corresponding
+ to a single dynamic library file.
+ **kwargs: other arguments to the top-level target.
+ """
+ private_kwargs = dict(kwargs)
+ private_kwargs["visibility"] = ["//visibility:private"]
+
+ targets = []
+ for f in shared_libraries:
+ native.cc_import(
+ name = name + "_" + f,
+ shared_library = f,
+ **private_kwargs
+ )
+ targets.append(name + "_" + f)
+
+ native.cc_library(
+ name = name,
+ deps = targets,
+ hdrs = hdrs,
+ strip_include_prefix = strip_include_prefix,
+ **kwargs
+ )