blob: 1e7796ee9e518f0c3e3e597b242b1aa2854f1c01 [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
#ifndef CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_
#define CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_
#include <string>
#include <type_traits>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "rs_bindings_from_cc/bazel_types.h"
#include "rs_bindings_from_cc/ir.h"
namespace crubit {
// Name of the namespace in which we generate code that triggers class template
// instantiations.
static constexpr absl::string_view kInstantiationsNamespaceName =
"__cc_template_instantiations";
struct NonCopyable final {
NonCopyable() = default;
NonCopyable(const NonCopyable&) = delete;
};
struct IrFromCcOptions final {
absl::string_view extra_source_code_for_testing = "";
BazelLabel current_target = BazelLabel{"//test:testing_target"};
absl::Span<const HeaderName> public_headers = {};
absl::flat_hash_map<HeaderName, std::string>
virtual_headers_contents_for_testing = {};
absl::flat_hash_map<HeaderName, BazelLabel> headers_to_targets = {};
absl::Span<const std::string> extra_rs_srcs = {};
absl::Span<const absl::string_view> clang_args = {};
absl::Span<const std::string> extra_instantiations = {};
absl::flat_hash_map<BazelLabel, absl::flat_hash_set<std::string>>
crubit_features = {};
// Not an argument, just here to prevent the options struct from being
// copied/moved with nontrivial lifetime implications.
NonCopyable do_not_copy = {};
};
static_assert(std::is_aggregate_v<IrFromCcOptions>);
// Parses C++ source code into IR.
//
// Parameters:
// * `extra_source_code_for_testing`: C++ source code to be written into a
// virtual header and included in binding generation. Intended for testing
// only.
// * `current_target`: full label of the target for which we generate bindings.
// If not specified `//test:testing_target` is used.
// * `public_headers`: names of headers from which we build the Clang AST. If
// `extra_source_code_for_testing` is specified its header will be added
// automatically.
// * `virtual_headers_contents_for_testing`: names and contents of virtual
// headers that will be created in the virtual filesystem. These headers have
// to be manually added to `public_headers` if needed.
// * `headers_to_targets`: mapping of headers to the label of the owning target.
// If `extra_source_code` is specified it's added automatically under
// `//test:testing_target`. Headers from
// `virtual_headers_contents_for_testing` are not added automatically.
// * `clang_args`: additional command line arguments for Clang
// * `extra_rs_srcs`: A list of paths for additional rust files to include into
// the crate. This is done via `#[path="..."] mod <...>; pub use <...>::*;`.
// * `extra_instantiations`: names of full C++ class template specializations
// to instantiate and generate bindings from.
// * `crubit_features`: The set of Crubit features to enable for each target.
//
absl::StatusOr<IR> IrFromCc(IrFromCcOptions options);
} // namespace crubit
#endif // CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_