Skip to content

Commit d48ab69

Browse files
committedNov 30, 2018
Auto merge of #49219 - eddyb:proc-macro-decouple, r=alexcrichton
Decouple proc_macro from the rest of the compiler. This PR removes all dependencies of `proc_macro` on compiler crates and allows multiple copies of `proc_macro`, built even by different compilers (but from the same source), to interoperate. Practically, it allows: * running proc macro tests at stage1 (I moved most from `-fulldeps` to the regular suites) * using proc macros in the compiler itself (may require some rustbuild trickery) On the server (i.e. compiler front-end) side: * `server::*` traits are implemented to provide the concrete types and methods * the concrete types are completely separated from the `proc_macro` public API * the only use of the type implementing `Server` is to be passed to `Client::run` On the client (i.e. proc macro) side (potentially using a different `proc_macro` instance!): * `client::Client` wraps around client-side (expansion) function pointers * it encapsulates the `proc_macro` instance used by the client * its `run` method can be called by a server, to execute the client-side function * the client instance is bridged to the provided server, while it runs * ~~currently a thread is spawned, could use process isolation in the future~~ (not the case anymore, see #56058) * proc macro crates get a generated `static` holding a `&[ProcMacro]` * this describes all derives/attr/bang proc macros, replacing the "registrar" function * each variant of `ProcMacro` contains an appropriately typed `Client<fn(...) -> ...>` `proc_macro` public APIs call into the server via an internal "bridge": * only a currently running proc macro `Client` can interact with those APIs * server code might not be able to (if it uses a different `proc_macro` instance) * however, it can always create and `run` its own `Client`, but that may be inefficient * the `bridge` uses serialization, C ABI and integer handles to avoid Rust ABI instability * each invocation of a proc macro results in disjoint integers in its `proc_macro` handles * this prevents using values of those types across invocations (if they even can be kept) r? @alexcrichton cc @jseyfried @nikomatsakis @Zoxc @thepowersgang
2 parents 3e90a12 + 3a04d44 commit d48ab69

File tree

287 files changed

+3327
-1168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

287 files changed

+3327
-1168
lines changed
 

‎Cargo.lock

+1-9
Original file line numberDiff line numberDiff line change
@@ -1599,12 +1599,6 @@ dependencies = [
15991599
[[package]]
16001600
name = "proc_macro"
16011601
version = "0.0.0"
1602-
dependencies = [
1603-
"rustc_data_structures 0.0.0",
1604-
"rustc_errors 0.0.0",
1605-
"syntax 0.0.0",
1606-
"syntax_pos 0.0.0",
1607-
]
16081602

16091603
[[package]]
16101604
name = "profiler_builtins"
@@ -1933,7 +1927,6 @@ dependencies = [
19331927
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
19341928
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
19351929
"polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
1936-
"proc_macro 0.0.0",
19371930
"rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
19381931
"rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
19391932
"rustc_apfloat 0.0.0",
@@ -2351,7 +2344,6 @@ dependencies = [
23512344
"flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
23522345
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
23532346
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
2354-
"proc_macro 0.0.0",
23552347
"rustc 0.0.0",
23562348
"rustc_data_structures 0.0.0",
23572349
"rustc_errors 0.0.0",
@@ -2890,7 +2882,6 @@ version = "0.0.0"
28902882
dependencies = [
28912883
"fmt_macros 0.0.0",
28922884
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
2893-
"proc_macro 0.0.0",
28942885
"rustc_data_structures 0.0.0",
28952886
"rustc_errors 0.0.0",
28962887
"rustc_target 0.0.0",
@@ -2980,6 +2971,7 @@ name = "test"
29802971
version = "0.0.0"
29812972
dependencies = [
29822973
"getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
2974+
"proc_macro 0.0.0",
29832975
"term 0.0.0",
29842976
]
29852977

‎src/bootstrap/bin/rustc.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ fn main() {
129129
// Help the libc crate compile by assisting it in finding the MUSL
130130
// native libraries.
131131
if let Some(s) = env::var_os("MUSL_ROOT") {
132-
let mut root = OsString::from("native=");
133-
root.push(&s);
134-
root.push("/lib");
135-
cmd.arg("-L").arg(&root);
132+
if target.contains("musl") {
133+
let mut root = OsString::from("native=");
134+
root.push(&s);
135+
root.push("/lib");
136+
cmd.arg("-L").arg(&root);
137+
}
136138
}
137139

138140
// Override linker if necessary.

0 commit comments

Comments
 (0)