2017-03-12 09:44:29 -07:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
export MAKE_FLAGS='-j4'
|
2017-09-21 02:25:09 -07:00
|
|
|
export EXPORTED_FUNCTIONS_STANDARD='["_crypto_aead_chacha20poly1305_abytes","_crypto_aead_chacha20poly1305_decrypt","_crypto_aead_chacha20poly1305_decrypt_detached","_crypto_aead_chacha20poly1305_encrypt","_crypto_aead_chacha20poly1305_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_abytes","_crypto_aead_chacha20poly1305_ietf_decrypt","_crypto_aead_chacha20poly1305_ietf_decrypt_detached","_crypto_aead_chacha20poly1305_ietf_encrypt","_crypto_aead_chacha20poly1305_ietf_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_keybytes","_crypto_aead_chacha20poly1305_ietf_keygen","_crypto_aead_chacha20poly1305_ietf_npubbytes","_crypto_aead_chacha20poly1305_ietf_nsecbytes","_crypto_aead_chacha20poly1305_keybytes","_crypto_aead_chacha20poly1305_keygen","_crypto_aead_chacha20poly1305_npubbytes","_crypto_aead_chacha20poly1305_nsecbytes","_crypto_aead_xchacha20poly1305_ietf_abytes","_crypto_aead_xchacha20poly1305_ietf_decrypt","_crypto_aead_xchacha20poly1305_ietf_decrypt_detached","_crypto_aead_xchacha20poly1305_ietf_encrypt","_crypto_aead_xchacha20poly1305_ietf_encrypt_detached","_crypto_aead_xchacha20poly1305_ietf_keybytes","_crypto_aead_xchacha20poly1305_ietf_keygen","_crypto_aead_xchacha20poly1305_ietf_npubbytes","_crypto_aead_xchacha20poly1305_ietf_nsecbytes","_crypto_auth","_crypto_auth_bytes","_crypto_auth_keybytes","_crypto_auth_keygen","_crypto_auth_verify","_crypto_box_beforenm","_crypto_box_beforenmbytes","_crypto_box_detached","_crypto_box_detached_afternm","_crypto_box_easy","_crypto_box_easy_afternm","_crypto_box_keypair","_crypto_box_macbytes","_crypto_box_noncebytes","_crypto_box_open_detached","_crypto_box_open_detached_afternm","_crypto_box_open_easy","_crypto_box_open_easy_afternm","_crypto_box_publickeybytes","_crypto_box_seal","_crypto_box_seal_open","_crypto_box_sealbytes","_crypto_box_secretkeybytes","_crypto_box_seed_keypair","_crypto_box_seedbytes","_crypto_core_hchacha20","_crypto_core_hchacha20_constbytes","_crypto_core_hchacha20_inputbytes","_crypto_core_hchacha20_keybytes","_crypto_core_hchacha20_outputbytes","_crypto_generichash","_crypto_generichash_bytes","_crypto_generichash_bytes_max","_crypto_generichash_bytes_min","_crypto_generichash_final","_crypto_generichash_init","_crypto_generichash_keybytes","_crypto_generichash_keybytes_max","_crypto_generichash_keybytes_min","_crypto_generichash_keygen","_crypto_generichash_statebytes","_crypto_generichash_update","_crypto_hash","_crypto_hash_bytes","_crypto_kdf_bytes_max","_crypto_kdf_bytes_min","_crypto_kdf_contextbytes","_crypto_kdf_derive_from_key","_crypto_kdf_keybytes","_crypto_kdf_keygen","_crypto_kx_client_session_keys","_crypto_kx_keypair","_crypto_kx_publickeybytes","_crypto_kx_secretkeybytes","_crypto_kx_seed_keypair","_crypto_kx_seedbytes","_crypto_kx_server_session_keys","_crypto_kx_sessionkeybytes","_crypto_scalarmult","_crypto_scalarmult_base","_crypto_scalarmult_bytes","_crypto_scalarmult_scalarbytes","_crypto_secretbox_detached","_crypto_secretbox_easy","_crypto_secretbox_keybytes","_crypto_secretbox_keygen","_crypto_secretbox_macbytes","_crypto_secretbox_noncebytes","_crypto_secretbox_open_detached","_crypto_secretbox_open_easy","_crypto_secretstream_xchacha20poly1305_abytes","_crypto_secretstream_xchacha20poly1305_headerbytes","_crypto_secretstream_xchacha20poly1305_init_pull","_crypto_secretstream_xchacha20poly1305_init_push","_crypto_secretstream_xchacha20poly1305_keybytes","_crypto_secretstream_xchacha20poly1305_keygen","_crypto_secretstream_xchacha20poly1305_messagebytes_max","_crypto_secretstream_xchacha20poly1305_pull","_crypto_secretstream_xchacha20poly1305_push","_crypto_secretstream_xchacha20poly1305_rekey","_crypto_secretstream_xchacha20poly1305_statebytes","_crypto_secretstream_xchacha20poly1305_tag_final","_crypto_secretstream_xchacha20poly1305_tag_message","_crypto_secretstream_xchacha20poly1305_tag_push","_crypto_secretstream_xchacha20poly1305_tag_rekey","_crypto_shorthash","_crypto_shorthash_bytes","_crypto_shorthash_keybytes","_crypto_shorthash_keygen","_crypto_sign","_crypto_sign_bytes","_crypto_sign_detached","_
|
|
|
|
export EXPORTED_FUNCTIONS_SUMO='["_crypto_aead_chacha20poly1305_abytes","_crypto_aead_chacha20poly1305_decrypt","_crypto_aead_chacha20poly1305_decrypt_detached","_crypto_aead_chacha20poly1305_encrypt","_crypto_aead_chacha20poly1305_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_abytes","_crypto_aead_chacha20poly1305_ietf_decrypt","_crypto_aead_chacha20poly1305_ietf_decrypt_detached","_crypto_aead_chacha20poly1305_ietf_encrypt","_crypto_aead_chacha20poly1305_ietf_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_keybytes","_crypto_aead_chacha20poly1305_ietf_keygen","_crypto_aead_chacha20poly1305_ietf_npubbytes","_crypto_aead_chacha20poly1305_ietf_nsecbytes","_crypto_aead_chacha20poly1305_keybytes","_crypto_aead_chacha20poly1305_keygen","_crypto_aead_chacha20poly1305_npubbytes","_crypto_aead_chacha20poly1305_nsecbytes","_crypto_aead_xchacha20poly1305_ietf_abytes","_crypto_aead_xchacha20poly1305_ietf_decrypt","_crypto_aead_xchacha20poly1305_ietf_decrypt_detached","_crypto_aead_xchacha20poly1305_ietf_encrypt","_crypto_aead_xchacha20poly1305_ietf_encrypt_detached","_crypto_aead_xchacha20poly1305_ietf_keybytes","_crypto_aead_xchacha20poly1305_ietf_keygen","_crypto_aead_xchacha20poly1305_ietf_npubbytes","_crypto_aead_xchacha20poly1305_ietf_nsecbytes","_crypto_auth","_crypto_auth_bytes","_crypto_auth_hmacsha256","_crypto_auth_hmacsha256_bytes","_crypto_auth_hmacsha256_final","_crypto_auth_hmacsha256_init","_crypto_auth_hmacsha256_keybytes","_crypto_auth_hmacsha256_keygen","_crypto_auth_hmacsha256_statebytes","_crypto_auth_hmacsha256_update","_crypto_auth_hmacsha256_verify","_crypto_auth_hmacsha512","_crypto_auth_hmacsha512256","_crypto_auth_hmacsha512256_bytes","_crypto_auth_hmacsha512256_final","_crypto_auth_hmacsha512256_init","_crypto_auth_hmacsha512256_keybytes","_crypto_auth_hmacsha512256_keygen","_crypto_auth_hmacsha512256_statebytes","_crypto_auth_hmacsha512256_update","_crypto_auth_hmacsha512256_verify","_crypto_auth_hmacsha512_bytes","_crypto_auth_hmacsha512_final","_crypto_auth_hmacsha512_init","_crypto_auth_hmacsha512_keybytes","_crypto_auth_hmacsha512_keygen","_crypto_auth_hmacsha512_statebytes","_crypto_auth_hmacsha512_update","_crypto_auth_hmacsha512_verify","_crypto_auth_keybytes","_crypto_auth_keygen","_crypto_auth_primitive","_crypto_auth_verify","_crypto_box","_crypto_box_afternm","_crypto_box_beforenm","_crypto_box_beforenmbytes","_crypto_box_boxzerobytes","_crypto_box_curve25519xchacha20poly1305_beforenm","_crypto_box_curve25519xchacha20poly1305_beforenmbytes","_crypto_box_curve25519xchacha20poly1305_detached","_crypto_box_curve25519xchacha20poly1305_detached_afternm","_crypto_box_curve25519xchacha20poly1305_easy","_crypto_box_curve25519xchacha20poly1305_easy_afternm","_crypto_box_curve25519xchacha20poly1305_keypair","_crypto_box_curve25519xchacha20poly1305_macbytes","_crypto_box_curve25519xchacha20poly1305_noncebytes","_crypto_box_curve25519xchacha20poly1305_open_detached","_crypto_box_curve25519xchacha20poly1305_open_detached_afternm","_crypto_box_curve25519xchacha20poly1305_open_easy","_crypto_box_curve25519xchacha20poly1305_open_easy_afternm","_crypto_box_curve25519xchacha20poly1305_publickeybytes","_crypto_box_curve25519xchacha20poly1305_seal","_crypto_box_curve25519xchacha20poly1305_seal_open","_crypto_box_curve25519xchacha20poly1305_sealbytes","_crypto_box_curve25519xchacha20poly1305_secretkeybytes","_crypto_box_curve25519xchacha20poly1305_seed_keypair","_crypto_box_curve25519xchacha20poly1305_seedbytes","_crypto_box_curve25519xsalsa20poly1305","_crypto_box_curve25519xsalsa20poly1305_afternm","_crypto_box_curve25519xsalsa20poly1305_beforenm","_crypto_box_curve25519xsalsa20poly1305_beforenmbytes","_crypto_box_curve25519xsalsa20poly1305_boxzerobytes","_crypto_box_curve25519xsalsa20poly1305_keypair","_crypto_box_curve25519xsalsa20poly1305_macbytes","_crypto_box_curve25519xsalsa20poly1305_noncebytes","_crypto_box_curve25519xsalsa20poly1305_open","_crypto_box_curve25519xsalsa20poly1305_open_afternm","_crypto_box_curve25519xsalsa20poly1305_publickeybytes","_crypto_box_curve25519xsalsa20poly1305_s
|
2017-03-12 09:44:29 -07:00
|
|
|
export LDFLAGS="-s RESERVED_FUNCTION_POINTERS=8"
|
2017-09-28 17:36:03 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s WASM=1 -s SINGLE_FILE=1"
|
2017-08-25 13:53:31 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s NO_DYNAMIC_EXECUTION=1 -s ASSERTIONS=0"
|
2017-03-12 09:44:29 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s ALIASING_FUNCTION_POINTERS=1"
|
|
|
|
export LDFLAGS="${LDFLAGS} -s FUNCTION_POINTER_ALIGNMENT=1 -s DISABLE_EXCEPTION_CATCHING=1"
|
|
|
|
export LDFLAGS="${LDFLAGS} -s ALLOW_MEMORY_GROWTH=1"
|
|
|
|
export LDFLAGS_DIST="-s NO_FILESYSTEM=1"
|
|
|
|
export CFLAGS="-Os"
|
|
|
|
|
|
|
|
echo
|
|
|
|
if [ "x$1" = "x--standard" ]; then
|
|
|
|
echo "Building a standard distribution in ${PREFIX}"
|
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_STANDARD"
|
|
|
|
export PREFIX="$(pwd)/libsodium-js"
|
|
|
|
export DONE_FILE="$(pwd)/js.done"
|
2017-07-30 14:31:56 -07:00
|
|
|
export CONFIG_EXTRA="--enable-minimal"
|
2017-03-12 09:44:29 -07:00
|
|
|
export DIST='yes'
|
|
|
|
elif [ "x$1" = "x--sumo" ]; then
|
|
|
|
echo "Building a sumo distribution in ${PREFIX}"
|
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_SUMO"
|
|
|
|
export PREFIX="$(pwd)/libsodium-js-sumo"
|
|
|
|
export DONE_FILE="$(pwd)/js-sumo.done"
|
|
|
|
export DIST='yes'
|
|
|
|
elif [ "x$1" = "x--browser-tests" ]; then
|
|
|
|
echo "Building tests for web browsers"
|
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_SUMO"
|
|
|
|
export PREFIX="$(pwd)/libsodium-js-tests"
|
|
|
|
export DONE_FILE="$(pwd)/js-tests-browser.done"
|
|
|
|
export BROWSER_TESTS='yes'
|
|
|
|
export DIST='no'
|
|
|
|
elif [ "x$1" = "x--tests" ]; then
|
|
|
|
echo "Building for testing"
|
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_SUMO"
|
|
|
|
export PREFIX="$(pwd)/libsodium-js-tests"
|
|
|
|
export DONE_FILE="$(pwd)/js-tests.done"
|
|
|
|
export DIST='no'
|
|
|
|
else
|
|
|
|
echo "Usage: $0 <build_type>"
|
|
|
|
echo "<build_type> := --standard | --sumo | --browser-tests | --tests"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
export JS_EXPORTS_FLAGS="-s EXPORTED_FUNCTIONS=${EXPORTED_FUNCTIONS}"
|
|
|
|
|
|
|
|
rm -f "$DONE_FILE"
|
|
|
|
|
|
|
|
echo
|
2017-07-30 14:31:56 -07:00
|
|
|
emconfigure ./configure $CONFIG_EXTRA --disable-shared --prefix="$PREFIX" \
|
2017-03-12 09:44:29 -07:00
|
|
|
--without-pthreads CFLAGS="$CFLAGS" && \
|
|
|
|
emmake make clean
|
|
|
|
[ $? = 0 ] || exit 1
|
|
|
|
|
|
|
|
if [ "$DIST" = yes ]; then
|
|
|
|
emmake make $MAKE_FLAGS install && \
|
|
|
|
emcc "$CFLAGS" --llvm-lto 1 --memory-init-file 0 $CPPFLAGS $LDFLAGS $JS_EXPORTS_FLAGS \
|
2017-08-01 14:21:57 -07:00
|
|
|
"${PREFIX}/lib/libsodium.a" -o "${PREFIX}/lib/libsodium.js" || exit 1
|
2017-03-12 09:44:29 -07:00
|
|
|
touch -r "${PREFIX}/lib/libsodium.js" "$DONE_FILE"
|
|
|
|
ls -l "${PREFIX}/lib/libsodium.js"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test "x$NODE" = x; then
|
|
|
|
for candidate in node nodejs; do
|
|
|
|
case $($candidate --version 2>&1) in #(
|
|
|
|
v*)
|
|
|
|
NODE=$candidate
|
|
|
|
break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$BROWSER_TESTS" != "x" ]; then
|
|
|
|
echo 'Compiling the test suite for web browsers...' && \
|
|
|
|
emmake make $MAKE_FLAGS CPPFLAGS="$CPPFLAGS -DBROWSER_TESTS=1" check > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
if test "x$NODE" = x; then
|
|
|
|
echo 'node.js not found - test suite skipped' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Using [${NODE}] as a Javascript runtime"
|
|
|
|
echo 'Compiling the test suite...' && \
|
|
|
|
emmake make $MAKE_FLAGS check > /dev/null 2>&1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$BROWSER_TESTS" != "x" ]; then
|
|
|
|
echo 'Creating the test suite for web browsers'
|
|
|
|
(
|
|
|
|
cd test/default && \
|
|
|
|
mkdir -p browser-wasm && \
|
|
|
|
rm -f browser-wasm/tests.txt && \
|
|
|
|
for file in *.js; do
|
|
|
|
tname=$(echo "$file" | sed 's/.js$//')
|
2017-08-03 13:45:18 -07:00
|
|
|
if echo "$tname" | egrep -q '[.]asm$'; then
|
|
|
|
continue
|
|
|
|
fi
|
2017-03-12 09:44:29 -07:00
|
|
|
echo "[${tname}]"
|
|
|
|
fgrep -v "#! /usr/bin/env ${NODE}" "$file" > "browser-wasm/${file}"
|
|
|
|
cp -f "${tname}.exp" "browser-wasm/${tname}.exp" 2> /dev/null
|
|
|
|
cp -f "${tname}.wasm" "browser-wasm/${tname}.wasm" 2> /dev/null
|
|
|
|
cp -f "${tname}.asm.js" "browser-wasm/${tname}.asm.js" 2> /dev/null
|
|
|
|
sed "s/{{tname}}/${tname}/" index-wasm.html.tpl > "browser-wasm/${tname}.html"
|
|
|
|
echo "${tname}.html" >> "browser-wasm/tests.txt"
|
|
|
|
done
|
|
|
|
touch "$DONE_FILE"
|
|
|
|
)
|
|
|
|
else
|
|
|
|
echo 'Running the test suite'
|
|
|
|
(
|
|
|
|
cd test/default && \
|
|
|
|
for file in $(ls *.js | fgrep -v asm.js); do
|
|
|
|
echo "#! /usr/bin/env ${NODE}" > "${file}.tmp"
|
|
|
|
fgrep -v "#! /usr/bin/env ${NODE}" "$file" >> "${file}.tmp"
|
|
|
|
chmod +x "${file}.tmp"
|
|
|
|
mv -f "${file}.tmp" "$file"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
make $MAKE_FLAGS check || exit 1
|
|
|
|
touch "$DONE_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo 'Done.'
|