Rebar:交叉编译选项

Rebar: Cross Compilation Options

我正在尝试使用 rebar 在 64 位 arch 系统上生成 32 位 arch 版本。我不清楚我需要如何修改应用程序的 rebar.config 才能执行此操作。

我查看了 rebar 源代码,看看他们是如何检测我的环境的:rebar_utils.erl 将架构设置为 "x86_64-unknown-linux-gnu",并在 rebar_port_compiler 中将其设置为 "default_env"。我想知道如何让 rebar 为另一个目标架构编译。

我尝试了以下 port_env 个选项

{port_env, [{"CFLAGS", "$CFLAGS -fPIC -m32"},{"LDFLAGS", "-arch i386"}]}.

使用这些选项(以及我路径中的 32 位 Erlang 安装),当我 运行 rebar get-deps compile 我的依赖项仍在构建时64 位,因此 ld 跳过我的 32 位库(最终失败,因为它找不到 64 位实现)

/usr/bin/ld: skipping incompatible <PATH TO 32-bit erlang install>/lib/erlang/lib/erl_interface-3.7.14/lib/liberl_interface.a when searching for -lerl_interface
/usr/bin/ld: cannot find -lerl_interface
collect2: ld returned 1 exit status
ERROR: sh(cc c_src/epam.o $LDFLAGS -shared  -L"<PATH TO 32-bit erlang install>/lib/erlang/lib/erl_interface-3.7.14/lib" -lerl_interface -lei -o priv/lib/epam.so)

我需要做什么来强制我的依赖项编译为 32 位?我在这里的尝试没有用。

rebar.config 中的 port_env 设置可以使用 ERLANG_ARCH 环境变量来确定 Erlang 运行时是为 32 位系统还是 64 位系统构建的。例如,以下 port_env 定义为 x86_64、i686 和 i386 芯片架构设置 -m32-m64 以适合 C 编译器:

{port_env, [{"x86_64", "CFLAGS", "$CFLAGS -m$ERLANG_ARCH"},
            {"i[36]86", "CFLAGS", "$CFLAGS -m$ERLANG_ARCH"}]}.

每个元组中的第一个字符串是与 erlang:system_info(system_architecture) function 返回的 Erlang 运行时的系统架构字符串相匹配的正则表达式。在此示例中,仅当正则表达式匹配时才添加额外的 -m$ERLANG_ARCH 选项,所有其他架构都获得默认的 CFLAGS 设置。