~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git
Discussions: https://groups.google.com/g/rust-embed-devs

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


Files changed (1) hide show
  1. impl/src/lib.rs +11 -1
impl/src/lib.rs CHANGED
@@ -4,7 +4,7 @@ extern crate quote;
4
4
  extern crate proc_macro;
5
5
 
6
6
  use proc_macro::TokenStream;
7
- use std::path::Path;
7
+ use std::{env, path::Path};
8
8
  use syn::{export::TokenStream2, Data, DeriveInput, Fields, Lit, Meta};
9
9
 
10
10
  #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
@@ -144,6 +144,16 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> TokenStream2 {
144
144
  #[cfg(feature = "interpolate-folder-path")]
145
145
  let folder_path = shellexpand::full(&folder_path).unwrap().to_string();
146
146
 
147
+ // Base relative paths on the Cargo.toml location
148
+ let folder_path = if Path::new(&folder_path).is_relative() {
149
+ Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap())
150
+ .join(folder_path)
151
+ .to_string_lossy()
152
+ .to_string()
153
+ } else {
154
+ folder_path
155
+ };
156
+
147
157
  if !Path::new(&folder_path).exists() {
148
158
  let mut message = format!(
149
159
  "#[derive(RustEmbed)] folder '{}' does not exist. cwd: '{}'",