Skip to content

Commit

Permalink
remove scripts and run compilation directly in Containerfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Dec 22, 2023
1 parent d7d1344 commit 7e1c425
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 65 deletions.
48 changes: 45 additions & 3 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,54 @@ RUN apt-get update \
build-essential

COPY submodules/libsecp256k1 /app
COPY scripts/compile.sh /app
COPY scripts/exported_functions /app

WORKDIR /app

RUN ./compile.sh
# expose sha256 from libsecp256k1
RUN sed -i 's/static \(void secp256k1_sha256_\(initialize\|write\|finalize\)\)/\1/' src/hash_impl.h
RUN sed -i 's/static \(void secp256k1_sha256_\(initialize\|write\|finalize\)\)/extern \1/' src/hash.h

# workaround for <https://github.com/emscripten-core/emscripten/issues/13551>
RUN echo '{"type":"commonjs"}' > package.json

# autogen
RUN ./autogen.sh

# configure
RUN emconfigure ./configure \
--enable-module-schnorrsig=yes\
--enable-module-extrakeys=yes \
--with-ecmult-window=4 \
--with-ecmult-gen-precision=2 \
--disable-shared \
CFLAGS="-fdata-sections -ffunction-sections -O2" \
LDFLAGS="-Wl,--gc-sections"

# make
RUN emmake make FORMAT=wasm
RUN emmake make src/precompute_ecmult-precompute_ecmult FORMAT=wasm

# reset output dir
RUN rm -rf out
RUN mkdir -p out

# compile
RUN emcc src/precompute_ecmult-precompute_ecmult.o \
src/libsecp256k1_precomputed_la-precomputed_ecmult.o \
src/libsecp256k1_precomputed_la-precomputed_ecmult_gen.o \
src/libsecp256k1_la-secp256k1.o \
-O3 \
-s WASM=1 \
-s TOTAL_MEMORY=1mb \
-s "BINARYEN_METHOD='native-wasm'" \
-s DETERMINISTIC=1 \
-s EXPORTED_FUNCTIONS="_malloc _free _secp256k1_context_create _secp256k1_keypair_create _secp256k1_keypair_xonly_pub _secp256k1_xonly_pubkey_parse _secp256k1_xonly_pubkey_serialize _secp256k1_schnorrsig_sign32 _secp256k1_schnorrsig_verify _secp256k1_sha256_initialize _secp256k1_sha256_write _secp256k1_sha256_finalize" \
-s MINIMAL_RUNTIME=1 \
-s NO_EXIT_RUNTIME=1 \
-o out/secp256k1.js

# verify
RUN ls -la out/

# copy outputs to mounted volume
CMD ["cp", "-r", "/app/out", "/out"]
Binary file modified bun.lockb
Binary file not shown.
50 changes: 0 additions & 50 deletions scripts/compile.sh

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/exported_functions

This file was deleted.

0 comments on commit 7e1c425

Please sign in to comment.