Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing how Rust source files are found for v0.6 #13

Closed
rksm opened this issue Aug 13, 2022 · 0 comments
Closed

Changing how Rust source files are found for v0.6 #13

rksm opened this issue Aug 13, 2022 · 0 comments

Comments

@rksm
Copy link
Owner

rksm commented Aug 13, 2022

The hot_module attribute macro (via hot_functions_from_file!("path/to/file.rs")) and the define_lib_reloader!(...) macro allow specifying Rust source files from which public #[no_mangle] functions are discovered and for which hot-reloadable proxy functions are created.

So far, both macros expected file relative paths, i.e. paths relative to the file where the macro was defined. So, for example:

├── Cargo.toml
└── src
│   └── main.rs    <- hot_functions_from_file!("../lib/src/lib.rs");
└── lib
    ├── Cargo.toml
    └── src
        └── lib.rs 

Code for this is here: https://github.com/rksm/hot-lib-reloader-rs/blob/cb016a03c68ea2fb2176b683ff466d8bdb8f94e0/macro/src/util.rs

The reasoning behind it was that it might be more intuitive and easier to reason about with larger code bases but there are two problems that requiring a relative path created:

  1. We need Rust nightly to use the proc_macro::Span feature to lookup the path of the file in which the macro was declared
  2. rust-analyzer fails to expand the macro and cannot give code completion

Thinking about it again, requiring that the path of the files to be relative to the project root is not so bad and will solve both of the problems above. But it means that we need to break the interface. For this reason this change requires a version bump to v0.6.

So` instead of the above, the following will be expected:

├── Cargo.toml
└── src
│   └── main.rs    <- hot_functions_from_file!("lib/src/lib.rs");
└── lib
    ├── Cargo.toml
    └── src
        └── lib.rs 
@rksm rksm changed the title Changing how Rust source files are found Changing how Rust source files are found for v0.6 Aug 13, 2022
rksm added a commit that referenced this issue Aug 13, 2022
- fixes rust-analyzer
- no requirement for nightly anymore

ref #13
@rksm rksm closed this as completed Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant