Skip to content

Commit

Permalink
Auto merge of #56447 - eddyb:serde-poc, r=<try>
Browse files Browse the repository at this point in the history
Start using serde_derive in a couple places in the compiler.

Note that this doesn't actually use `serde` for anything currently - I have a different branch where I started that, but I thought I'd extract this proof of concept out, to deal with build system issues.

The second commit is needed to fix this error in `rustc_codegen_llvm` and `rustdoc`:
```
error[E0463]: can't find crate for `serde_derive` which `rustc` depends on
```
This problem arises because we use different Cargo build dirs for codegen backends and `rustdoc` from the main `rustc` Cargo build dir, and without the second commit in this PR, the host `deps` (including `serde_derive`) weren't copied over to the common sysroot (shared between all builds).

*Quite surprisingly*, everything else seems to "just work"!
This is in part because of pre-existing logic in `rustbuild` to only use `stage0` for build scripts when building libstd itself, which *happens to* be what we need to make proc macros work in all stages 🎉

cc @alexcrichton @Mark-Simulacrum @Zoxc @nikomatsakis
  • Loading branch information
bors committed Dec 2, 2018
2 parents 21f2684 + 7b22fcb commit d934074
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,7 @@ version = "0.0.0"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

Expand Down Expand Up @@ -2288,6 +2289,8 @@ dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_cratesio_shim 0.0.0",
"rustc_data_structures 0.0.0",
"serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"syntax_pos 0.0.0",
"termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -2901,6 +2904,8 @@ dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_data_structures 0.0.0",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
Expand Down
8 changes: 1 addition & 7 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,15 +1064,9 @@ pub fn run_cargo(builder: &Builder,

let filename = Path::new(&*filename);

// If this was an output file in the "host dir" we don't actually
// worry about it, it's not relevant for us.
if filename.starts_with(&host_root_dir) {
continue;
}

// If this was output in the `deps` dir then this is a precise file
// name (hash included) so we start tracking it.
if filename.starts_with(&target_deps_dir) {
if filename.starts_with(&host_root_dir) || filename.starts_with(&target_deps_dir) {
deps.push(filename.to_path_buf());
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_cratesio_shim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ crate-type = ["dylib"]
[dependencies]
bitflags = "1.0"
log = "0.4"
serde = "1.0"
unicode-width = "0.1.4"
1 change: 1 addition & 0 deletions src/librustc_cratesio_shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
extern crate bitflags;
extern crate log;
extern crate proc_macro;
extern crate serde;
extern crate unicode_width;
2 changes: 2 additions & 0 deletions src/librustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ serialize = { path = "../libserialize" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
serde = "1.0"
serde_derive = "1.0"
unicode-width = "0.1.4"
atty = "0.2"
termcolor = "1.0"
8 changes: 7 additions & 1 deletion src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ extern crate libc;
#[macro_use]
extern crate log;
extern crate rustc_data_structures;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serialize as rustc_serialize;
extern crate syntax_pos;
extern crate unicode_width;
Expand Down Expand Up @@ -66,7 +69,10 @@ use syntax_pos::{BytePos,
Span,
NO_EXPANSION};

#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
#[derive(Copy, Clone, Debug, PartialEq, Hash,
RustcDecodable, RustcEncodable,
Serialize, Deserialize,
)]
pub enum Applicability {
MachineApplicable,
HasPlaceholders,
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax_pos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ serialize = { path = "../libserialize" }
rustc_data_structures = { path = "../librustc_data_structures" }
arena = { path = "../libarena" }
scoped-tls = { version = "0.1.1", features = ["nightly"] }
serde = "1.0"
serde_derive = "1.0"
unicode-width = "0.1.4"
cfg-if = "0.1.2"
8 changes: 7 additions & 1 deletion src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ extern crate rustc_data_structures;

#[macro_use]
extern crate scoped_tls;
#[macro_use]
extern crate serde_derive;
extern crate serde;

use serialize::{Encodable, Decodable, Encoder, Decoder};

Expand Down Expand Up @@ -84,7 +87,10 @@ impl Globals {
scoped_thread_local!(pub static GLOBALS: Globals);

/// Differentiates between real files and common virtual files
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)]
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash,
RustcDecodable, RustcEncodable,
Serialize, Deserialize,
)]
pub enum FileName {
Real(PathBuf),
/// A macro. This includes the full name of the macro, so that there are no clashes.
Expand Down
6 changes: 6 additions & 0 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ const WHITELIST: &[Crate] = &[
Crate("parking_lot_core"),
Crate("pkg-config"),
Crate("polonius-engine"),
Crate("proc-macro2"),
Crate("quick-error"),
Crate("quote"),
Crate("rand"),
Crate("rand_core"),
Crate("redox_syscall"),
Expand All @@ -121,15 +123,19 @@ const WHITELIST: &[Crate] = &[
Crate("rustc-rayon-core"),
Crate("scoped-tls"),
Crate("scopeguard"),
Crate("serde"),
Crate("serde_derive"),
Crate("smallvec"),
Crate("stable_deref_trait"),
Crate("syn"),
Crate("tempfile"),
Crate("termcolor"),
Crate("terminon"),
Crate("termion"),
Crate("thread_local"),
Crate("ucd-util"),
Crate("unicode-width"),
Crate("unicode-xid"),
Crate("unreachable"),
Crate("utf8-ranges"),
Crate("version_check"),
Expand Down

0 comments on commit d934074

Please sign in to comment.