From 0bbb2985f069c2c1785d33da6887598673cdaaac Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Mon, 30 May 2011 21:13:38 -0400 Subject: [PATCH] Use external wordsize to get emulator build arch Calling erlang:system_info(wordsize) yields the internal word size of the Erlang emulator. But due to the halfword emulator, need to pass {wordsize, external} instead to get the word size, or pointer size, as seen by external code such as NIFs. The halfword emulator has 4 byte internal words but 8 byte external words due to 64-bit compilation, which means NIFs for the halfword emulator also have to be compiled 64-bit. But just passing wordsize is equivalent to passing {wordsize, internal}, which does not indicate the pointer size for the halfword emulator. Older versions of Erlang do not support {wordsize, external}, though, so continue to pass just wordsize for those versions. --- src/rebar_erlc_compiler.erl | 3 ++- src/rebar_port_compiler.erl | 9 ++++++++- src/rebar_utils.erl | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 38dd198..efbdf09 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -52,7 +52,8 @@ %% %% OtpRelease = erlang:system_info(otp_release). %% SysArch = erlang:system_info(system_architecture). -%% Words = integer_to_list(8 * erlang:system_info(wordsize)). +%% Words = integer_to_list(8 * +%% erlang:system_info({wordsize, external})). %% %% E.g. to define HAVE_SENDFILE only on systems with %% sendfile(), to define BACKLOG on Linux/FreeBSD as 128, diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl index a9b73cc..ad1e387 100644 --- a/src/rebar_port_compiler.erl +++ b/src/rebar_port_compiler.erl @@ -398,7 +398,14 @@ default_env() -> {"DRV_LDFLAGS", "-shared $ERL_LDFLAGS"}, {"darwin", "DRV_LDFLAGS", "-bundle -flat_namespace -undefined suppress $ERL_LDFLAGS"}, - {"ERLANG_ARCH", integer_to_list(8 * erlang:system_info(wordsize))}, + {"ERLANG_ARCH", + try erlang:system_info({wordsize, external}) of + Val -> + integer_to_list(8 * Val) + catch + error:badarg -> + integer_to_list(8 * erlang:system_info(wordsize)) + end}, {"ERLANG_TARGET", rebar_utils:get_arch()}, %% Solaris specific flags diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 792c54f..68ca0dc 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -62,7 +62,13 @@ is_arch(ArchRegex) -> end. get_arch() -> - Words = integer_to_list(8 * erlang:system_info(wordsize)), + Words = try erlang:system_info({wordsize, external}) of + Val -> + integer_to_list(8 * Val) + catch + error:badarg -> + integer_to_list(8 * erlang:system_info(wordsize)) + end, erlang:system_info(otp_release) ++ "-" ++ erlang:system_info(system_architecture) ++ "-" ++ Words.