rustler icon indicating copy to clipboard operation
rustler copied to clipboard

Cache Mix.env() to trigger recompilation

Open evnu opened this issue 2 years ago • 3 comments

When using MIX_ENV to configure the build profile, changing MIX_ENV in a subsequent run needs to trigger the mechanism for recompilation to determine if that mode was build. For this, we need to cache value of Mix.env() and detect when that changes. If it changes, we write the cache, @external_resource can pick that up.

Close #479

evnu avatar Sep 12 '22 19:09 evnu

See also https://github.com/rusterlium/rustler/issues/479#issuecomment-1244239121.

evnu avatar Sep 12 '22 19:09 evnu

I haven't looked into this much, but would making rust use a different target directory for each mix compilation mode be another option?

What are the pros/cons of these two options?

hansihe avatar Sep 13 '22 07:09 hansihe

I haven't looked into this much, but would making rust use a different target directory for each mix compilation mode be another option?

The library which is loaded is hard-coded into the module at compile time, see the Rustler module (config.lib defaults to true in Rustler.Compiler.Config). So, unless I am missing something, the library path will not change, unless a recompilation is triggered. Also, the library directory already depends on the build profile. It defaults to _build/rustler/{debug,release}.

So, we need to find a way to ensure that a module recompilation is triggered (use needs to be expanded again), if the mix environment changes.

But maybe we really should get rid of MIX_ENV handling altogether instead and tell users to pick the build profile explicitly in use Rustler.

evnu avatar Sep 13 '22 09:09 evnu

Closing in favor of https://github.com/rusterlium/rustler/pull/496.

evnu avatar Nov 09 '22 16:11 evnu