Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using serde_derive in a couple places in the compiler. #56447

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 7 additions & 7 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,6 @@ fn main() {
}
}

// Force all crates compiled by this compiler to (a) be unstable and (b)
// allow the `rustc_private` feature to link to other unstable crates
// also in the sysroot.
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}

if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
cmd.arg("--remap-path-prefix").arg(&map);
}
Expand All @@ -294,6 +287,13 @@ fn main() {
}
}

// Force all crates compiled by this compiler to (a) be unstable and (b)
// allow the `rustc_private` feature to link to other unstable crates
// also in the sysroot.
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}

if env::var_os("RUSTC_PARALLEL_QUERIES").is_some() {
cmd.arg("--cfg").arg("parallel_queries");
}
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand a bit on what's going on here? This feels like it shouldn't be necessary...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description tries to explain this. It's needed for the compiler to be able to find the (host-only) proc macro dependencies of e.g. librustc, from across a Cargo build (i.e. from codegen backends).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ok, I ask because I don't think that this is right. This I think is definitely not what we want when cross-compiling because it's mixing architectures of libraries in one directory. For non-cross-compiling situations this'll copy too much for things like build scripts and/or intermediate proc-macro dependencies.

Could we perhaps whitelist an explicit copy of serde_derive if necessary? Or something like that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if cargo would tell us if artifacts are proc macros, but I think a whitelist will suffice here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing architectures isn't a problem for rustc, and a whitelist feels hackier IMO.

I still like the idea of making the same -Ldependency= distinction Cargo makes, in the sysroot, as well (from #56447 (comment)).

In fact, we can even copy the host deps to rustlib/$host/deps instead of rustlib/$target/deps, and have the compiler look in the right place.


I should also mention I was able to work around this by adding a serde_derive dependency to librustc_codegen_llvm, but I feel like this also doesn't scale (and it builds serde_derive more than once).


I guess I'd accept the whitelisting if someone else implemented it, just to unblock @Zoxc.

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