Revert "Remove alwayslink handling from cc_prebuilt_library* macros"
Revert submission 2467901-b/267214124
Reason for revert: compile error
Reverted changes: /q/submissionid:2467901-b/267214124
Change-Id: I0c211a48a945091bb572433ae607e96dff6d82f5
Fix: 271943047
diff --git a/rules/cc/BUILD.bazel b/rules/cc/BUILD.bazel
index 16c4e48..105f7bd 100644
--- a/rules/cc/BUILD.bazel
+++ b/rules/cc/BUILD.bazel
@@ -25,7 +25,6 @@
load(":cc_proto_test.bzl", "cc_proto_test_suite")
load(":cc_sysprop_library_test.bzl", "cc_gen_sysprop_test_suite")
load(":cc_prebuilt_binary_test.bzl", "cc_prebuilt_binary_test_suite")
-load(":cc_prebuilt_library_static_test.bzl", "cc_prebuilt_library_static_test_suite")
load(":clang_tidy_test.bzl", "clang_tidy_test_suite")
load(":flex_test.bzl", "flex_test_suite")
load(":stl_test.bzl", "stl_test_suite")
@@ -75,8 +74,6 @@
cc_prebuilt_binary_test_suite(name = "cc_prebuilt_binary_tests")
-cc_prebuilt_library_static_test_suite(name = "cc_prebuilt_library_static_tests")
-
cc_proto_test_suite(name = "cc_proto_tests")
clang_tidy_test_suite(name = "clang_tidy_tests")
diff --git a/rules/cc/cc_prebuilt_library_shared.bzl b/rules/cc/cc_prebuilt_library_shared.bzl
index 0ed5a02..35d4109 100644
--- a/rules/cc/cc_prebuilt_library_shared.bzl
+++ b/rules/cc/cc_prebuilt_library_shared.bzl
@@ -27,3 +27,10 @@
alwayslink = alwayslink,
**kwargs
)
+
+ native.cc_import(
+ name = name + "_alwayslink",
+ shared_library = shared_library,
+ alwayslink = True,
+ **kwargs
+ )
diff --git a/rules/cc/cc_prebuilt_library_static.bzl b/rules/cc/cc_prebuilt_library_static.bzl
index 9658b25..6204f5c 100644
--- a/rules/cc/cc_prebuilt_library_static.bzl
+++ b/rules/cc/cc_prebuilt_library_static.bzl
@@ -17,6 +17,7 @@
def cc_prebuilt_library_static(
name,
static_library,
+ alwayslink = None,
export_includes = [],
export_system_includes = [],
**kwargs):
@@ -27,5 +28,13 @@
native.cc_import(
name = name,
static_library = static_library,
+ alwayslink = alwayslink,
+ **kwargs
+ )
+
+ native.cc_import(
+ name = name + "_alwayslink",
+ static_library = static_library,
+ alwayslink = True,
**kwargs
)
diff --git a/rules/cc/cc_prebuilt_library_static_test.bzl b/rules/cc/cc_prebuilt_library_static_test.bzl
deleted file mode 100644
index 4962367..0000000
--- a/rules/cc/cc_prebuilt_library_static_test.bzl
+++ /dev/null
@@ -1,75 +0,0 @@
-"""
-Copyright (C) 2022 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.
-"""
-
-load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
-load("//build/bazel/rules/cc:cc_prebuilt_library_static.bzl", "cc_prebuilt_library_static")
-
-# NOTE: currently failing
-def _cc_prebuilt_library_static_alwayslink_test_impl(ctx):
- env = analysistest.begin(ctx)
- target = analysistest.target_under_test(env)
- expected_lib = ctx.attr.expected_lib
- cc_info = target[CcInfo]
- linker_inputs = cc_info.linking_context.linker_inputs.to_list()
- libs_to_link = []
- for l in linker_inputs:
- libs_to_link += l.libraries
-
- has_alwayslink = False
- libs = {}
- for lib_to_link in libs_to_link:
- lib = lib_to_link.static_library.basename
- libs[lib_to_link.static_library] = lib_to_link.alwayslink
- if lib == expected_lib:
- has_alwayslink = lib_to_link.alwayslink
- if has_alwayslink:
- break
- asserts.true(env, has_alwayslink, "\nExpected to find the static library `%s` unconditionally in the linker_input, with alwayslink set:\n\t%s" % (expected_lib, str(libs)))
-
- return analysistest.end(env)
-
-_cc_prebuilt_library_static_alwayslink_test = analysistest.make(
- _cc_prebuilt_library_static_alwayslink_test_impl,
- attrs = {"expected_lib": attr.string()},
-)
-
-def _cc_prebuilt_library_static_given_alwayslink_lib():
- name = "_cc_prebuilt_library_static_given_alwayslink_lib"
- test_name = name + "_test"
- lib = "libfoo.a"
-
- cc_prebuilt_library_static(
- name = name,
- static_library = lib,
- alwayslink = True,
- tags = ["manual"],
- )
-
- _cc_prebuilt_library_static_alwayslink_test(
- name = test_name,
- target_under_test = name,
- expected_lib = lib,
- )
-
- return test_name
-
-def cc_prebuilt_library_static_test_suite(name):
- native.test_suite(
- name = name,
- tests = [
- _cc_prebuilt_library_static_given_alwayslink_lib(),
- ],
- )