rksm / hot-lib-reloader-rs

Reload Rust code without app restarts. For faster feedback cycles.
MIT License
577 stars 21 forks source link

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

Closed rksm closed 1 year ago

rksm commented 1 year ago

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