Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c_src/libsodium-f553bb4bf22a6a8e4fa5f69cfbf91ce95327b790
63 changes: 63 additions & 0 deletions build_libsodium.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

CORE_TOP=`pwd`

LIBSODIUM_VER="f553bb4bf22a6a8e4fa5f69cfbf91ce95327b790"
LIBSODIUM_ZIP="libsodium-$LIBSODIUM_VER.zip"
LIBSODIUM_DIR="$CORE_TOP/c_src/libsodium-$LIBSODIUM_VER"


UNZIP=`which unzip`
if ! test -n "UNZIP"; then
display_error "Error: unzip is required. Add it to 'PATH'"
exit 1
fi

clean() {
echo "==> clean libsodium"
if test -f $LIBSODIUM_DIR/Makefile; then
cd $LIBSODIUM_DIR && make clean
fi
}


build() {
echo "==> build libsodium"
# unzip
if ! test -d $LIBSODIUM_DIR; then
cd $CORE_TOP/c_src && $UNZIP $LIBSODIUM_ZIP
fi

cd $LIBSODIUM_DIR

# configure
if ! test -f $LIBSODIUM_DIR/Makefile; then
./autogen.sh
./configure --disable-pie \
--disable-ssp \
--disable-shared \
--enable-static
fi

make
}

if [ "x$1" = "x" ]; then
build
exit 0
fi

case "$1" in
build)
shift 1
build
;;
clean)
shift 1
clean
;;
*)
echo "badarg"
exit 1;
;;
esac
Binary file not shown.
24 changes: 17 additions & 7 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*-
% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et:
%
%%%
%%% Reconcile NaCl's idea of architecture name with Erlang's, set compiler
%%% flags and paths for NIF compilation.
%%%

Arch = erlang:system_info(system_architecture),

LIBSODIUM_VER="f553bb4bf22a6a8e4fa5f69cfbf91ce95327b790",
LIBSODIUM_CFLAGS="-Ic_src/libsodium-" ++ LIBSODIUM_VER ++"/src/libsodium/include/sodium",
LIBSODIUM_LDLAGS="c_src/libsodium-" ++ LIBSODIUM_VER ++ "/src/libsodium/.libs/libsodium.a",

%% Augment configuration from rebar.config with NIF settings.
lists:keymerge(1,
lists:keysort(1, [
{port_env, [{"DRV_CFLAGS", "$DRV_CFLAGS -Wall -Werror -I/usr/local/include/sodium"},
{"DRV_LDFLAGS", "$DRV_LDFLAGS -L/usr/local/lib -Wl,-R/usr/local/lib -lsodium"}]},
{port_specs, [{filename:join(["priv", Arch, "salt_nif.so"]), ["c_src/salt_nif.c"]}]},
{pre_hooks, [{clean, "rm -fr ebin erl_crash.dump salt_test.beam c_src/salt_nif.o priv/" ++ Arch}]}
]),
lists:keysort(1, CONFIG)).
lists:keysort(1, [
{port_env, [{"DRV_CFLAGS", "$DRV_CFLAGS -Wall -Werror " ++ LIBSODIUM_CFLAGS},
{"DRV_LDFLAGS", "$DRV_LDFLAGS " ++ LIBSODIUM_LDLAGS}]},
{port_specs, [{filename:join(["priv", Arch, "salt_nif.so"]),
["c_src/salt_nif.c"]}]},
{pre_hooks, [{compile, "./build_libsodium.sh"},
{clean, "rm -fr ebin erl_crash.dump salt_test.beam c_src/salt_nif.o priv/" ++ Arch},
{clean, "./build_libsodium.sh clean"}]}
]),
lists:keysort(1, CONFIG)).
14 changes: 13 additions & 1 deletion src/salt_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@
%%%

load() ->
Path = filename:join([code:priv_dir(salt), erlang:system_info(system_architecture), "salt_nif"]),
%% get local priv dir if we test from the shell
PrivDir = case code:priv_dir(salt) of
{error, _} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Dir ->
Dir
end,

Path = filename:join([PrivDir,
erlang:system_info(system_architecture),
"salt_nif"]),
erlang:load_nif(Path, 0).

%%% Exported from salt_nif.c.
Expand Down