mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 22:40:01 -04:00
Merge branch 'main' into wolfssl-testing
This commit is contained in:
commit
b49d677686
37 changed files with 1131 additions and 273 deletions
|
@ -2,53 +2,93 @@
|
|||
|
||||
set -e
|
||||
|
||||
INCLUDE_DIR="build/curl-wasm/include/"
|
||||
LIB_DIR="build/curl-wasm/lib/"
|
||||
OUT_FILE="out/libcurl.js"
|
||||
ES6_FILE="out/libcurl_module.mjs"
|
||||
MODULE_FILE="out/emscripten_compiled.js"
|
||||
#path definitions
|
||||
OUT_DIR="${OUT_DIR:=out}"
|
||||
BUILD_DIR="build"
|
||||
C_DIR="libcurl"
|
||||
FRAGMENTS_DIR="fragments"
|
||||
WRAPPER_SOURCE="main.js"
|
||||
JAVSCRIPT_DIR="javascript"
|
||||
WISP_CLIENT="wisp_client"
|
||||
|
||||
EXPORTED_FUNCS="_init_curl,_start_request,_tick_request,_active_requests"
|
||||
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
|
||||
COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lwolfssl -lcjson -lz -lbrotlidec -lbrotlicommon -I $INCLUDE_DIR -L $LIB_DIR"
|
||||
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sASSERTIONS=1 -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
|
||||
INCLUDE_DIR="$BUILD_DIR/curl-wasm/include/"
|
||||
LIB_DIR="$BUILD_DIR/curl-wasm/lib/"
|
||||
OUT_FILE="$OUT_DIR/libcurl.js"
|
||||
ES6_FILE="$OUT_DIR/libcurl.mjs"
|
||||
MODULE_FILE="$OUT_DIR/emscripten_compiled.js"
|
||||
COMPILED_FILE="$OUT_DIR/emscripten_compiled.wasm"
|
||||
WASM_FILE="$OUT_DIR/libcurl.wasm"
|
||||
|
||||
if [ "$1" = "release" ]; then
|
||||
#read exported functions
|
||||
EXPORTED_FUNCS=""
|
||||
for func in $(cat exported_funcs.txt); do
|
||||
EXPORTED_FUNCS="$EXPORTED_FUNCS,_$func"
|
||||
done
|
||||
EXPORTED_FUNCS="${EXPORTED_FUNCS:1}"
|
||||
|
||||
#compile options
|
||||
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
|
||||
COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lwolfssl -lcjson -lz -lbrotlidec -lbrotlicommon -lnghttp2 -I $INCLUDE_DIR -L $LIB_DIR"
|
||||
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sENVIRONMENT=worker,web -sASSERTIONS=1 -sLLD_REPORT_UNDEFINED -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
|
||||
|
||||
#clean output dir
|
||||
rm -rf $OUT_DIR
|
||||
mkdir -p $OUT_DIR
|
||||
|
||||
if [[ "$*" == *"all"* ]]; then
|
||||
mkdir -p $OUT_DIR/release
|
||||
mkdir -p $OUT_DIR/single_file
|
||||
OUT_DIR=$OUT_DIR/release ./build.sh release
|
||||
OUT_DIR=$OUT_DIR/single_file ./build.sh release single_file
|
||||
mv $OUT_DIR/release/* $OUT_DIR
|
||||
mv $OUT_DIR/single_file/* $OUT_DIR
|
||||
rm -rf $OUT_DIR/release
|
||||
rm -rf $OUT_DIR/single_file
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$*" == *"release"* ]]; then
|
||||
COMPILER_OPTIONS="-Oz -flto $COMPILER_OPTIONS"
|
||||
EMSCRIPTEN_OPTIONS="-sSINGLE_FILE $EMSCRIPTEN_OPTIONS"
|
||||
echo "note: building with release optimizations"
|
||||
else
|
||||
COMPILER_OPTIONS="$COMPILER_OPTIONS --profiling -g"
|
||||
fi
|
||||
|
||||
if [[ "$*" == *"single_file"* ]]; then
|
||||
EMSCRIPTEN_OPTIONS="-sSINGLE_FILE $EMSCRIPTEN_OPTIONS"
|
||||
OUT_FILE="$OUT_DIR/libcurl_full.js"
|
||||
ES6_FILE="$OUT_DIR/libcurl_full.mjs"
|
||||
echo "note: building as a single js file"
|
||||
fi
|
||||
|
||||
#ensure deps are compiled
|
||||
tools/all_deps.sh
|
||||
tools/generate_cert.sh
|
||||
|
||||
#clean output dir
|
||||
rm -rf out
|
||||
mkdir -p out
|
||||
|
||||
#compile the main c file - but only if the source has been modified
|
||||
COMPILE_CMD="emcc main.c $COMPILER_OPTIONS $EMSCRIPTEN_OPTIONS"
|
||||
#compile the main c file
|
||||
COMPILE_CMD="emcc $C_DIR/*.c $COMPILER_OPTIONS $EMSCRIPTEN_OPTIONS"
|
||||
echo $COMPILE_CMD
|
||||
$COMPILE_CMD
|
||||
mv $COMPILED_FILE $WASM_FILE || true
|
||||
|
||||
#merge compiled emscripten module and wrapper code
|
||||
cp $WRAPPER_SOURCE $OUT_FILE
|
||||
cp $JAVSCRIPT_DIR/main.js $OUT_FILE
|
||||
sed -i "/__emscripten_output__/r $MODULE_FILE" $OUT_FILE
|
||||
rm $MODULE_FILE
|
||||
|
||||
#add wisp libraries
|
||||
#add version number and copyright notice
|
||||
VERSION=$(cat package.json | jq -r '.version')
|
||||
sed -i "s/__library_version__/$VERSION/" $OUT_FILE
|
||||
|
||||
#add extra libraries
|
||||
sed -i "/__extra_libraries__/r $WISP_CLIENT/polyfill.js" $OUT_FILE
|
||||
sed -i "/__extra_libraries__/r $WISP_CLIENT/wisp.js" $OUT_FILE
|
||||
sed -i "/__extra_libraries__/r ./messages.js" $OUT_FILE
|
||||
sed -i "/__extra_libraries__/r $JAVSCRIPT_DIR/messages.js" $OUT_FILE
|
||||
sed -i "/__extra_libraries__/r $JAVSCRIPT_DIR/websocket.js" $OUT_FILE
|
||||
sed -i "/__extra_libraries__/r $JAVSCRIPT_DIR/copyright.js" $OUT_FILE
|
||||
|
||||
#apply patches
|
||||
python3 patcher.py $FRAGMENTS_DIR $OUT_FILE
|
||||
python3 tools/patch_js.py $FRAGMENTS_DIR $OUT_FILE
|
||||
|
||||
#generate es6 module
|
||||
cp $OUT_FILE $ES6_FILE
|
||||
sed -i 's/window.libcurl/export const libcurl/' $ES6_FILE
|
||||
sed -i 's/const libcurl = /export const libcurl = /' $ES6_FILE
|
Loading…
Add table
Add a link
Reference in a new issue