ejpcmac/typed_struct

TypedStruct undefined after distillery release

jamescheuk91 opened this issue · 10 comments

The TypedStruct module is undefined after distillery release due to Mix.Project is not defined.

lib/typed_struct.ex
{:typed_struct, "~> #{Mix.Project.config()[:version]}", runtime: false}

Should we remove calling Mix.Project?

This is strange because I’ve already used TypedStruct in Nerves projects—thus using Distillery—without any issue. TypedStruct is a compile-time only dependency as it just generates some code. Are you sure you’ve set runtime: false?

If the issue persists, it may be a problem specific to Elixir 1.7 and its new documentation format as my Nerves projects are running on 1.6.6. But this seems strange to me since this line should be resolved during the compilation of TypedStruct and not during runtime.

P.S.: I’m on holidays and in festival from this afternoon so I may not be responsive until next week.

Hi @ejpcmac, the issue can be reproduced when attempting to hot load modules within the context remote_console session.

To reproduce

  1. build an app with distillery that has a module that uses typedstruct
  2. start the app, connect into the application using remote_console (ie. ./bin/my_app remote_console
  3. Copy/paste the entire module into the iex session

You should receive an error

Hi @thekvn! Can you try not to use runtime: false in you Mix dependencies when first compiling your project? The module should then be available on the server. I think the call to Mix.Project.config/0 shouldn’t be an issue as it is called when TypedStruct is defined. Let me know if the problem persists.

@ejpcmac We are already using runtime: false

@thekvn You should try not to use it. When using runtime: false, TypedStruct is available on compile-time, but is not included in the Distillery release and cannot be used then at runtime in the console.

I’ve just tried it with Elixir 1.6.6 and Distillery 1.5.3. I’m able to reproduce it with runtime: false but it is expected in this case. Without runtime: false, I’m able to define a new module using TypedStruct in a remote console attached to the running release.

I keep the issue open to check with Elixir 1.7 and Distillery 2.0 when it will be out.

@ejpcmac Thanks.
Without runtime: false, the TypedStruct module is loaded in the runtime.

Thanks

I’ve just removed runtime: false in the docs so that it is possible to define modules using TypedStruct at runtime. I let this issue open for people who would encounter the same problem as you. It will automatically close when the changes will be available on master.