Skip to content

Commit 9abcb5c

Browse files
committed
Make the crate work both in rustc and locally
1 parent 615f8c5 commit 9abcb5c

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

Cargo.toml

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
rustc_middle = { path = "../rustc_middle" }
8-
rustc_driver = { path = "../rustc_driver" }
9-
rustc_borrowck = { path = "../rustc_borrowck" }
10-
rustc_interface = { path = "../rustc_interface" }
7+
rustc_middle = { path = "../rustc_middle", optional = true }
8+
rustc_driver = { path = "../rustc_driver", optional = true }
9+
rustc_borrowck = { path = "../rustc_borrowck", optional = true }
10+
rustc_interface = { path = "../rustc_interface", optional = true }
11+
12+
[features]
13+
default = ["rustc_middle", "rustc_driver", "rustc_borrowck", "rustc_interface"]

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ sync is pushed entirely onto us, without affecting rustc workflows negatively.
77
This may change in the future, but changes to policy should only be done via a
88
compiler team MCP.
99

10+
## Instructions for working on this crate locally
11+
12+
Since the crate is the same in the rustc repo and here, the dependencies on rustc_* crates
13+
will only either work here or there, but never in both places at the same time. Thus we use
14+
optional dependencies on the rustc_* crates, requiring local development to use
15+
16+
```
17+
cargo build --no-default-features -Zavoid-dev-deps
18+
```
19+
20+
in order to compile successfully.
21+
1022
## Instructions for syncing
1123

1224
### Updating this repository

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
test(attr(allow(unused_variables), deny(warnings)))
1212
)]
1313

14+
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
15+
1416
pub mod mir;
1517

1618
pub mod very_unstable;

src/mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use rustc_middle::mir::{
1+
pub use crate::very_unstable::middle::mir::{
22
visit::MutVisitor, AggregateKind, AssertKind, BasicBlock, BasicBlockData, BinOp, BindingForm,
33
BlockTailInfo, Body, BorrowKind, CastKind, ClearCrossCrate, Constant, ConstantKind,
44
CopyNonOverlapping, Coverage, FakeReadCause, Field, GeneratorInfo, ImplicitSelfKind,

src/very_unstable.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
//! Only use rustc_smir in your dependencies and use the reexports here instead of
44
//! directly referring to the unstable crates.
55
6-
pub use rustc_borrowck as borrowck;
7-
pub use rustc_driver as driver;
8-
pub use rustc_hir as hir;
9-
pub use rustc_interface as interface;
10-
pub use rustc_middle as middle;
11-
pub use rustc_mir_dataflow as dataflow;
12-
pub use rustc_mir_transform as transform;
13-
pub use rustc_serialize as serialize;
14-
pub use rustc_trait_selection as trait_selection;
6+
macro_rules! crates {
7+
($($rustc_name:ident -> $name:ident,)*) => {
8+
$(
9+
#[cfg(not(feature = "default"))]
10+
pub extern crate $rustc_name as $name;
11+
#[cfg(feature = "default")]
12+
pub use $rustc_name as $name;
13+
)*
14+
}
15+
}
16+
17+
crates! {
18+
rustc_borrowck -> borrowck,
19+
rustc_driver -> driver,
20+
rustc_hir -> hir,
21+
rustc_interface -> interface,
22+
rustc_middle -> middle,
23+
rustc_mir_dataflow -> dataflow,
24+
rustc_mir_transform -> transform,
25+
rustc_serialize -> serialize,
26+
rustc_trait_selection -> trait_selection,
27+
}

0 commit comments

Comments
 (0)