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> |
Devin Jeanpierre | b0af4dc | 2023-04-27 06:59:25 -0700 | [diff] [blame] | 9 | #include <type_traits> |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 10 | |
Lukasz Anforowicz | cec7a8a | 2022-04-27 10:24:51 -0700 | [diff] [blame] | 11 | #include "absl/container/flat_hash_map.h" |
Devin Jeanpierre | 6ed0f60 | 2023-03-01 17:22:54 -0800 | [diff] [blame] | 12 | #include "absl/container/flat_hash_set.h" |
Lukasz Anforowicz | cec7a8a | 2022-04-27 10:24:51 -0700 | [diff] [blame] | 13 | #include "absl/status/statusor.h" |
| 14 | #include "absl/strings/string_view.h" |
| 15 | #include "absl/types/span.h" |
Marcel Hlopko | 3b254b3 | 2022-03-09 14:10:49 +0000 | [diff] [blame] | 16 | #include "rs_bindings_from_cc/bazel_types.h" |
| 17 | #include "rs_bindings_from_cc/ir.h" |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 18 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 19 | namespace crubit { |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 20 | |
Marcel Hlopko | 20de6de | 2022-09-13 05:28:08 -0700 | [diff] [blame] | 21 | // Name of the namespace in which we generate code that triggers class template |
| 22 | // instantiations. |
| 23 | static constexpr absl::string_view kInstantiationsNamespaceName = |
| 24 | "__cc_template_instantiations"; |
| 25 | |
Devin Jeanpierre | b0af4dc | 2023-04-27 06:59:25 -0700 | [diff] [blame] | 26 | struct NonCopyable final { |
| 27 | NonCopyable() = default; |
| 28 | NonCopyable(const NonCopyable&) = delete; |
| 29 | }; |
| 30 | |
| 31 | struct IrFromCcOptions final { |
| 32 | absl::string_view extra_source_code_for_testing = ""; |
| 33 | BazelLabel current_target = BazelLabel{"//test:testing_target"}; |
| 34 | absl::Span<const HeaderName> public_headers = {}; |
| 35 | absl::flat_hash_map<const HeaderName, const std::string> |
| 36 | virtual_headers_contents_for_testing = {}; |
| 37 | absl::flat_hash_map<HeaderName, BazelLabel> headers_to_targets = {}; |
| 38 | absl::Span<const std::string> extra_rs_srcs = {}; |
| 39 | absl::Span<const absl::string_view> clang_args = {}; |
| 40 | absl::Span<const std::string> extra_instantiations = {}; |
| 41 | absl::flat_hash_map<BazelLabel, absl::flat_hash_set<std::string>> |
| 42 | crubit_features = {}; |
| 43 | |
| 44 | // Not an argument, just here to prevent the options struct from being |
| 45 | // copied/moved with nontrivial lifetime implications. |
| 46 | NonCopyable do_not_copy = {}; |
| 47 | }; |
| 48 | |
| 49 | static_assert(std::is_aggregate_v<IrFromCcOptions>); |
| 50 | |
Devin Jeanpierre | df4dc8b | 2021-10-21 12:53:19 +0000 | [diff] [blame] | 51 | // Parses C++ source code into IR. |
| 52 | // |
| 53 | // Parameters: |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 54 | // * `extra_source_code_for_testing`: C++ source code to be written into a |
| 55 | // virtual header and included in binding generation. Intended for testing |
| 56 | // only. |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 57 | // * `current_target`: full label of the target for which we generate bindings. |
| 58 | // If not specified `//test:testing_target` is used. |
| 59 | // * `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] | 60 | // `extra_source_code_for_testing` is specified its header will be added |
| 61 | // automatically. |
| 62 | // * `virtual_headers_contents_for_testing`: names and contents of virtual |
| 63 | // headers that will be created in the virtual filesystem. These headers have |
| 64 | // to be manually added to `public_headers` if needed. |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 65 | // * `headers_to_targets`: mapping of headers to the label of the owning target. |
| 66 | // If `extra_source_code` is specified it's added automatically under |
Lukasz Anforowicz | 121338a | 2022-11-01 14:28:32 -0700 | [diff] [blame] | 67 | // `//test:testing_target`. Headers from |
| 68 | // `virtual_headers_contents_for_testing` are not added automatically. |
| 69 | // * `clang_args`: additional command line arguments for Clang |
Devin Jeanpierre | 96bf0bd | 2022-10-04 20:32:15 -0700 | [diff] [blame] | 70 | // * `extra_rs_srcs`: A list of paths for additional rust files to include into |
Devin Jeanpierre | 6ed0f60 | 2023-03-01 17:22:54 -0800 | [diff] [blame] | 71 | // the crate. This is done via `#[path="..."] mod <...>; pub use <...>::*;`. |
Marcel Hlopko | 2ee2391 | 2022-05-09 06:13:55 -0700 | [diff] [blame] | 72 | // * `extra_instantiations`: names of full C++ class template specializations |
Devin Jeanpierre | 6ed0f60 | 2023-03-01 17:22:54 -0800 | [diff] [blame] | 73 | // to instantiate and generate bindings from. |
| 74 | // * `crubit_features`: The set of Crubit features to enable for each target. |
Devin Jeanpierre | df4dc8b | 2021-10-21 12:53:19 +0000 | [diff] [blame] | 75 | // |
Devin Jeanpierre | b0af4dc | 2023-04-27 06:59:25 -0700 | [diff] [blame] | 76 | absl::StatusOr<IR> IrFromCc(IrFromCcOptions options); |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 77 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 78 | } // namespace crubit |
Googler | 741ed9c | 2021-10-01 08:00:49 +0000 | [diff] [blame] | 79 | |
Dmitri Gribenko | e4e77d0 | 2022-03-17 14:09:39 +0000 | [diff] [blame] | 80 | #endif // CRUBIT_RS_BINDINGS_FROM_CC_IR_FROM_CC_H_ |