#Mix Erlang/Elixir include path

13 messages · Page 1 of 1 (latest)

waxen osprey
#

I'm trying to write some stuff in Elixir that uses the wx, gl, and glu modules from Erlang. These have a lot of macro defines that, as far as I know, I need to wrap to access in Elixir. I've found a few ways that this is done, but none of them seem to work. This example: https://gist.github.com/simonmcconnell/a20c245bb441986c8f6da65fa6489a9d is ideal for me, because I'd like it to update with changes to the underling wxErlang modules. But even a "simpler" example such as https://wtfleming.github.io/blog/getting-started-opengl-elixir/ doesn't seem to work.

In both cases, there seems to be an issue with the -include_lib calls. As an example from the gist which generates calls for all of the macros, I'm getting this error:

❯ iex -S mix
Compiling 2 files (.erl)
src/wx_include.erl:2:14: can't find include lib "wx/include/wx.hrl"
%    2| -include_lib("wx/include/wx.hrl").
%     |              ^

src/wx_include.erl:4:25: undefined macro 'wxDefaultCoord'
%    4| get(wxDefaultCoord) -> ?wxDefaultCoord;
%     |                         ^

src/wx_include.erl:3:2: function get/1 undefined
%    3| -export([get/1]).
%     |  ^

src/gl_include.erl:2:14: can't find include lib "wx/include/gl.hrl"
%    2| -include_lib("wx/include/gl.hrl").
%     |              ^

src/gl_include.erl:4:27: undefined macro 'GL_VERSION_1_1'
%    4| get(glGL_VERSION_1_1) -> ?GL_VERSION_1_1;
%     |                           ^

src/gl_include.erl:3:2: function get/1 undefined
%    3| -export([get/1]).
%     |  ^

From the simpler example where only the used macros are exported, it's similar:

❯ iex -S mix
Compiling 2 files (.erl)
src/gl_const.erl:4:14: can't find include lib "wx/include/gl.hrl"
%    4| -include_lib("wx/include/gl.hrl").
%     |              ^

src/wx_const.erl:4:14: can't find include lib "wx/include/wx.hrl"
%    4| -include_lib("wx/include/wx.hrl").
%     |              ^

src/gl_const.erl:7:4: undefined macro 'GL_SMOOTH'
%    7|   ?GL_SMOOTH.
%     |    ^
#

according to the docs, include_lib basically does code.lib_dir(wx) and appends include/gl.hrl to it, like the gist does. this works in iex:

$ iex
Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.16.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> lib_dir = :code.lib_dir(:wx)
~c"/opt/homebrew/Cellar/erlang/26.2.1/lib/erlang/lib/wx-2.4"
iex(2)> file = :filename.join([lib_dir, 'include/wx.hrl'])
~c"/opt/homebrew/Cellar/erlang/26.2.1/lib/erlang/lib/wx-2.4/include/wx.hrl"
iex(3)> {:ok, forms} = :epp_dodger.parse_file(file)
{:ok,
 [
   {:tree, :attribute, {:attr, 26, [], :none},
    {:attribute, {:tree, :atom, {:attr, 26, [], :none}, :record},
     ...
#

it almost seems like mix doesn't have the include libraries set correctly for erlang, but I'm not sure how to do that.

clear flicker
#

Instead of writing Erlang module to the path I would simply read the data and generate Elixir module that will expose all that values directly

waxen osprey
#

how? I've only seen things do it this way

#

by things I mean specifically using wx/gl in elixir. I'm not a fan of this method either, but I'm not sure how else to do it.

waxen osprey
#

Oh, huh. I guess I would just write the actual values to an elixir file. I can't test it right now but I don't see why it wouldn't work. Just spit out a file like

defmodule WXGlobal do
  def wxID_ANY, do: 5
  ...

That seems a little silly at that point. I'd rather them be compile time constants. Hm.

ivory slate
#

Functions with no arguments and a single return value are optimized by the BEAM to basically be constants, I wouldn't worry about it too much

waxen osprey
#

Nice

clear flicker
ivory slate
#

Oh no? Could have sworn I read that somewhere. Thanks for the correction

clear flicker
ivory slate
#

Ah, makes sense. Thanks