Finally, move `bindings` to a separate crate.
PiperOrigin-RevId: 572036945
Change-Id: I1d4af80e6b45a1b038d4e22ce46605969b6fe213
diff --git a/cc_bindings_from_rs/BUILD b/cc_bindings_from_rs/BUILD
index bfa9cea..7ccdd32 100644
--- a/cc_bindings_from_rs/BUILD
+++ b/cc_bindings_from_rs/BUILD
@@ -12,14 +12,42 @@
package(default_applicable_licenses = ["//:license"])
+rust_library(
+ name = "bindings",
+ srcs = ["bindings.rs"],
+ deps = [
+ ":run_compiler",
+ ":toposort",
+ "//common:code_gen_utils",
+ "//common:token_stream_printer",
+ "@crate_index//:anyhow",
+ "@crate_index//:itertools",
+ "@crate_index//:once_cell",
+ "@crate_index//:proc-macro2",
+ "@crate_index//:quote",
+ "@crate_index//:syn",
+ "@rules_rust//tools/runfiles",
+ ],
+)
+
+crubit_rust_test(
+ name = "bindings_test",
+ crate = ":bindings",
+ tags = [
+ "not_build:arm",
+ "noubsan", # rustc-as-a-library isn't supported for UBSan.
+ ],
+ deps = [
+ ":run_compiler_test_support",
+ "//common:token_stream_matchers",
+ "@crate_index//:itertools",
+ "@crate_index//:tempfile",
+ ],
+)
+
crubit_rust_binary(
name = "cc_bindings_from_rs",
- srcs = [
- # TODO(b/254679226): These should be separate crates.
- "bindings.rs",
- "cc_bindings_from_rs.rs",
- ],
- crate_root = "cc_bindings_from_rs.rs",
+ srcs = ["cc_bindings_from_rs.rs"],
# TODO(b/242703401): Remove once cc_common.link works for rustc libraries.
tags = [
"not_build:arm",
@@ -29,20 +57,14 @@
"//visibility:public",
],
deps = [
+ ":bindings",
":cmdline",
":run_compiler",
- ":toposort",
"//common:code_gen_utils",
"//common:token_stream_printer",
"@crate_index//:anyhow",
"@crate_index//:clap",
- "@crate_index//:either",
"@crate_index//:itertools",
- "@crate_index//:once_cell",
- "@crate_index//:proc-macro2",
- "@crate_index//:quote",
- "@crate_index//:syn",
- "@rules_rust//tools/runfiles",
],
)
@@ -55,7 +77,6 @@
],
deps = [
":run_compiler_test_support",
- "//common:token_stream_matchers",
"@crate_index//:regex",
"@crate_index//:tempfile",
],
diff --git a/cc_bindings_from_rs/bindings.rs b/cc_bindings_from_rs/bindings.rs
index 4ac214c..d6b6663 100644
--- a/cc_bindings_from_rs/bindings.rs
+++ b/cc_bindings_from_rs/bindings.rs
@@ -1,6 +1,17 @@
// 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
+#![feature(rustc_private)]
+#![deny(rustc::internal)]
+
+extern crate rustc_attr;
+extern crate rustc_hir;
+extern crate rustc_infer;
+extern crate rustc_middle;
+extern crate rustc_span;
+extern crate rustc_target;
+extern crate rustc_trait_selection;
+extern crate rustc_type_ir;
use anyhow::{anyhow, bail, ensure, Context, Result};
use code_gen_utils::{
diff --git a/cc_bindings_from_rs/cc_bindings_from_rs.rs b/cc_bindings_from_rs/cc_bindings_from_rs.rs
index b914670..a476e99 100644
--- a/cc_bindings_from_rs/cc_bindings_from_rs.rs
+++ b/cc_bindings_from_rs/cc_bindings_from_rs.rs
@@ -6,24 +6,7 @@
#![feature(rustc_private)]
#![deny(rustc::internal)]
-extern crate rustc_attr;
-extern crate rustc_driver;
-extern crate rustc_error_codes;
-extern crate rustc_errors;
-extern crate rustc_feature;
-extern crate rustc_hir;
-extern crate rustc_infer;
-extern crate rustc_interface;
-extern crate rustc_lint_defs;
extern crate rustc_middle;
-extern crate rustc_session;
-extern crate rustc_span;
-extern crate rustc_target;
-extern crate rustc_trait_selection;
-extern crate rustc_type_ir;
-
-// TODO(b/254679226): these should be separate crates.
-mod bindings;
use anyhow::Context;
use itertools::Itertools;