Having separate file of the executable and updating it, while not needing to rebuild

Hello Rust community.
I am using Rust (crate actix web) for backend and a javascript framework for frontend.
I noticed there are no dist folder (frontend files) on the target, the executable has all the files inside.
So how could i separate them?.

My use case: I have a javascript (json) file that i will update often, so that i send it from backend to frontend (via GET request) to update the view on the frontend.
MAP: Update json -> rust takes it and -> sends it to frontend via GET -> view updated.

But this means that rust will have a separate file outside of the executable!.
Is possible to separate the exe?

Notes: I need to update the json file without rebuilding the project. So it will update the frontend via the map shown above.

Questions:

  1. Is it possible to separate the frontend files from the exe and run them together?
  2. how could i solve my use case? Updating the file on backend.

Sorry if this is not explained well, i will update it if something is not clear!

Edit: I copied the executable to my desktop and it seems it has all the files inside it, so i want to separate them for updating only one file and not building everything from the beginning!

In a traditional C workflow, you'd do this with some linker tricks: Put the data to be changed in its own object file, and then just re-link the executable when the file changes. As Rust uses the LLVM backend and linker, there's probably some way to pull the same trick (but I don't know what it is).

From your post it's not clear if you want your server to remain a single self-contained executable.

If not, then solution is rather simple. Instead of having files compiled in into the server (via include_bytes! or some other clever macro crate) have them loaded from disk via std::fs::read or such. actix-files can serve files from an on-disk folder.
A slight complication will be in telling the executable where the files are on disk. You could assume current directory, or same directory as the executable (guessed from std::env::args().nth(0)) or perhaps configured via an env var or command-line argument.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.