Skip to content

Commit

Permalink
[Wasm] Made BuildWasm.sh script compatible with Mac.
Browse files Browse the repository at this point in the history
- Added wrapper for 'realpath' command, which is not availbale on macOS.
- Made 'sed' command compatible between Linux and macOS.
- Replaced 'readarray' command with 'cat' and for-loop.
  • Loading branch information
LukasBanana committed Aug 27, 2024
1 parent 97f4868 commit 0186a1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 18 additions & 9 deletions BuildWasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,26 @@ if [ ! -d "$OUTPUT_DIR" ]; then
mkdir "$OUTPUT_DIR"
fi

# Wrapper for 'realpath' when it's not available (like on macOS)
get_realpath()
{
if command -v realpath &> /dev/null; then
echo $(realpath "$1")
else
echo "$1"
fi
}

# Checkout external depenencies
GAUSSIAN_LIB_DIR="GaussianLib/include"

if [ -f "$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR/Gauss/Gauss.h" ]; then
GAUSSIAN_LIB_DIR=$(realpath "$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR")
GAUSSIAN_LIB_DIR=$(get_realpath "$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR")
else
if [ ! -d "$OUTPUT_DIR/$GAUSSIAN_LIB_DIR" ]; then
(cd "$OUTPUT_DIR" && git clone https://github.com/LukasBanana/GaussianLib.git)
fi
GAUSSIAN_LIB_DIR=$(realpath "$OUTPUT_DIR/$GAUSSIAN_LIB_DIR")
GAUSSIAN_LIB_DIR=$(get_realpath "$OUTPUT_DIR/$GAUSSIAN_LIB_DIR")
fi

# Print additional information if in verbose mode
Expand Down Expand Up @@ -161,29 +171,28 @@ generate_html5_page()
# Create folder structure
mkdir -p "$HTML5_ROOT"
BASE_FILENAME="Example_$CURRENT_PROJECT"
cp "$SOURCE_DIR/examples/Cpp/ExampleBase/Wasm/index.html" "$HTML5_ROOT/index.html"
cp "$BIN_ROOT/$BASE_FILENAME.js" "$HTML5_ROOT/$BASE_FILENAME.js"
cp "$BIN_ROOT/$BASE_FILENAME.wasm" "$HTML5_ROOT/$BASE_FILENAME.wasm"
if [ $ENABLE_PTHREADS = "ON" ]; then
cp "$BIN_ROOT/$BASE_FILENAME.worker.js" "$HTML5_ROOT/$BASE_FILENAME.worker.js"
fi

# Replace meta data
sed -i "s/LLGL_EXAMPLE_NAME/${CURRENT_PROJECT}/" "$HTML5_ROOT/index.html"
sed -i "s/LLGL_EXAMPLE_PROJECT/Example_${CURRENT_PROJECT}/" "$HTML5_ROOT/index.html"
sed -e "s/LLGL_EXAMPLE_NAME/${CURRENT_PROJECT}/g" \
-e "s/LLGL_EXAMPLE_PROJECT/Example_${CURRENT_PROJECT}/g" \
"$SOURCE_DIR/examples/Cpp/ExampleBase/Wasm/index.html" > "$HTML5_ROOT/index.html"

# Find all required assets in Android.assets.txt file of respective project directory and copy them into app folder
ASSET_DIR="$HTML5_ROOT/assets"
mkdir -p "$ASSET_DIR"

ASSET_LIST_FILE="$PROJECT_SOURCE_DIR/Android.assets.txt"
if [ -f "$ASSET_LIST_FILE" ]; then
# Read Android.asset.txt file line-by-line into array and make sure '\r' character is not present (on Win32 platform)
readarray -t ASSET_FILTERS < <(tr -d '\r' < "$ASSET_LIST_FILE")
# Read asset filenames to copy to package output
ASSET_FILES=()
for FILTER in ${ASSET_FILTERS[@]}; do
for FILTER in $(cat $ASSET_LIST_FILE); do
for FILE in $ASSET_SOURCE_DIR/$FILTER; do
ASSET_FILES+=( "$FILE" )
ASSET_FILES+=( $(echo "$FILE" | tr -d '\r') ) # Remove '\r' characters when reading .txt file from WSL
done
done

Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/Wasm/WasmCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <LLGL/Display.h>
#include "../../Core/CoreUtils.h"

#include <LLGL/Log.h>


namespace LLGL
{
Expand Down

0 comments on commit 0186a1d

Please sign in to comment.