hot-lib-reloader-rs
hot-lib-reloader-rs copied to clipboard
Q: Is copying the library required on *nix?
On *nix you can overwrite a file that's being read by another process.
https://stackoverflow.com/questions/2028874/what-happens-to-an-open-file-handle-on-linux-if-the-pointed-file-gets-moved-or-d
This should mean that the compiler can output a new dynamic library without hitting errors because there's programs still reading (soon to be older versions of) it. When Casey presents this copy-based workaround, he's just working around the Windows FS guarantees.
Can the copy become Windows-specific?
Hmm good question. So on macOS at least there is this problem:
- https://github.com/rust-lang/rust/issues/47974
- https://github.com/rust-lang/rust/issues/88737
Basically, unloading a library does not work and in order to get the changes we need to load from a new file.
On Linux it might be worth a try...
I'm fairly certain Linux
has similar situations where the library isn't unloaded and this also prevents loading a new version with the same name.
E.g. when there are thread local destructors that haven't ran (due to the associated thread still being alive). See https://fasterthanli.me/articles/so-you-want-to-live-reload-rust.
It is also possible to overwrite the loaded library file in the sense of actually writing to the existing file and (i.e. not deleting it and creating a new one with the same name), however I have seen this cause issues/crashes (I assume due to the old thread locals still being loaded and/or other state associated with the loaded library that doesn't expect to be used with a new version of the code).