Closed sisungo closed 5 months ago
The embed
macro import paths are relative to CARGO_MANIFEST_DIR
i.e. the directory where the Cargo.toml
file is located.
Have you tried importing the main.js
with the path src/main.js
?
I know this is different from how rust does file imports with include!()
but there is no good way to replicate that behavior in proc macro like embed
so that is way file paths in the embed
macro are relative to the crate root.
The
embed
macro import paths are relative toCARGO_MANIFEST_DIR
i.e. the directory where theCargo.toml
file is located.Have you tried importing the
main.js
with the pathsrc/main.js
?
@DelSkayn I tried src/main.js
, crate_a/src/main.js
, and them with ./
prefix. Neither of them are working. When I input an empty path like this:
static JSBUNDLE: Bundle = rquickjs::embed! [
"app_main": "",
];
The error message looks like:
error: Error loading embedded js module from path `/Users/sisungo/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/rquickjs-macro-0.4.0-beta.4`: Is a directory (os error 21)
--> airlogd/src/main.rs:5:9
|
5 | "app_main": "",
| ^^^^^^^^^^
Deleting all README.md
in my project, and input README.md
as path, the error message turned to:
error: Exception generated by quickjs
--> airlogd/src/main.rs:4:31
|
4 | static JSBUNDLE: Bundle = rquickjs::embed! [
| _______________________________^
5 | | "app_main": "README.md",
6 | | ];
| |_____^
|
= note: this error originates in the macro `rquickjs::embed` (in Nightly builds, run with -Z macro-backtrace for more info)
I think the procedure macro is finding file from ~/.cargo/registry/src/*/rquickjs-macro-*
. (the problem also happens on rquickjs 0.3.x
)
I have found the problem and it is already fixed in the master branch. Turns out the 0.3 and the current beta still have a bug in retrieving CARGO_MANIFEST_DIR
, They accidentally use the environment variable from compile time instead of runtime.
It is already fixed in main, I am hoping to release the full 0.4 this week so it will be fixed then. I'll leave this issue open until then.
Closing this issue as it should be fixed in the new 0.4 version
Introduction
My project has a structure like:
When using
rquickjs::embed! []
macro, withmain.rs
looks like:It fails with the error of
No such file or directory
. When inputing an empty path, it shows that the file is being found at a directory beginning with$HOME/.cargo/registry/src
.Environment