Skip to content

Commit 2739474

Browse files
Make the procedural macros read files relative to $CARGO_MANIFEST_DIR (#167)
(fixes #159)
1 parent 8a27d70 commit 2739474

File tree

41 files changed

+82
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+82
-67
lines changed

crates/rust-wasm-impl/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::{Path, PathBuf};
2+
13
use proc_macro::TokenStream;
24
use syn::parse::{Error, Parse, ParseStream, Result};
35
use syn::punctuated::Punctuated;
@@ -28,11 +30,11 @@ fn run(input: TokenStream, dir: Direction) -> TokenStream {
2830

2931
// Include a dummy `include_str!` for any files we read so rustc knows that
3032
// we depend on the contents of those files.
31-
let cwd = std::env::current_dir().unwrap();
33+
let cwd = std::env::var("CARGO_MANIFEST_DIR").unwrap();
3234
for file in input.files.iter() {
3335
contents.push_str(&format!(
3436
"const _: &str = include_str!(r#\"{}\"#);\n",
35-
cwd.join(file).display()
37+
Path::new(&cwd).join(file).display()
3638
));
3739
}
3840

@@ -82,7 +84,9 @@ impl Parse for Opts {
8284
files.push(s.value());
8385
}
8486
let mut interfaces = Vec::new();
87+
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
8588
for path in files.iter() {
89+
let path = manifest_dir.join(path);
8690
let iface = Interface::parse_file(path).map_err(|e| Error::new(call_site, e))?;
8791
interfaces.push(iface);
8892
}
@@ -123,7 +127,9 @@ impl Parse for ConfigField {
123127
let paths = Punctuated::<syn::LitStr, Token![,]>::parse_terminated(&paths)?;
124128
let values = paths.iter().map(|s| s.value()).collect::<Vec<_>>();
125129
let mut interfaces = Vec::new();
130+
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
126131
for value in &values {
132+
let value = manifest_dir.join(value);
127133
let interface =
128134
Interface::parse_file(value).map_err(|e| Error::new(bracket.span, e))?;
129135
interfaces.push(interface);

crates/test-modules/modules/crates/flags-main/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::import!("crates/flags/flags.wit");
1+
wit_bindgen_rust::import!("../flags/flags.wit");
22

33
use flags::*;
44

crates/test-modules/modules/crates/flags/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::export!("crates/flags/flags.wit");
1+
wit_bindgen_rust::export!("flags.wit");
22

33
use flags::*;
44

crates/test-modules/modules/crates/lists-main/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::import!("crates/lists/lists.wit");
1+
wit_bindgen_rust::import!("../lists/lists.wit");
22

33
use lists::*;
44

crates/test-modules/modules/crates/lists/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::export!("crates/lists/lists.wit");
1+
wit_bindgen_rust::export!("lists.wit");
22

33
use lists::*;
44

crates/test-modules/modules/crates/nested-main/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::import!("crates/nested_b/nested_b.wit");
1+
wit_bindgen_rust::import!("../nested_b/nested_b.wit");
22

33
use nested_b::*;
44

crates/test-modules/modules/crates/nested_a/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::export!("crates/nested_a/nested_a.wit");
1+
wit_bindgen_rust::export!("nested_a.wit");
22

33
struct NestedA;
44

crates/test-modules/modules/crates/nested_b/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
wit_bindgen_rust::import!("crates/nested_a/nested_a.wit");
2-
wit_bindgen_rust::export!("crates/nested_b/nested_b.wit");
1+
wit_bindgen_rust::import!("../nested_a/nested_a.wit");
2+
wit_bindgen_rust::export!("nested_b.wit");
33

44
struct NestedB;
55

crates/test-modules/modules/crates/records-main/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::import!("crates/records/records.wit");
1+
wit_bindgen_rust::import!("../records/records.wit");
22

33
use records::*;
44

crates/test-modules/modules/crates/records/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
wit_bindgen_rust::export!("crates/records/records.wit");
1+
wit_bindgen_rust::export!("records.wit");
22

33
use records::*;
44

0 commit comments

Comments
 (0)