Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 1 | // 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 Gribenko | e4e77d0 | 2022-03-17 14:09:39 +0000 | [diff] [blame] | 5 | #ifndef CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_ |
| 6 | #define CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_ |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 7 | |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Lukasz Anforowicz | cec7a8a | 2022-04-27 10:24:51 -0700 | [diff] [blame] | 10 | #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 Hlopko | 3b254b3 | 2022-03-09 14:10:49 +0000 | [diff] [blame] | 14 | #include "rs_bindings_from_cc/bazel_types.h" |
| 15 | #include "rs_bindings_from_cc/ir.h" |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 16 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 17 | namespace crubit { |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 18 | |
Marcel Hlopko | 20de6de | 2022-09-13 05:28:08 -0700 | [diff] [blame] | 19 | // Name of the namespace in which we generate code that triggers class template |
| 20 | // instantiations. |
| 21 | static constexpr absl::string_view kInstantiationsNamespaceName = |
| 22 | "__cc_template_instantiations"; |
| 23 | |
Devin Jeanpierre | df4dc8b | 2021-10-21 12:53:19 +0000 | [diff] [blame] | 24 | // Parses C++ source code into IR. |
| 25 | // |
| 26 | // Parameters: |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 27 | // * `extra_source_code_for_testing`: C++ source code to be written into a |
| 28 | // virtual header and included in binding generation. Intended for testing |
| 29 | // only. |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 30 | // * `current_target`: full label of the target for which we generate bindings. |
| 31 | // If not specified `//test:testing_target` is used. |
| 32 | // * `public_headers`: names of headers from which we build the Clang AST. If |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 33 | // `extra_source_code_for_testing` is specified its header will be added |
| 34 | // automatically. |
| 35 | // * `virtual_headers_contents_for_testing`: names and contents of virtual |
| 36 | // headers that will be created in the virtual filesystem. These headers have |
| 37 | // to be manually added to `public_headers` if needed. |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 38 | // * `headers_to_targets`: mapping of headers to the label of the owning target. |
| 39 | // If `extra_source_code` is specified it's added automatically under |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 40 | // `//test:testing_target`. Headers from |
| 41 | // `virtual_headers_contents_for_testing` are not added automatically. |
| 42 | // * `clang_args`: additional command line arguments for Clang |
Devin Jeanpierre | 96bf0bd | 2022-10-04 20:32:15 -0700 | [diff] [blame] | 43 | // * `extra_rs_srcs`: A list of paths for additional rust files to include into |
| 44 | // the crate. This is done via `#[path="..."] mod <...>; pub use <...>::*;`. |
Marcel Hlopko | 2ee2391 | 2022-05-09 06:13:55 -0700 | [diff] [blame] | 45 | // * `extra_instantiations`: names of full C++ class template specializations |
| 46 | // to instantiate and generate bindings from. |
Devin Jeanpierre | df4dc8b | 2021-10-21 12:53:19 +0000 | [diff] [blame] | 47 | // |
Michael Forster | 3f323be | 2021-10-11 07:13:28 +0000 | [diff] [blame] | 48 | absl::StatusOr<IR> IrFromCc( |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 49 | absl::string_view extra_source_code_for_testing, |
Googler | 6c3de12 | 2022-03-28 11:40:41 +0000 | [diff] [blame] | 50 | BazelLabel current_target = BazelLabel{"//test:testing_target"}, |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 51 | absl::Span<const HeaderName> public_headers = {}, |
| 52 | absl::flat_hash_map<const HeaderName, const std::string> |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 53 | virtual_headers_contents_for_testing = {}, |
Googler | 6c3de12 | 2022-03-28 11:40:41 +0000 | [diff] [blame] | 54 | absl::flat_hash_map<const HeaderName, const BazelLabel> headers_to_targets = |
Googler | e05154d | 2022-01-10 08:39:03 +0000 | [diff] [blame] | 55 | {}, |
Devin Jeanpierre | 96bf0bd | 2022-10-04 20:32:15 -0700 | [diff] [blame] | 56 | absl::Span<const std::string> extra_rs_srcs = {}, |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 57 | absl::Span<const absl::string_view> clang_args = {}, |
Marcel Hlopko | 2ee2391 | 2022-05-09 06:13:55 -0700 | [diff] [blame] | 58 | absl::Span<const std::string> extra_instantiations = {}); |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 59 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 60 | } // namespace crubit |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 61 | |
Dmitri Gribenko | e4e77d0 | 2022-03-17 14:09:39 +0000 | [diff] [blame] | 62 | #endif // CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_ |