-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathobjc_library.bzl
More file actions
179 lines (159 loc) · 6.94 KB
/
Copy pathobjc_library.bzl
File metadata and controls
179 lines (159 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Copyright 2020 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.
"""objc_library Starlark implementation replacing native"""
load("//cc:build_settings.bzl", "cc")
load("//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
load("//cc/common:cc_common.bzl", "cc_common")
load("//cc/common:cc_helper.bzl", "cc_helper")
load("//cc/common:cc_info.bzl", "CcInfo")
load("//cc/common:semantics.bzl", cc_semantics = "semantics")
load(":objc_attrs.bzl", "common_attrs")
load(":objc_common.bzl", "extensions")
load(":objc_compilation_support.bzl", "compilation_support")
load(":objc_semantics.bzl", "semantics")
def _attribute_error(attr_name, msg):
fail("in attribute '" + attr_name + "': " + msg)
def _validate_attributes(srcs, non_arc_srcs, label):
cc_helper.check_file_extensions(
srcs,
extensions.SRCS,
"srcs",
label,
"objc_library",
False,
)
cc_helper.check_file_extensions(
non_arc_srcs,
extensions.NON_ARC_SRCS,
"non_arc_srcs",
label,
"objc_library",
False,
)
if label.name.find("/") != -1:
_attribute_error("name", "this attribute has unsupported character '/'")
def _objc_library_impl(ctx):
"""Implementation of objc_library."""
_validate_attributes(srcs = ctx.attr.srcs, non_arc_srcs = ctx.attr.non_arc_srcs, label = ctx.label)
cc_toolchain = find_cc_toolchain(ctx)
requested_features = ctx.features
unsupported_features = ctx.disabled_features
semantics.check_toolchain_supports_objc_compile(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = requested_features,
unsupported_features = unsupported_features,
)
common_variables = compilation_support.build_common_variables(
ctx = ctx,
toolchain = cc_toolchain,
use_pch = True,
deps = ctx.attr.deps,
implementation_deps = ctx.attr.implementation_deps,
attr_linkopts = ctx.attr.linkopts,
alwayslink = cc.target_should_alwayslink(ctx),
requested_features = requested_features,
unsupported_features = unsupported_features,
)
files = []
if common_variables.compilation_artifacts.archive != None:
files.append(common_variables.compilation_artifacts.archive)
compilation_result = compilation_support.register_compile_and_archive_actions(
common_variables,
)
(compilation_context, linking_context, compilation_outputs, output_groups) = compilation_result
compilation_support.validate_attributes(common_variables)
objc_provider = common_variables.objc_provider
if hasattr(compilation_outputs, "gcno_files"):
gcno_files = compilation_outputs.gcno_files()
else:
gcno_files = compilation_outputs._gcno_files
if hasattr(compilation_outputs, "pic_gcno_files"):
pic_gcno_files = compilation_outputs.pic_gcno_files()
else:
pic_gcno_files = compilation_outputs._pic_gcno_files
feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = requested_features,
unsupported_features = unsupported_features,
)
instrumented_files_info = coverage_common.instrumented_files_info(
ctx = ctx,
source_attributes = ["srcs", "non_arc_srcs", "hdrs"],
dependency_attributes = ["deps", "data", "binary", "xctest_app"],
extensions = extensions.NON_CPP_SOURCES + extensions.CPP_SOURCES + extensions.HEADERS,
coverage_environment = cc_helper.get_coverage_environment(ctx, ctx.fragments.cpp, cc_toolchain, feature_configuration),
# TODO(cmita): Use ctx.coverage_instrumented() instead when rules_swift can access
# cc_toolchain.coverage_files and the coverage_support_files parameter of
# coverage_common.instrumented_files_info(...)
coverage_support_files = cc_toolchain._coverage_files if ctx.configuration.coverage_enabled else depset([]),
metadata_files = gcno_files + pic_gcno_files,
)
runfiles_list = []
for data_dep in ctx.attr.data:
if data_dep[DefaultInfo].data_runfiles.files:
runfiles_list.append(data_dep[DefaultInfo].data_runfiles)
else:
# This branch ensures interop with custom Starlark rules following
# https://bazel.build/extending/rules#runfiles_features_to_avoid
runfiles_list.append(ctx.runfiles(transitive_files = data_dep[DefaultInfo].files))
runfiles_list.append(data_dep[DefaultInfo].default_runfiles)
for src in ctx.attr.srcs:
runfiles_list.append(src[DefaultInfo].default_runfiles)
for dep in ctx.attr.deps:
runfiles_list.append(dep[DefaultInfo].default_runfiles)
for dep in ctx.attr.implementation_deps:
runfiles_list.append(dep[DefaultInfo].default_runfiles)
runfiles = ctx.runfiles().merge_all(runfiles_list)
return [
DefaultInfo(
files = depset(files),
runfiles = runfiles,
),
CcInfo(
compilation_context = compilation_context,
linking_context = linking_context,
),
objc_provider,
instrumented_files_info,
OutputGroupInfo(**output_groups),
]
objc_library = rule(
implementation = _objc_library_impl,
initializer = common_attrs.alwayslink_initializer,
doc = """
<p>This rule produces a static library from the given Objective-C source files.</p>""",
attrs = common_attrs.union(
{
"data": attr.label_list(allow_files = True),
"implementation_deps": attr.label_list(providers = [CcInfo], allow_files = False, doc = """
The list of other libraries that the library target depends on. Unlike with
<code>deps</code>, the headers and include paths of these libraries (and all their
transitive deps) are only used for compilation of this library, and not libraries that
depend on it. Libraries specified with <code>implementation_deps</code> are still linked
in binary targets that depend on this library."""),
},
common_attrs.ALWAYSLINK_RULE,
common_attrs.COMPILING_RULE,
common_attrs.COMPILE_DEPENDENCY_RULE,
common_attrs.COPTS_RULE,
common_attrs.LICENSES,
common_attrs.SDK_FRAMEWORK_DEPENDER_RULE,
),
fragments = ["objc", "apple", "cpp"],
cfg = semantics.apple_crosstool_transition,
toolchains = use_cc_toolchain() + cc_semantics.get_runtimes_toolchain(),
provides = [CcInfo],
)