~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 (2) hide show
  1. changelog.md +7 -0
  2. impl/src/lib.rs +12 -1
changelog.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  Thanks to [Mcat12](https://github.com/Mcat12) for the changelog.
9
9
 
10
+ ## Unreleased
11
+
12
+ ### Fixed
13
+
14
+ - Fixed the `folder` directory being relative to the current directory.
15
+ It is now relative to `Cargo.toml`.
16
+
10
17
  ## [5.4.0] - 2020-02-24
11
18
 
12
19
  ### Changed
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,17 @@ 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_str()
152
+ .unwrap()
153
+ .to_owned()
154
+ } else {
155
+ folder_path
156
+ };
157
+
147
158
  if !Path::new(&folder_path).exists() {
148
159
  let mut message = format!(
149
160
  "#[derive(RustEmbed)] folder '{}' does not exist. cwd: '{}'",