blob: 2759af3f9508d27db736285ff0101f96e35c8ae7 [file] [log] [blame]
Googler741ed9c2021-10-01 08:00:49 +00001// Part of the Crubit project, under the Apache License v2.0 with LLVM
2// Exceptions. See /LICENSE for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
Dmitri Gribenkoe4e77d02022-03-17 14:09:39 +00005#ifndef CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_
6#define CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_
Googler741ed9c2021-10-01 08:00:49 +00007
Marcel Hlopko7aa38a72021-11-11 07:39:51 +00008#include <string>
9
Lukasz Anforowiczcec7a8a2022-04-27 10:24:51 -070010#include "absl/container/flat_hash_map.h"
11#include "absl/status/statusor.h"
12#include "absl/strings/string_view.h"
13#include "absl/types/span.h"
Marcel Hlopko3b254b32022-03-09 14:10:49 +000014#include "rs_bindings_from_cc/bazel_types.h"
15#include "rs_bindings_from_cc/ir.h"
Googler741ed9c2021-10-01 08:00:49 +000016
Marcel Hlopkof15e8ce2022-04-08 08:46:09 -070017namespace crubit {
Googler741ed9c2021-10-01 08:00:49 +000018
Marcel Hlopko20de6de2022-09-13 05:28:08 -070019// Name of the namespace in which we generate code that triggers class template
20// instantiations.
21static constexpr absl::string_view kInstantiationsNamespaceName =
22 "__cc_template_instantiations";
23
Devin Jeanpierredf4dc8b2021-10-21 12:53:19 +000024// Parses C++ source code into IR.
25//
26// Parameters:
Marcel Hlopko7aa38a72021-11-11 07:39:51 +000027// * `extra_source_code`: C++ source code to be written into a virtual header
28// and included in binding generation. Intended for testing only.
29// * `current_target`: full label of the target for which we generate bindings.
30// If not specified `//test:testing_target` is used.
31// * `public_headers`: names of headers from which we build the Clang AST. If
32// `extra_source_code` is specified its header will be added automatically.
33// * `virtual_headers_contents`: names and contents of virtual headers that
34// will be created in the virtual filesystem. These headers have to be
35// manually added to `public_headers` if needed.
36// * `headers_to_targets`: mapping of headers to the label of the owning target.
37// If `extra_source_code` is specified it's added automatically under
38// `//test:testing_target`. Headers from `virtual_headers_contents` are not
39// added automatically.
Devin Jeanpierredf4dc8b2021-10-21 12:53:19 +000040// * `args`: additional command line arguments for Clang
Devin Jeanpierre96bf0bd2022-10-04 20:32:15 -070041// * `extra_rs_srcs`: A list of paths for additional rust files to include into
42// the crate. This is done via `#[path="..."] mod <...>; pub use <...>::*;`.
Marcel Hlopko2ee23912022-05-09 06:13:55 -070043// * `extra_instantiations`: names of full C++ class template specializations
44// to instantiate and generate bindings from.
Devin Jeanpierredf4dc8b2021-10-21 12:53:19 +000045//
Michael Forster3f323be2021-10-11 07:13:28 +000046absl::StatusOr<IR> IrFromCc(
Marcel Hlopko7aa38a72021-11-11 07:39:51 +000047 absl::string_view extra_source_code,
Googler6c3de122022-03-28 11:40:41 +000048 BazelLabel current_target = BazelLabel{"//test:testing_target"},
Marcel Hlopko7aa38a72021-11-11 07:39:51 +000049 absl::Span<const HeaderName> public_headers = {},
50 absl::flat_hash_map<const HeaderName, const std::string>
51 virtual_headers_contents = {},
Googler6c3de122022-03-28 11:40:41 +000052 absl::flat_hash_map<const HeaderName, const BazelLabel> headers_to_targets =
Googlere05154d2022-01-10 08:39:03 +000053 {},
Devin Jeanpierre96bf0bd2022-10-04 20:32:15 -070054 absl::Span<const std::string> extra_rs_srcs = {},
Marcel Hlopko2ee23912022-05-09 06:13:55 -070055 absl::Span<const absl::string_view> args = {},
56 absl::Span<const std::string> extra_instantiations = {});
Googler741ed9c2021-10-01 08:00:49 +000057
Marcel Hlopkof15e8ce2022-04-08 08:46:09 -070058} // namespace crubit
Googler741ed9c2021-10-01 08:00:49 +000059
Dmitri Gribenkoe4e77d02022-03-17 14:09:39 +000060#endif // CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_