From d3b7a0783e3e3fdde6b331d1492abe2dc0475df6 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 21 Jan 2021 16:24:01 +0100 Subject: [PATCH] macros: Only depend on serde when it's actually used --- sqlx-macros/Cargo.toml | 8 ++++---- sqlx-macros/src/query/mod.rs | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sqlx-macros/Cargo.toml b/sqlx-macros/Cargo.toml index bf3b8494..679b5179 100644 --- a/sqlx-macros/Cargo.toml +++ b/sqlx-macros/Cargo.toml @@ -34,7 +34,7 @@ _rt-async-std = [] _rt-tokio = [] # offline building support -offline = ["sqlx-core/offline", "hex", "once_cell", "sha2"] +offline = ["sqlx-core/offline", "hex", "once_cell", "serde", "serde_json", "sha2"] # database mysql = [ "sqlx-core/mysql" ] @@ -50,7 +50,7 @@ time = [ "sqlx-core/time" ] ipnetwork = [ "sqlx-core/ipnetwork" ] uuid = [ "sqlx-core/uuid" ] bit-vec = [ "sqlx-core/bit-vec" ] -json = [ "sqlx-core/json" ] +json = [ "sqlx-core/json", "serde_json" ] [dependencies] dotenv = { version = "0.15.0", default-features = false } @@ -62,8 +62,8 @@ once_cell = { version = "1.5.2", optional = true } proc-macro2 = { version = "1.0.9", default-features = false } sqlx-core = { version = "0.4.2", default-features = false, path = "../sqlx-core" } sqlx-rt = { version = "0.2.0", default-features = false, path = "../sqlx-rt" } -serde = { version = "1.0.111", features = ["derive"] } -serde_json = { version = "1.0.30", features = [ "preserve_order" ] } +serde = { version = "1.0.111", features = ["derive"], optional = true } +serde_json = { version = "1.0.30", features = ["preserve_order"], optional = true } sha2 = { version = "0.9.1", optional = true } syn = { version = "1.0.30", default-features = false, features = [ "full" ] } quote = { version = "1.0.6", default-features = false } diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index 770f157b..68170ddd 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -1,9 +1,9 @@ use std::env; -use std::path::{Path, PathBuf}; -use std::process::Command; +use std::path::Path; +#[cfg(feature = "offline")] +use std::path::PathBuf; use proc_macro2::TokenStream; -use serde::Deserialize; use syn::Type; use url::Url; @@ -28,6 +28,9 @@ mod output; // reflect the workspace dir: https://github.com/rust-lang/cargo/issues/3946 #[cfg(feature = "offline")] static CRATE_ROOT: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { + use serde::Deserialize; + use std::process::Command; + let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` must be set"); let cargo = env::var_os("CARGO").expect("`CARGO` must be set");