blob: 5de55383e0c19ca3f016cab360087240a56adff4 [file] [log] [blame]
# Part of the Crubit project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Utility module for sharing logic between rules and aspects that generate Rust bindings from C++.
Disclaimer: This project is experimental, under heavy development, and should
not be used yet.
"""
def compile_cc(
ctx,
attr,
cc_toolchain,
feature_configuration,
src,
cc_infos,
extra_cc_compilation_action_inputs):
"""Compiles a C++ source file.
Args:
ctx: The rule context.
attr: The current rule's attributes.
cc_toolchain: A cc_toolchain.
feature_configuration: A feature configuration.
src: The source file to be compiled.
cc_infos: List[CcInfo]: A list of CcInfo dependencies.
extra_cc_compilation_action_inputs: A list of input files for the C++ compilation action.
Returns:
A CcInfo provider.
"""
cc_info = cc_common.merge_cc_infos(cc_infos = cc_infos)
(compilation_context, compilation_outputs) = cc_common.compile(
name = src.basename,
actions = ctx.actions,
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
srcs = [src],
additional_inputs = extra_cc_compilation_action_inputs,
user_compile_flags = attr.copts if hasattr(attr, "copts") else [],
compilation_contexts = [cc_info.compilation_context],
)
(linking_context, _) = cc_common.create_linking_context_from_compilation_outputs(
name = src.basename,
actions = ctx.actions,
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
compilation_outputs = compilation_outputs,
linking_contexts = [cc_info.linking_context],
)
return CcInfo(
compilation_context = compilation_context,
linking_context = linking_context,
)