From 70877428a8d9f17834dee72f03ef80ce5c206e68 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 11 Dec 2020 14:57:50 +0100 Subject: Pass crate environment to proc macros --- crates/proc_macro_api/src/lib.rs | 4 +++- crates/proc_macro_api/src/rpc.rs | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/proc_macro_api') diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index a61afbbd6..2ea456fb0 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs @@ -16,7 +16,7 @@ use std::{ sync::Arc, }; -use base_db::ProcMacro; +use base_db::{Env, ProcMacro}; use tt::{SmolStr, Subtree}; use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; @@ -44,12 +44,14 @@ impl base_db::ProcMacroExpander for ProcMacroProcessExpander { &self, subtree: &Subtree, attr: Option<&Subtree>, + env: &Env, ) -> Result { let task = ExpansionTask { macro_body: subtree.clone(), macro_name: self.name.to_string(), attributes: attr.cloned(), lib: self.dylib_path.to_path_buf(), + env: env.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect(), }; let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?; diff --git a/crates/proc_macro_api/src/rpc.rs b/crates/proc_macro_api/src/rpc.rs index b85f92eea..cf830b59f 100644 --- a/crates/proc_macro_api/src/rpc.rs +++ b/crates/proc_macro_api/src/rpc.rs @@ -51,6 +51,9 @@ pub struct ExpansionTask { pub attributes: Option, pub lib: PathBuf, + + /// Environment variables to set during macro expansion. + pub env: Vec<(String, String)>, } #[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize)] @@ -251,6 +254,7 @@ mod tests { macro_name: Default::default(), attributes: None, lib: Default::default(), + env: Default::default(), }; let json = serde_json::to_string(&task).unwrap(); -- cgit v1.2.3