Set current working directory for procedural macros

This commit is contained in:
vlad20012 2022-01-27 15:54:06 +03:00
parent e149a15edd
commit 6051318744
No known key found for this signature in database
GPG key ID: 58E62ED31A8B3999
3 changed files with 28 additions and 0 deletions

View file

@ -156,12 +156,18 @@ impl ProcMacro {
attr: Option<&Subtree>,
env: Vec<(String, String)>,
) -> Result<Result<Subtree, PanicMessage>, ServerError> {
let current_dir = env
.iter()
.find(|(name, _)| name == "CARGO_MANIFEST_DIR")
.map(|(_, value)| value.clone());
let task = ExpandMacro {
macro_body: FlatTree::new(subtree),
macro_name: self.name.to_string(),
attributes: attr.map(FlatTree::new),
lib: self.dylib_path.to_path_buf().into(),
env,
current_dir,
};
let request = msg::Request::ExpandMacro(task);

View file

@ -48,6 +48,8 @@ pub struct ExpandMacro {
/// Environment variables to set during macro expansion.
pub env: Vec<(String, String)>,
pub current_dir: Option<String>,
}
pub trait Message: Serialize + DeserializeOwned {
@ -143,6 +145,7 @@ mod tests {
attributes: None,
lib: std::env::current_dir().unwrap(),
env: Default::default(),
current_dir: Default::default(),
};
let json = serde_json::to_string(&task).unwrap();