Skip to content

Commit

Permalink
emscripten build adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
neodix42 committed Nov 26, 2024
1 parent 657773f commit a694e21
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions CMake/BuildSECP256K1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ if (NOT SECP256K1_LIBRARY)
OUTPUT ${SECP256K1_LIBRARY}
)
elseif (EMSCRIPTEN)
set(SECP256K1_LIBRARY ${SECP256K1_BINARY_DIR}/lib/libsecp256k1.a)
set(SECP256K1_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/secp256k1)
set(SECP256K1_LIBRARY ${SECP256K1_BINARY_DIR}/.libs/libsecp256k1.a)
set(SECP256K1_INCLUDE_DIR ${SECP256K1_SOURCE_DIR}/include)
add_custom_command(
WORKING_DIRECTORY ${SECP256K1_SOURCE_DIR}
COMMAND ./autogen.sh
COMMAND emconfigure ./configure --enable-module-recovery --enable-module-extrakeys --prefix ${SECP256K1_BINARY_DIR}
COMMAND emconfigure ./configure --enable-module-recovery --enable-module-extrakeys --disable-tests --disable-benchmark
COMMAND emmake make clean
COMMAND emmake make
COMMAND emmake make install
COMMENT "Build Secp256k1 with emscripten"
DEPENDS ${SECP256K1_SOURCE_DIR}
OUTPUT ${SECP256K1_LIBRARY}
Expand All @@ -46,7 +47,6 @@ if (NOT SECP256K1_LIBRARY)
)
endif()
endif()

else()
message(STATUS "Use Secp256k1: ${SECP256K1_LIBRARY}")
endif()
Expand Down
23 changes: 9 additions & 14 deletions assembly/wasm/fift-func-wasm-build-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export CCACHE_DISABLE=1
echo `pwd`
if [ "$scratch_new" = true ]; then
echo Compiling openssl zlib lz4 emsdk libsodium emsdk ton
rm -rf openssl zlib lz4 emsdk libsodium build
rm -rf openssl zlib lz4 emsdk libsodium build openssl_em
fi


if [ ! -d "openssl" ]; then
git clone https://github.com/openssl/openssl.git
cp -r openssl openssl_em
cd openssl
git checkout openssl-3.1.4
./config
Expand All @@ -44,11 +45,6 @@ else
echo Using compiled openssl at $OPENSSL_DIR
fi

cd third-party/secp256k1
make clean
rm -rf .libs lib build
cd ../..

if [ ! -d "build" ]; then
mkdir build
cd build
Expand All @@ -75,8 +71,8 @@ echo
fi

cd emsdk
./emsdk install 3.1.19
./emsdk activate 3.1.19
./emsdk install 3.1.40
./emsdk activate 3.1.40
EMSDK_DIR=`pwd`

. $EMSDK_DIR/emsdk_env.sh
Expand All @@ -86,20 +82,21 @@ export CCACHE_DISABLE=1

cd ..

if [ ! -f "openssl/openssl_em" ]; then
cd openssl
make clean
if [ ! -f "openssl_em/openssl_em" ]; then
cd openssl_em
emconfigure ./Configure linux-generic32 no-shared no-dso no-engine no-unit-test no-tests no-fuzz-afl no-fuzz-libfuzzer
sed -i 's/CROSS_COMPILE=.*/CROSS_COMPILE=/g' Makefile
sed -i 's/-ldl//g' Makefile
sed -i 's/-O3/-Os/g' Makefile
emmake make depend
emmake make -j16
test $? -eq 0 || { echo "Can't compile OpenSSL with emmake "; exit 1; }
OPENSSL_DIR=`pwd`
touch openssl_em
cd ..
else
echo Using compiled openssl with emscripten
OPENSSL_DIR=`pwd`/openssl_em
echo Using compiled with empscripten openssl at $OPENSSL_DIR
fi

if [ ! -d "zlib" ]; then
Expand Down Expand Up @@ -183,5 +180,3 @@ if [ "$with_artifacts" = true ]; then
cp -R crypto/smartcont artifacts
cp -R crypto/fift/lib artifacts
fi


7 changes: 5 additions & 2 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,22 @@ target_include_directories(ton_crypto PRIVATE ${BLST_INCLUDE_DIR})
target_link_libraries(ton_crypto PRIVATE ${BLST_LIB})

target_include_directories(ton_crypto_core PUBLIC $<BUILD_INTERFACE:${SECP256K1_INCLUDE_DIR}>)
target_link_libraries(ton_crypto_core PUBLIC ${SECP256K1_LIBRARY})
target_link_libraries(ton_crypto PUBLIC ${SECP256K1_LIBRARY})

if (MSVC)
find_package(Sodium REQUIRED)
target_compile_definitions(ton_crypto PUBLIC SODIUM_STATIC)
elseif (EMSCRIPTEN)
target_link_libraries(ton_crypto_core PUBLIC $<BUILD_INTERFACE:${SECP256K1_LIBRARY}>)
target_link_libraries(ton_crypto PUBLIC $<BUILD_INTERFACE:${SECP256K1_LIBRARY}>)
else()
if (NOT SODIUM_FOUND)
find_package(Sodium REQUIRED)
else()
message(STATUS "Using Sodium ${SODIUM_LIBRARY_RELEASE}")
endif()
target_compile_definitions(ton_crypto PUBLIC SODIUM_STATIC)
target_link_libraries(ton_crypto_core PUBLIC ${SECP256K1_LIBRARY})
target_link_libraries(ton_crypto PUBLIC ${SECP256K1_LIBRARY})
endif()

target_include_directories(ton_crypto_core PUBLIC $<BUILD_INTERFACE:${SODIUM_INCLUDE_DIR}>)
Expand Down

0 comments on commit a694e21

Please sign in to comment.