Skip to content

Commit

Permalink
chore(ci): run wasm build on ubuntu instead of macos
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf committed Dec 12, 2024
1 parent ba1c5e1 commit 9f8a73a
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 18 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/check-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ on:
pull_request:
branches: [main]
push:
branches: [main]
branches: [main, chore/ci-wasm-build]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-wasm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Setup
run: make linux-setup
- name: Build WASM
run: make wasm
- name: Upload WASM Artifacts
uses: actions/upload-artifact@v4
with:
name: dotlottie-player.wasm.tar.gz
path: release/wasm/dotlottie-player.wasm.tar.gz
if-no-files-found: error
check-pr:
if: github.head_ref != 'release'
runs-on: ubuntu-latest
Expand Down
100 changes: 100 additions & 0 deletions .linux-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env bash

SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"

RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
GREEN=$(tput setaf 2)
WHITE=$(tput setaf 15)
NC=$(tput sgr0)

EMSDK_VERSION=${EMSDK_VERSION:-latest}
UNIFFI_BINDGEN_CPP_VERSION=${UNIFFI_BINDGEN_CPP_VERSION:-"v0.6.3+v0.25.0"}

die() { printf %s "${@+$@$'\n'}" 1>&2 ; exit 1; }

check_for() {
local -r app=$1
local install_cmd=$2

echo "Checking for ${GREEN}${app}${NC} ..."
if ! which "${app}" &>/dev/null; then
echo "${RED}=>${NC} Could not find ${app}, installing..."
if [ -z "$install_cmd" ]; then
echo "${RED}No installation command provided for ${app}${NC}"
exit 1
fi
eval "$install_cmd" || die "Failed to install ${app}"
fi
}

if [ -f /etc/debian_version ]; then
PKG_MANAGER="apt-get"
PKG_UPDATE="sudo apt-get update"
INSTALL_CMD="sudo apt-get install -y"
elif [ -f /etc/fedora-release ]; then
PKG_MANAGER="dnf"
PKG_UPDATE="sudo dnf check-update"
INSTALL_CMD="sudo dnf install -y"
else
echo "${RED}Unsupported Linux distribution${NC}"
exit 1
fi

echo "Updating package manager..."
eval "$PKG_UPDATE"

echo "Installing basic dependencies..."
$INSTALL_CMD \
build-essential \
cmake \
pkg-config \
ninja-build \
python3-pip \
nasm \
git \
curl \
wget

echo "Installing Meson 1.6.0..."
pip3 install 'meson==1.6.0'

check_for rustup "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"

source "$HOME/.cargo/env"

echo
echo "Installing rust target ..."
rustup target add wasm32-unknown-emscripten

echo
echo "Setting up project ..."
make deps

echo "Installing nightly toolchain"
rustup install nightly
rustup component add rust-src --toolchain nightly
rustup target add wasm32-unknown-emscripten --toolchain nightly

echo
echo "Installing cargo dependencies"
cargo install uniffi-bindgen-cpp \
--git https://github.com/NordSecurity/uniffi-bindgen-cpp \
--tag "${UNIFFI_BINDGEN_CPP_VERSION}"

echo
echo "Setting up emsdk"
cd "${SCRIPT_DIR}/deps/modules/emsdk" || die "Could not find Emscripten SDK under ${RED}deps/modules/emsdk${NC}!"
./emsdk install "${EMSDK_VERSION}"
./emsdk activate "${EMSDK_VERSION}"
source ./emsdk_env.sh
cd "${SCRIPT_DIR}/deps/modules/emsdk/upstream/emscripten" || die "Could not find Emscripten under ${RED}deps/modules/emsdk/upstream/emscripten${NC}!"
npm install
cd "${SCRIPT_DIR}" || die "Could not find project root directory!"

echo
echo "Disabling unneeded webp features"
cd "${SCRIPT_DIR}/deps/modules/libwebp" || die "Could not find libwebp under ${RED}deps/modules/libwep${NC}!"
file_path="${SCRIPT_DIR}/deps/modules/libwebp/CMakeLists.txt"
sed -i 's/option(WEBP_BUILD_ANIM_UTILS "Build animation utilities." ON)/option(WEBP_BUILD_ANIM_UTILS "Build animation utilities." OFF)/' "$file_path"
sed -i 's/option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." ON)/option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." OFF)/' "$file_path"
44 changes: 27 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,22 @@ define SIMPLE_CARGO_BUILD
endef

define CARGO_BUILD
if [ "$(CARGO_TARGET)" = "wasm32-unknown-emscripten" ]; then \
source $(EMSDK_DIR)/$(EMSDK)_env.sh && \
RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build \
-Z build-std=std,panic_abort \
-Z build-std-features="panic_immediate_abort,optimize_for_size" \
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--release; \
else \
IPHONEOS_DEPLOYMENT_TARGET=$(APPLE_IOS_VERSION_MIN) \
MACOSX_DEPLOYMENT_TARGET=$(APPLE_MACOS_VERSION_MIN) \
cargo build \
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--release; \
fi
if [ "$(CARGO_TARGET)" = "wasm32-unknown-emscripten" ]; then \
. $(EMSDK_DIR)/$(EMSDK)_env.sh && \
RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build \
-Z build-std=std,panic_abort \
-Z build-std-features="panic_immediate_abort,optimize_for_size" \
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--release; \
else \
IPHONEOS_DEPLOYMENT_TARGET=$(APPLE_IOS_VERSION_MIN) \
MACOSX_DEPLOYMENT_TARGET=$(APPLE_MACOS_VERSION_MIN) \
cargo build \
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--release; \
fi
endef

define UNIFFI_BINDINGS_BUILD
Expand All @@ -415,7 +415,11 @@ define UNIFFI_BINDINGS_CPP_BUILD
--config $(RUNTIME_FFI)/uniffi.toml \
--out-dir $(RUNTIME_FFI)/$(RUNTIME_FFI_UNIFFI_BINDINGS)/$(CPLUSPLUS) \
$(RUNTIME_FFI)/src/dotlottie_player_cpp.udl
sed -i .bak 's/uint8_t/char/g' $(RUNTIME_FFI)/$(RUNTIME_FFI_UNIFFI_BINDINGS)/$(CPLUSPLUS)/*
if [ "$(BUILD_PLATFORM)" = "$(DARWIN)" ]; then \
sed -i .bak 's/uint8_t/char/g' $(RUNTIME_FFI)/$(RUNTIME_FFI_UNIFFI_BINDINGS)/$(CPLUSPLUS)/*; \
else \
sed -i 's/uint8_t/char/g' $(RUNTIME_FFI)/$(RUNTIME_FFI_UNIFFI_BINDINGS)/$(CPLUSPLUS)/*; \
fi
cp $(RUNTIME_FFI)/emscripten_bindings.cpp $(RUNTIME_FFI)/$(RUNTIME_FFI_UNIFFI_BINDINGS)/$(CPLUSPLUS)/.
endef

Expand Down Expand Up @@ -1003,6 +1007,12 @@ mac-setup: export UNIFFI_BINDGEN_CPP_VERSION:= $(UNIFFI_BINDGEN_CPP_VERSION)
mac-setup:
@./.$@.sh

.PHONY: linux-setup
linux-setup: export EMSDK_VERSION := $(EMSDK_VERSION)
linux-setup: export UNIFFI_BINDGEN_CPP_VERSION:= $(UNIFFI_BINDGEN_CPP_VERSION)
linux-setup:
@./.$@.sh

.PHONY: test
test: test-all

Expand Down

0 comments on commit 9f8a73a

Please sign in to comment.