[python] Remove semicolon after `PyObject_HEAD` (#16123)
[google-protobuf.git] / bazel / private / upb_proto_library_internal / cc_library_func.bzl
blob4753d18413754180660514f52547fe86033df4de
1 """A function to compile C/C++ code, like cc_library() but from Starlark."""
3 load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
5 def upb_use_cpp_toolchain():
6     return use_cpp_toolchain()
8 def cc_library_func(ctx, name, hdrs, srcs, copts, dep_ccinfos, includes = []):
9     """Like cc_library(), but callable from rules.
11     Args:
12       ctx: Rule context.
13       name: Unique name used to generate output files.
14       hdrs: Public headers that can be #included from other rules.
15       srcs: C/C++ source files.
16       copts: Additional options for cc compilation.
17       dep_ccinfos: CcInfo providers of dependencies we should build/link against.
18       includes: Additional include paths.
20     Returns:
21       CcInfo provider for this compilation.
22     """
24     compilation_contexts = [info.compilation_context for info in dep_ccinfos]
25     linking_contexts = [info.linking_context for info in dep_ccinfos]
26     toolchain = find_cpp_toolchain(ctx)
27     feature_configuration = cc_common.configure_features(
28         ctx = ctx,
29         cc_toolchain = toolchain,
30         requested_features = ctx.features,
31         unsupported_features = ctx.disabled_features,
32     )
34     (compilation_context, compilation_outputs) = cc_common.compile(
35         actions = ctx.actions,
36         feature_configuration = feature_configuration,
37         cc_toolchain = toolchain,
38         name = name,
39         srcs = srcs,
40         includes = includes,
41         public_hdrs = hdrs,
42         user_compile_flags = copts,
43         compilation_contexts = compilation_contexts,
44     )
46     # buildifier: disable=unused-variable
47     (linking_context, linking_outputs) = cc_common.create_linking_context_from_compilation_outputs(
48         actions = ctx.actions,
49         name = name,
50         feature_configuration = feature_configuration,
51         cc_toolchain = toolchain,
52         compilation_outputs = compilation_outputs,
53         linking_contexts = linking_contexts,
54         disallow_dynamic_library = cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "targets_windows") or not cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "supports_dynamic_linker"),
55     )
57     return CcInfo(
58         compilation_context = compilation_context,
59         linking_context = linking_context,
60     )