about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-06-02 09:55:54 +0000
committerOli Scherer <github35764891676564198441@oli-obk.de>2022-06-02 12:06:34 +0200
commit9abcb5c7b574cf316eb23d3f469187bb86ba3019 (patch)
tree8156ef820b283c9bcc567a37cce77e4db2a66f36
parent615f8c5dbbd59b9ec734efaeb36b0e619c9e3e38 (diff)
downloadrust-9abcb5c7b574cf316eb23d3f469187bb86ba3019.tar.gz
rust-9abcb5c7b574cf316eb23d3f469187bb86ba3019.zip
Make the crate work both in rustc and locally
-rw-r--r--.gitignore1
-rw-r--r--Cargo.toml11
-rw-r--r--README.md12
-rw-r--r--src/lib.rs2
-rw-r--r--src/mir.rs2
-rw-r--r--src/very_unstable.rs31
6 files changed, 45 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000000..eb5a316cbd1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/Cargo.toml b/Cargo.toml
index 0c5a19d4034..bc0cac5a0bc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,7 +4,10 @@ version = "0.0.0"
 edition = "2021"
 
 [dependencies]
-rustc_middle = { path = "../rustc_middle" }
-rustc_driver = { path = "../rustc_driver" }
-rustc_borrowck = { path = "../rustc_borrowck" }
-rustc_interface = { path = "../rustc_interface" }
+rustc_middle = { path = "../rustc_middle", optional = true }
+rustc_driver = { path = "../rustc_driver", optional = true }
+rustc_borrowck = { path = "../rustc_borrowck", optional = true }
+rustc_interface = { path = "../rustc_interface", optional = true }
+
+[features]
+default = ["rustc_middle", "rustc_driver", "rustc_borrowck", "rustc_interface"]
diff --git a/README.md b/README.md
index 92eb926f505..ae49098dd0c 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,18 @@ sync is pushed entirely onto us, without affecting rustc workflows negatively.
 This may change in the future, but changes to policy should only be done via a
 compiler team MCP.
 
+## Instructions for working on this crate locally
+
+Since the crate is the same in the rustc repo and here, the dependencies on rustc_* crates
+will only either work here or there, but never in both places at the same time. Thus we use
+optional dependencies on the rustc_* crates, requiring local development to use
+
+```
+cargo build --no-default-features -Zavoid-dev-deps
+```
+
+in order to compile successfully.
+
 ## Instructions for syncing
 
 ### Updating this repository
diff --git a/src/lib.rs b/src/lib.rs
index 2b1c2bb3d2b..decdae953d9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,6 +11,8 @@
     test(attr(allow(unused_variables), deny(warnings)))
 )]
 
+#![cfg_attr(not(feature = "default"), feature(rustc_private))]
+
 pub mod mir;
 
 pub mod very_unstable;
diff --git a/src/mir.rs b/src/mir.rs
index 97969be669d..855605b1a4f 100644
--- a/src/mir.rs
+++ b/src/mir.rs
@@ -1,4 +1,4 @@
-pub use rustc_middle::mir::{
+pub use crate::very_unstable::middle::mir::{
     visit::MutVisitor, AggregateKind, AssertKind, BasicBlock, BasicBlockData, BinOp, BindingForm,
     BlockTailInfo, Body, BorrowKind, CastKind, ClearCrossCrate, Constant, ConstantKind,
     CopyNonOverlapping, Coverage, FakeReadCause, Field, GeneratorInfo, ImplicitSelfKind,
diff --git a/src/very_unstable.rs b/src/very_unstable.rs
index dacdabf1ccb..12ba133dbb1 100644
--- a/src/very_unstable.rs
+++ b/src/very_unstable.rs
@@ -3,12 +3,25 @@
 //! Only use rustc_smir in your dependencies and use the reexports here instead of
 //! directly referring to the unstable crates.
 
-pub use rustc_borrowck as borrowck;
-pub use rustc_driver as driver;
-pub use rustc_hir as hir;
-pub use rustc_interface as interface;
-pub use rustc_middle as middle;
-pub use rustc_mir_dataflow as dataflow;
-pub use rustc_mir_transform as transform;
-pub use rustc_serialize as serialize;
-pub use rustc_trait_selection as trait_selection;
+macro_rules! crates {
+    ($($rustc_name:ident -> $name:ident,)*) => {
+        $(
+            #[cfg(not(feature = "default"))]
+            pub extern crate $rustc_name as $name;
+            #[cfg(feature = "default")]
+            pub use $rustc_name as $name;
+        )*
+    }
+}
+
+crates! {
+    rustc_borrowck -> borrowck,
+    rustc_driver -> driver,
+    rustc_hir -> hir,
+    rustc_interface -> interface,
+    rustc_middle -> middle,
+    rustc_mir_dataflow -> dataflow,
+    rustc_mir_transform -> transform,
+    rustc_serialize -> serialize,
+    rustc_trait_selection -> trait_selection,
+}