Skip to content

Commit 13877ca

Browse files
eddybZoxc
authored andcommitted
Start using serde_derive in a couple places in the compiler.
1 parent f722699 commit 13877ca

File tree

13 files changed

+104
-30
lines changed

13 files changed

+104
-30
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,7 @@ version = "0.0.0"
25402540
dependencies = [
25412541
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
25422542
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
2543+
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
25432544
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
25442545
]
25452546

@@ -2604,6 +2605,7 @@ dependencies = [
26042605
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
26052606
"rustc_cratesio_shim 0.0.0",
26062607
"rustc_data_structures 0.0.0",
2608+
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
26072609
"serialize 0.0.0",
26082610
"syntax_pos 0.0.0",
26092611
"termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3217,6 +3219,7 @@ dependencies = [
32173219
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
32183220
"rustc_data_structures 0.0.0",
32193221
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
3222+
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
32203223
"serialize 0.0.0",
32213224
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
32223225
]

src/bootstrap/bin/rustc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ fn main() {
109109
// actually downloaded, so we just always pass the `--sysroot` option.
110110
cmd.arg("--sysroot").arg(&sysroot);
111111

112+
// Link crates to the proc macro crate for the target, but use a host proc macro crate
113+
// to actually run the macros
114+
if env::var_os("RUST_DUAL_PROC_MACROS").is_some() {
115+
cmd.arg("-Zdual-proc-macros");
116+
}
117+
112118
// When we build Rust dylibs they're all intended for intermediate
113119
// usage, so make sure we pass the -Cprefer-dynamic flag instead of
114120
// linking all deps statically into the dylib.

src/bootstrap/builder.rs

+7
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ impl<'a> Builder<'a> {
608608
.join(self.target)
609609
.join("lib");
610610
let _ = fs::remove_dir_all(&sysroot);
611+
eprintln!("creating sysroot {:?}", sysroot);
611612
t!(fs::create_dir_all(&sysroot));
612613
INTERNER.intern_path(sysroot)
613614
}
@@ -811,6 +812,12 @@ impl<'a> Builder<'a> {
811812
cargo.env("RUST_CHECK", "1");
812813
}
813814

815+
// Build proc macros both for the host and the target
816+
if target != compiler.host && cmd != "check" {
817+
cargo.arg("-Zdual-proc-macros");
818+
cargo.env("RUST_DUAL_PROC_MACROS", "1");
819+
}
820+
814821
cargo.arg("-j").arg(self.jobs().to_string());
815822
// Remove make-related flags to ensure Cargo can correctly set things up
816823
cargo.env_remove("MAKEFLAGS");

src/bootstrap/check.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ impl Step for Std {
4242
true);
4343

4444
let libdir = builder.sysroot_libdir(compiler, target);
45-
add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target));
45+
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
46+
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
4647
}
4748
}
4849

@@ -88,7 +89,8 @@ impl Step for Rustc {
8889
true);
8990

9091
let libdir = builder.sysroot_libdir(compiler, target);
91-
add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target));
92+
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
93+
add_to_sysroot(&builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
9294
}
9395
}
9496

@@ -175,7 +177,8 @@ impl Step for Test {
175177
true);
176178

177179
let libdir = builder.sysroot_libdir(compiler, target);
178-
add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
180+
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
181+
add_to_sysroot(builder, &libdir, &hostdir, &libtest_stamp(builder, compiler, target));
179182
}
180183
}
181184

@@ -222,7 +225,8 @@ impl Step for Rustdoc {
222225
true);
223226

224227
let libdir = builder.sysroot_libdir(compiler, target);
225-
add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
228+
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
229+
add_to_sysroot(&builder, &libdir, &hostdir, &rustdoc_stamp(builder, compiler, target));
226230
builder.cargo(compiler, Mode::ToolRustc, target, "clean");
227231
}
228232
}

src/bootstrap/compile.rs

+57-19
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ impl Step for StdLink {
224224
target_compiler.host,
225225
target));
226226
let libdir = builder.sysroot_libdir(target_compiler, target);
227-
add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target));
227+
let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
228+
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
228229

229230
if builder.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
230231
// The sanitizers are only built in stage1 or above, so the dylibs will
@@ -426,8 +427,12 @@ impl Step for TestLink {
426427
&compiler.host,
427428
target_compiler.host,
428429
target));
429-
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
430-
&libtest_stamp(builder, compiler, target));
430+
add_to_sysroot(
431+
builder,
432+
&builder.sysroot_libdir(target_compiler, target),
433+
&builder.sysroot_libdir(target_compiler, compiler.host),
434+
&libtest_stamp(builder, compiler, target)
435+
);
431436

432437
builder.cargo(target_compiler, Mode::ToolTest, target, "clean");
433438
}
@@ -491,8 +496,8 @@ impl Step for Rustc {
491496
return;
492497
}
493498

