Rustler - Any way to remove build artifacts automatically? 78mb exec vs 1.5gb build artifacts

I’m using rustler to wrap a Rust library. Specifically charabia. It’s a language tokenization library, and as such has to use a lot of dictionary data during building, which leads to large target directories. If my understanding of Rust is correct, the contents of build and deps are only relevant during building, and libmyapp_native or libmyapp_native.dylib are the only things that are needed during runtime. If this is the case, I’m curious if there’s a way to have Rustler automatically delete the deps and build directory after the executable has been built.

Here is what the sizes look like in my _build directory for the app’s native directory:

  0B	.cargo-lock
  0B	examples
  0B	incremental
4.0K	libmyapp_native.d
3.7M	.fingerprint
 78M	libmyapp_native.dylib
471M	deps
1.1G	build

From my understanding, this is the important part, not the stuff below it(at least once building is done).

 78M	libmyapp_native.dylib

You can try doing your own compilation step where you use cargo clean to clean the intermediate build files.

Rustler has a skip_compilation? option so you can do the compilation separately.

I’m not quite sure what you’re looking for but a simple deletion in a shell script wouldn’t do the job? Also applies if you’re building in a Dockerfile.

Certainly it could be done with a script, but then i’ve got to remember to run it every time, for each build, and for ElixirLS, and for the test environment, etc. I was hoping there was a way to either automatically clean it up, or at least a post install script that gets run after compilation has completed successfully.

Okay, so I’m definitely not getting your need. Thought you just wanted to clean up a deployment container image.

What’s your problem with 1.5 GB building artifacts?