From eee0f51e0c3ea2d52269741124b68b8dac0e051c Mon Sep 17 00:00:00 2001 From: Dmitry Rodionov Date: Mon, 28 Mar 2022 11:39:15 +0300 Subject: [PATCH] use cargo-hakari to manage workspace_hack crate workspace_hack is needed to avoid recompilation when different crates inside the workspace depend on the same packages but with different features being enabled. Problem occurs when you build crates separately one by one. So this is irrelevant to our CI setup because there we build all binaries at once, but it may be relevant for local development. this also changes cargo's resolver version to 2 --- .config/hakari.toml | 24 ++++++++++++++++ Cargo.lock | 15 ++++++++++ Cargo.toml | 1 + compute_tools/Cargo.toml | 1 + control_plane/Cargo.toml | 2 +- docs/sourcetree.md | 2 ++ pageserver/Cargo.toml | 2 +- postgres_ffi/Cargo.toml | 2 +- proxy/Cargo.toml | 1 + walkeeper/Cargo.toml | 2 +- workspace_hack/Cargo.toml | 60 ++++++++++++++++++++++++++++----------- workspace_hack/src/lib.rs | 24 +--------------- zenith/Cargo.toml | 2 +- zenith_metrics/Cargo.toml | 1 + zenith_utils/Cargo.toml | 2 +- 15 files changed, 96 insertions(+), 45 deletions(-) create mode 100644 .config/hakari.toml diff --git a/.config/hakari.toml b/.config/hakari.toml new file mode 100644 index 0000000000..7bccc6c4a3 --- /dev/null +++ b/.config/hakari.toml @@ -0,0 +1,24 @@ +# This file contains settings for `cargo hakari`. +# See https://docs.rs/cargo-hakari/latest/cargo_hakari/config for a full list of options. + +hakari-package = "workspace_hack" + +# Format for `workspace-hack = ...` lines in other Cargo.tomls. Requires cargo-hakari 0.9.8 or above. +dep-format-version = "2" + +# Setting workspace.resolver = "2" in the root Cargo.toml is HIGHLY recommended. +# Hakari works much better with the new feature resolver. +# For more about the new feature resolver, see: +# https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver +resolver = "2" + +# Add triples corresponding to platforms commonly used by developers here. +# https://doc.rust-lang.org/rustc/platform-support.html +platforms = [ + # "x86_64-unknown-linux-gnu", + # "x86_64-apple-darwin", + # "x86_64-pc-windows-msvc", +] + +# Write out exact versions rather than a semver range. (Defaults to false.) +# exact-versions = true diff --git a/Cargo.lock b/Cargo.lock index 290d715f2c..40f4358d98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,6 +407,7 @@ dependencies = [ "serde_json", "tar", "tokio", + "workspace_hack", ] [[package]] @@ -1803,6 +1804,7 @@ dependencies = [ "tokio-postgres 0.7.1 (git+https://github.com/zenithdb/rust-postgres.git?rev=2949d98df52587d562986aad155dd4e889e408b7)", "tokio-postgres-rustls", "tokio-rustls 0.22.0", + "workspace_hack", "zenith_metrics", "zenith_utils", ] @@ -3041,7 +3043,14 @@ dependencies = [ name = "workspace_hack" version = "0.1.0" dependencies = [ + "anyhow", + "bytes", + "cc", + "clap 2.34.0", + "either", + "hashbrown 0.11.2", "libc", + "log", "memchr", "num-integer", "num-traits", @@ -3049,8 +3058,13 @@ dependencies = [ "quote", "regex", "regex-syntax", + "reqwest", + "scopeguard", "serde", "syn", + "tokio", + "tracing", + "tracing-core", ] [[package]] @@ -3101,6 +3115,7 @@ dependencies = [ "libc", "once_cell", "prometheus", + "workspace_hack", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b20e64a06f..f3ac36dcb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "zenith_metrics", "zenith_utils", ] +resolver = "2" [profile.release] # This is useful for profiling and, to some extent, debug. diff --git a/compute_tools/Cargo.toml b/compute_tools/Cargo.toml index 3adf762dcb..4ecf7f6499 100644 --- a/compute_tools/Cargo.toml +++ b/compute_tools/Cargo.toml @@ -17,3 +17,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1" tar = "0.4" tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] } +workspace_hack = { version = "0.1", path = "../workspace_hack" } diff --git a/control_plane/Cargo.toml b/control_plane/Cargo.toml index b52c7ad5a9..e118ea4793 100644 --- a/control_plane/Cargo.toml +++ b/control_plane/Cargo.toml @@ -20,4 +20,4 @@ reqwest = { version = "0.11", default-features = false, features = ["blocking", pageserver = { path = "../pageserver" } walkeeper = { path = "../walkeeper" } zenith_utils = { path = "../zenith_utils" } -workspace_hack = { path = "../workspace_hack" } +workspace_hack = { version = "0.1", path = "../workspace_hack" } diff --git a/docs/sourcetree.md b/docs/sourcetree.md index 8d35d35f2f..89b07de8d2 100644 --- a/docs/sourcetree.md +++ b/docs/sourcetree.md @@ -67,6 +67,8 @@ For more detailed info, see `/walkeeper/README` `/workspace_hack`: The workspace_hack crate exists only to pin down some dependencies. +We use [cargo-hakari](https://crates.io/crates/cargo-hakari) for automation. + `/zenith` Main entry point for the 'zenith' CLI utility. diff --git a/pageserver/Cargo.toml b/pageserver/Cargo.toml index de22d0dd77..14eae31da8 100644 --- a/pageserver/Cargo.toml +++ b/pageserver/Cargo.toml @@ -51,7 +51,7 @@ async-compression = {version = "0.3", features = ["zstd", "tokio"]} postgres_ffi = { path = "../postgres_ffi" } zenith_metrics = { path = "../zenith_metrics" } zenith_utils = { path = "../zenith_utils" } -workspace_hack = { path = "../workspace_hack" } +workspace_hack = { version = "0.1", path = "../workspace_hack" } [dev-dependencies] hex-literal = "0.3" diff --git a/postgres_ffi/Cargo.toml b/postgres_ffi/Cargo.toml index 17f1ecd666..e8d471cb12 100644 --- a/postgres_ffi/Cargo.toml +++ b/postgres_ffi/Cargo.toml @@ -17,8 +17,8 @@ log = "0.4.14" memoffset = "0.6.2" thiserror = "1.0" serde = { version = "1.0", features = ["derive"] } -workspace_hack = { path = "../workspace_hack" } zenith_utils = { path = "../zenith_utils" } +workspace_hack = { version = "0.1", path = "../workspace_hack" } [build-dependencies] bindgen = "0.59.1" diff --git a/proxy/Cargo.toml b/proxy/Cargo.toml index dda018a1d8..72c394dad4 100644 --- a/proxy/Cargo.toml +++ b/proxy/Cargo.toml @@ -29,6 +29,7 @@ tokio-rustls = "0.22.0" zenith_utils = { path = "../zenith_utils" } zenith_metrics = { path = "../zenith_metrics" } +workspace_hack = { version = "0.1", path = "../workspace_hack" } [dev-dependencies] tokio-postgres-rustls = "0.8.0" diff --git a/walkeeper/Cargo.toml b/walkeeper/Cargo.toml index 193fc4acf6..f59c24816d 100644 --- a/walkeeper/Cargo.toml +++ b/walkeeper/Cargo.toml @@ -29,9 +29,9 @@ const_format = "0.2.21" tokio-postgres = { git = "https://github.com/zenithdb/rust-postgres.git", rev="2949d98df52587d562986aad155dd4e889e408b7" } postgres_ffi = { path = "../postgres_ffi" } -workspace_hack = { path = "../workspace_hack" } zenith_metrics = { path = "../zenith_metrics" } zenith_utils = { path = "../zenith_utils" } +workspace_hack = { version = "0.1", path = "../workspace_hack" } [dev-dependencies] tempfile = "3.2" diff --git a/workspace_hack/Cargo.toml b/workspace_hack/Cargo.toml index 48d81bbc07..6e6a0e09d7 100644 --- a/workspace_hack/Cargo.toml +++ b/workspace_hack/Cargo.toml @@ -1,22 +1,50 @@ +# This file is generated by `cargo hakari`. +# To regenerate, run: +# cargo hakari generate + [package] name = "workspace_hack" version = "0.1.0" -edition = "2021" +description = "workspace-hack package, managed by hakari" +# You can choose to publish this crate: see https://docs.rs/cargo-hakari/latest/cargo_hakari/publishing. +publish = false -[target.'cfg(all())'.dependencies] -libc = { version = "0.2", features = ["default", "extra_traits", "std"] } -memchr = { version = "2", features = ["default", "std", "use_std"] } +# The parts of the file between the BEGIN HAKARI SECTION and END HAKARI SECTION comments +# are managed by hakari. + +### BEGIN HAKARI SECTION +[dependencies] +anyhow = { version = "1", features = ["backtrace", "std"] } +bytes = { version = "1", features = ["serde", "std"] } +clap = { version = "2", features = ["ansi_term", "atty", "color", "strsim", "suggestions", "vec_map"] } +either = { version = "1", features = ["use_std"] } +hashbrown = { version = "0.11", features = ["ahash", "inline-more", "raw"] } +libc = { version = "0.2", features = ["extra_traits", "std"] } +log = { version = "0.4", default-features = false, features = ["serde", "std"] } +memchr = { version = "2", features = ["std", "use_std"] } num-integer = { version = "0.1", default-features = false, features = ["std"] } -num-traits = { version = "0.2", default-features = false, features = ["std"] } -regex = { version = "1", features = ["aho-corasick", "default", "memchr", "perf", "perf-cache", "perf-dfa", "perf-inline", "perf-literal", "std", "unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } -regex-syntax = { version = "0.6", features = ["default", "unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } -serde = { version = "1", features = ["default", "derive", "serde_derive", "std"] } +num-traits = { version = "0.2", features = ["std"] } +regex = { version = "1", features = ["aho-corasick", "memchr", "perf", "perf-cache", "perf-dfa", "perf-inline", "perf-literal", "std", "unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } +regex-syntax = { version = "0.6", features = ["unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } +reqwest = { version = "0.11", default-features = false, features = ["__rustls", "__tls", "blocking", "hyper-rustls", "json", "rustls", "rustls-pemfile", "rustls-tls", "rustls-tls-webpki-roots", "serde_json", "stream", "tokio-rustls", "tokio-util", "webpki-roots"] } +scopeguard = { version = "1", features = ["use_std"] } +serde = { version = "1", features = ["alloc", "derive", "serde_derive", "std"] } +tokio = { version = "1", features = ["bytes", "fs", "io-util", "libc", "macros", "memchr", "mio", "net", "num_cpus", "once_cell", "process", "rt", "rt-multi-thread", "signal-hook-registry", "sync", "time", "tokio-macros"] } +tracing = { version = "0.1", features = ["attributes", "std", "tracing-attributes"] } +tracing-core = { version = "0.1", features = ["lazy_static", "std"] } -[target.'cfg(all())'.build-dependencies] -libc = { version = "0.2", features = ["default", "extra_traits", "std"] } -memchr = { version = "2", features = ["default", "std", "use_std"] } -proc-macro2 = { version = "1", features = ["default", "proc-macro"] } -quote = { version = "1", features = ["default", "proc-macro"] } -regex = { version = "1", features = ["aho-corasick", "default", "memchr", "perf", "perf-cache", "perf-dfa", "perf-inline", "perf-literal", "std", "unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } -regex-syntax = { version = "0.6", features = ["default", "unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } -syn = { version = "1", features = ["clone-impls", "default", "derive", "full", "parsing", "printing", "proc-macro", "quote", "visit", "visit-mut"] } +[build-dependencies] +cc = { version = "1", default-features = false, features = ["jobserver", "parallel"] } +clap = { version = "2", features = ["ansi_term", "atty", "color", "strsim", "suggestions", "vec_map"] } +either = { version = "1", features = ["use_std"] } +libc = { version = "0.2", features = ["extra_traits", "std"] } +log = { version = "0.4", default-features = false, features = ["serde", "std"] } +memchr = { version = "2", features = ["std", "use_std"] } +proc-macro2 = { version = "1", features = ["proc-macro"] } +quote = { version = "1", features = ["proc-macro"] } +regex = { version = "1", features = ["aho-corasick", "memchr", "perf", "perf-cache", "perf-dfa", "perf-inline", "perf-literal", "std", "unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } +regex-syntax = { version = "0.6", features = ["unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"] } +serde = { version = "1", features = ["alloc", "derive", "serde_derive", "std"] } +syn = { version = "1", features = ["clone-impls", "derive", "extra-traits", "full", "parsing", "printing", "proc-macro", "quote", "visit", "visit-mut"] } + +### END HAKARI SECTION diff --git a/workspace_hack/src/lib.rs b/workspace_hack/src/lib.rs index ceba3d145d..22489f632b 100644 --- a/workspace_hack/src/lib.rs +++ b/workspace_hack/src/lib.rs @@ -1,23 +1 @@ -//! This crate contains no code. -//! -//! The workspace_hack crate exists only to pin down some dependencies, -//! so that those dependencies always build with the same features, -//! under a few different cases that can be problematic: -//! - Running `cargo check` or `cargo build` from a crate sub-directory -//! instead of the workspace root. -//! - Running `cargo install`, which can only be done per-crate -//! -//! The dependency lists in Cargo.toml were automatically generated by -//! a tool called -//! [Hakari](https://github.com/facebookincubator/cargo-guppy/tree/main/tools/hakari). -//! -//! Hakari doesn't have a CLI yet; in the meantime the example code in -//! their `README` file is enough to regenerate the dependencies. -//! Hakari's output was pasted into Cargo.toml, except for the -//! following manual edits: -//! - `winapi` dependency was removed. This is probably just due to the -//! fact that Hakari's target analysis is incomplete. -//! -//! There isn't any penalty to this data falling out of date; it just -//! means that under the conditions above Cargo will rebuild more -//! packages than strictly necessary. +// This is a stub lib.rs. diff --git a/zenith/Cargo.toml b/zenith/Cargo.toml index 8adbda0723..74aeffb51c 100644 --- a/zenith/Cargo.toml +++ b/zenith/Cargo.toml @@ -15,4 +15,4 @@ control_plane = { path = "../control_plane" } walkeeper = { path = "../walkeeper" } postgres_ffi = { path = "../postgres_ffi" } zenith_utils = { path = "../zenith_utils" } -workspace_hack = { path = "../workspace_hack" } +workspace_hack = { version = "0.1", path = "../workspace_hack" } diff --git a/zenith_metrics/Cargo.toml b/zenith_metrics/Cargo.toml index 0c921ede0b..906c5a1d64 100644 --- a/zenith_metrics/Cargo.toml +++ b/zenith_metrics/Cargo.toml @@ -8,3 +8,4 @@ prometheus = {version = "0.13", default_features=false} # removes protobuf depen libc = "0.2" lazy_static = "1.4" once_cell = "1.8.0" +workspace_hack = { version = "0.1", path = "../workspace_hack" } diff --git a/zenith_utils/Cargo.toml b/zenith_utils/Cargo.toml index 8e7f5f233c..e8ad0e627f 100644 --- a/zenith_utils/Cargo.toml +++ b/zenith_utils/Cargo.toml @@ -30,7 +30,7 @@ git-version = "0.3.5" serde_with = "1.12.0" zenith_metrics = { path = "../zenith_metrics" } -workspace_hack = { path = "../workspace_hack" } +workspace_hack = { version = "0.1", path = "../workspace_hack" } [dev-dependencies] byteorder = "1.4.3"