494-
// Ensure that build scripts have a std to link against.
495-
builder.ensure(Std {
499+
// Ensure that build scripts and proc macros have a std / libproc_macro to link against.
500+
builder.ensure(Test {
496501
compiler: builder.compiler(self.compiler.stage, builder.config.build),
497502
target: builder.config.build,
498503
});
@@ -587,8 +592,12 @@ impl Step for RustcLink {
587592
&compiler.host,
588593
target_compiler.host,
589594
target));
590-
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
591-
&librustc_stamp(builder, compiler, target));
595+
add_to_sysroot(
596+
builder,
597+
&builder.sysroot_libdir(target_compiler, target),
598+
&builder.sysroot_libdir(target_compiler, compiler.host),
599+
&librustc_stamp(builder, compiler, target)
600+
);
592601
builder.cargo(target_compiler, Mode::ToolRustc, target, "clean");
593602
}
594603
}
@@ -996,10 +1005,22 @@ impl Step for Assemble {
9961005
///
9971006
/// For a particular stage this will link the file listed in `stamp` into the
9981007
/// `sysroot_dst` provided.
999-
pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) {
1008+
pub fn add_to_sysroot(
1009+
builder: &Builder,
1010+
sysroot_dst: &Path,
1011+
sysroot_host_dst: &Path,
1012+
stamp: &Path
1013+
) {
1014+
//eprintln!("add_to_sysroot - host dir {:?} - stamp {:?}", sysroot_host_dst, stamp);
10001015
t!(fs::create_dir_all(&sysroot_dst));
1001-
for path in builder.read_stamp_file(stamp) {
1002-
builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
1016+
t!(fs::create_dir_all(&sysroot_host_dst));
1017+
for (path, host) in builder.read_stamp_file(stamp) {
1018+
if host {
1019+
eprintln!("add_to_sysroot host - copying {:?} to {:?}", path, sysroot_host_dst);
1020+
builder.copy(&path, &sysroot_host_dst.join(path.file_name().unwrap()));
1021+
} else {
1022+
builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
1023+
}
10031024
}
10041025
}
10051026

@@ -1028,8 +1049,14 @@ pub fn run_cargo(builder: &Builder,
10281049
let mut deps = Vec::new();
10291050
let mut toplevel = Vec::new();
10301051
let ok = stream_cargo(builder, cargo, &mut |msg| {
1031-
let filenames = match msg {
1032-
CargoMessage::CompilerArtifact { filenames, .. } => filenames,
1052+
let (filenames, crate_types) = match msg {
1053+
CargoMessage::CompilerArtifact {
1054+
filenames,
1055+
target: CargoTarget {
1056+
crate_types,
1057+
},
1058+
..
1059+
} => (filenames, crate_types),
10331060
_ => return,
10341061
};
10351062
for filename in filenames {
@@ -1044,15 +1071,19 @@ pub fn run_cargo(builder: &Builder,
10441071
let filename = Path::new(&*filename);
10451072

10461073
// If this was an output file in the "host dir" we don't actually
1047-
// worry about it, it's not relevant for us.
1074+
// worry about it, it's not relevant for us
10481075
if filename.starts_with(&host_root_dir) {
1076+
// Unless it's a proc macro used in the compiler
1077+
if crate_types.iter().any(|t| t == "proc-macro") {
1078+
deps.push((filename.to_path_buf(), true));
1079+
}
10491080
continue;
10501081
}
10511082

10521083
// If this was output in the `deps` dir then this is a precise file
10531084
// name (hash included) so we start tracking it.
10541085
if filename.starts_with(&target_deps_dir) {
1055-
deps.push(filename.to_path_buf());
1086+
deps.push((filename.to_path_buf(), false));
10561087
continue;
10571088
}
10581089

@@ -1105,10 +1136,10 @@ pub fn run_cargo(builder: &Builder,
11051136
let candidate = format!("{}.lib", path_to_add);
11061137
let candidate = PathBuf::from(candidate);
11071138
if candidate.exists() {
1108-
deps.push(candidate);
1139+
deps.push((candidate, false));
11091140
}
11101141
}
1111-
deps.push(path_to_add.into());
1142+
deps.push((path_to_add.into(), false));
11121143
}
11131144

11141145
// Now we want to update the contents of the stamp file, if necessary. First
@@ -1121,12 +1152,13 @@ pub fn run_cargo(builder: &Builder,
11211152
let mut new_contents = Vec::new();
11221153
let mut max = None;
11231154
let mut max_path = None;
1124-
for dep in deps.iter() {
1155+
for (dep, proc_macro) in deps.iter() {
11251156
let mtime = mtime(dep);
11261157
if Some(mtime) > max {
11271158
max = Some(mtime);
11281159
max_path = Some(dep.clone());
11291160
}
1161+
new_contents.extend(if *proc_macro { b"h" } else { b"t" });
11301162
new_contents.extend(dep.to_str().unwrap().as_bytes());
11311163
new_contents.extend(b"\0");
11321164
}
@@ -1138,15 +1170,15 @@ pub fn run_cargo(builder: &Builder,
11381170
if contents_equal && max <= stamp_mtime {
11391171
builder.verbose(&format!("not updating {:?}; contents equal and {:?} <= {:?}",
11401172
stamp, max, stamp_mtime));
1141-
return deps
1173+
return deps.into_iter().map(|(d, _)| d).collect()
11421174
}
11431175
if max > stamp_mtime {
11441176
builder.verbose(&format!("updating {:?} as {:?} changed", stamp, max_path));
11451177
} else {
11461178
builder.verbose(&format!("updating {:?} as deps changed", stamp));
11471179
}
11481180
t!(fs::write(&stamp, &new_contents));
1149-
deps
1181+
deps.into_iter().map(|(d, _)| d).collect()
11501182
}
11511183

11521184
pub fn stream_cargo(
@@ -1192,13 +1224,19 @@ pub fn stream_cargo(
11921224
status.success()
11931225
}
11941226

1227+
#[derive(Deserialize)]
1228+
pub struct CargoTarget<'a> {
1229+
crate_types: Vec<Cow<'a, str>>,
1230+
}
1231+
11951232
#[derive(Deserialize)]
11961233
#[serde(tag = "reason", rename_all = "kebab-case")]
11971234
pub enum CargoMessage<'a> {
11981235
CompilerArtifact {
11991236
package_id: Cow<'a, str>,
12001237
features: Vec<Cow<'a, str>>,
12011238
filenames: Vec<Cow<'a, str>>,
1239+
target: CargoTarget<'a>,
12021240
},
12031241
BuildScriptExecuted {
12041242
package_id: Cow<'a, str>,

src/bootstrap/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
//! also check out the `src/bootstrap/README.md` file for more information.
105105
106106
#![deny(bare_trait_objects)]
107-
#![deny(warnings)]
107+
//#![deny(warnings)]
108108
#![feature(core_intrinsics)]
109109
#![feature(drain_filter)]
110110

@@ -1142,7 +1142,7 @@ impl Build {
11421142
ret
11431143
}
11441144

1145-
fn read_stamp_file(&self, stamp: &Path) -> Vec<PathBuf> {
1145+
fn read_stamp_file(&self, stamp: &Path) -> Vec<(PathBuf, bool)> {
11461146
if self.config.dry_run {
11471147
return Vec::new();
11481148
}
@@ -1155,8 +1155,9 @@ impl Build {
11551155
if part.is_empty() {
11561156
continue
11571157
}
1158-
let path = PathBuf::from(t!(str::from_utf8(part)));
1159-
paths.push(path);
1158+
let host = part[0] as char == 'h';
1159+
let path = PathBuf::from(t!(str::from_utf8(&part[1..])));
1160+
paths.push((path, host));
11601161
}
11611162
paths
11621163
}

src/bootstrap/tool.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ impl Step for ToolBuild {
9292
compile::CargoMessage::CompilerArtifact {
9393
package_id,
9494
features,
95-
filenames
95+
filenames,
96+
target: _,
9697
} => {
9798
(package_id, features, filenames)
9899
}

src/librustc_cratesio_shim/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ crate-type = ["dylib"]
2222
[dependencies]
2323
bitflags = "1.0"
2424
log = "0.4"
25+
serde = { version = "1.0", features = ["serde_derive"] }
2526
unicode-width = "0.1.4"

src/librustc_cratesio_shim/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
extern crate bitflags;
77
extern crate log;
88
extern crate proc_macro;
9+
extern crate serde;
910
extern crate unicode_width;

src/librustc_errors/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ serialize = { path = "../libserialize" }
1414
syntax_pos = { path = "../libsyntax_pos" }
1515
rustc_data_structures = { path = "../librustc_data_structures" }
1616
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
17+
serde = { version = "1.0", features = ["serde_derive"] }
1718
unicode-width = "0.1.4"
1819
atty = "0.2"
1920
termcolor = "1.0"

src/librustc_errors/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern crate libc;
1616
#[macro_use]
1717
extern crate log;
1818
extern crate rustc_data_structures;
19+
extern crate serde;
1920
extern crate serialize as rustc_serialize;
2021
extern crate syntax_pos;
2122
extern crate unicode_width;
@@ -35,6 +36,8 @@ use std::cell::Cell;
3536
use std::{error, fmt};
3637
use std::panic;
3738

39+
use serde::{Serialize, Deserialize};
40+
3841
use termcolor::{ColorSpec, Color};
3942

4043
mod diagnostic;
@@ -59,7 +62,8 @@ use syntax_pos::{BytePos,
5962
/// All suggestions are marked with an `Applicability`. Tools use the applicability of a suggestion
6063
/// to determine whether it should be automatically applied or if the user should be consulted
6164
/// before applying the suggestion.
62-
#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
65+
#[derive(Copy, Clone, Debug, PartialEq, Hash,
66+
RustcEncodable, RustcDecodable, Serialize, Deserialize)]
6367
pub enum Applicability {
6468
/// The suggestion is definitely what the user intended. This suggestion should be
6569
/// automatically applied.

src/libsyntax_pos/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ serialize = { path = "../libserialize" }
1313
rustc_data_structures = { path = "../librustc_data_structures" }
1414
arena = { path = "../libarena" }
1515
scoped-tls = { version = "0.1.1", features = ["nightly"] }
16+
serde = { version = "1.0", features = ["serde_derive"] }
1617
unicode-width = "0.1.4"
1718
cfg-if = "0.1.2"

0 commit comments

Comments
 (0)