Makes include_str! use a relative path
@@ -166,9 +166,14 @@ fn generate_builtin_rules() -> Vec<(&'static str, TokenStream)> {
// Needed because Cargo doesn't watch for changes in grammars.
fn generate_include(name: &Ident, path: &str) -> TokenStream {
let const_name = Ident::new(&format!("_PEST_GRAMMAR_{}", name), Span::call_site());
+ // Need to make this relative to the current directory since the path to the file
+ // is derived from the CARGO_MANIFEST_DIR environment variable
+ let mut current_dir = std::env::current_dir().expect("Unable to get current directory");
+ current_dir.push(path);
+ let relative_path = current_dir.to_str().expect("path contains invalid unicode");
quote! {
#[allow(non_upper_case_globals)]
- const #const_name: &'static str = include_str!(#path);
+ const #const_name: &'static str = include_str!(#relative_path);
}
}
