Skip to content

Commit

Permalink
feat(build): refactor WASM build process and introduce convenience ta…
Browse files Browse the repository at this point in the history
…rgets for WebGL and WebGPU
  • Loading branch information
theashraf committed Feb 27, 2025
1 parent ee06e8b commit 83caad5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ jobs:
env:
TARGET: wasm

- name: Build WASM (webgl)
run: |
make wasm
wasm-opt release/wasm/DotLottiePlayer.wasm -o release/wasm/DotLottiePlayer.wasm -all -Oz
make distclean
- name: Build WASM
run: make wasm

- name: Upload WASM Artifacts
uses: actions/upload-artifact@v4
Expand All @@ -120,10 +117,7 @@ jobs:
if-no-files-found: error

- name: Build WASM (webgpu)
run: |
make wasm THORVG_ENGINE=wg
wasm-opt release/wasm/DotLottiePlayer.wasm -o release/wasm/DotLottiePlayer.wasm -all -Oz
make distclean
run: make wasm-webgpu

- name: Upload WASM (webgpu) Artifacts
uses: actions/upload-artifact@v4
Expand All @@ -133,10 +127,7 @@ jobs:
if-no-files-found: error

- name: Build WASM (webgl)
run: |
make wasm THORVG_ENGINE=gl
wasm-opt release/wasm/DotLottiePlayer.wasm -o release/wasm/DotLottiePlayer.wasm -all -Oz
make distclean
run: make wasm-webgl

- name: Upload WASM (webgl) Artifacts
uses: actions/upload-artifact@v4
Expand Down
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ XCODEBUILD := xcodebuild
# Wasm
WASM := wasm
WASM_BUILD := $(BUILD)/$(WASM)
THORVG_ENGINE ?= sw # Default to software renderer, can be 'sw', 'gl', or 'wg'
THORVG_RENDERER ?= sw # Default to software renderer, can be 'sw', 'gl', or 'wg'

EMSDK := emsdk
EMSDK_DIR := $(PROJECT_DIR)/$(DEPS_MODULES_DIR)/$(EMSDK)
Expand Down Expand Up @@ -282,8 +282,8 @@ cpp_link_args = [
'--strip-all',
'--emit-tsd=${WASM_MODULE}.d.ts',
'--closure=1',
$(if $(filter $(THORVG_ENGINE),gl),'-sMAX_WEBGL_VERSION=2', '-sFULL_ES3',)\
$(if $(filter $(THORVG_ENGINE),wg),'-sUSE_WEBGPU=1',)]
$(if $(filter $(THORVG_RENDERER),gl),'-sMAX_WEBGL_VERSION=2', '-sFULL_ES3',)\
$(if $(filter $(THORVG_RENDERER),wg),'-sUSE_WEBGPU=1',)]

[host_machine]
system = '$(SYSTEM)'
Expand Down Expand Up @@ -391,7 +391,7 @@ define CARGO_BUILD
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--no-default-features \
--features thorvg_v1,thorvg_v1_$(THORVG_ENGINE) \
--features thorvg_v1,thorvg_v1_$(THORVG_RENDERER) \
--release; \
else \
IPHONEOS_DEPLOYMENT_TARGET=$(APPLE_IOS_VERSION_MIN) \
Expand All @@ -400,7 +400,7 @@ define CARGO_BUILD
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--no-default-features \
--features thorvg_v1,thorvg_v1_$(THORVG_ENGINE) \
--features thorvg_v1,thorvg_v1_$(THORVG_RENDERER) \
--release; \
fi
endef
Expand Down Expand Up @@ -502,6 +502,7 @@ define WASM_RELEASE
cp $(RUNTIME_FFI)/$(WASM_BUILD)/$(BUILD)/$(WASM_MODULE).js \
$(RELEASE)/$(WASM)/$(WASM_MODULE).mjs
cd $(RELEASE)/$(WASM) && \
wasm-opt $(WASM_MODULE).wasm -o $(WASM_MODULE).wasm -all -Oz && \
rm -f $(DOTLOTTIE_PLAYER).$(WASM).tar.gz && \
tar zcf $(DOTLOTTIE_PLAYER).$(WASM).tar.gz *
endef
Expand Down Expand Up @@ -678,7 +679,7 @@ endef

define NEW_WASM_DEPS_BUILD
$(eval $(call NEW_WASM_CROSS_FILE,$1,$$($1_THORVG_DEP_BUILD_DIR)/..,emscripten))
$(eval $(call NEW_THORVG_BUILD,$1,false,true,"lottie_expressions",false,$(THORVG_ENGINE)))
$(eval $(call NEW_THORVG_BUILD,$1,false,true,"lottie_expressions",false,$(THORVG_RENDERER)))
endef

define NEW_ANDROID_BUILD
Expand Down Expand Up @@ -974,6 +975,16 @@ $(WASM):
@$(MAKE) $(WASM_BUILD_TARGETS)
@$(MAKE) post-make-wasm

.PHONY: wasm-webgl
wasm-webgl:
@$(MAKE) distclean
@$(MAKE) wasm THORVG_RENDERER=gl

.PHONY: wasm-webgpu
wasm-webgpu:
@$(MAKE) distclean
@$(MAKE) wasm THORVG_RENDERER=wg

.PHONY: $(NATIVE)
$(NATIVE): $(RUNTIME_FFI)/target/$(RELEASE)/$(RUNTIME_FFI_LIB)
$(NATIVE_RELEASE)
Expand Down Expand Up @@ -1065,6 +1076,10 @@ help:
@echo "Use the $(YELLOW)wasm$(NC) target to build all wasm targets."
@echo " - THORVG_ENGINE can be 'sw' (default), 'gl', or 'wg'"
@echo " - Example: make wasm THORVG_ENGINE=gl"
@echo
@echo "Convenience targets for clean WASM builds:"
@echo " - $(YELLOW)wasm-webgl$(NC) - runs distclean and builds WASM with WebGL renderer"
@echo " - $(YELLOW)wasm-webgpu$(NC) - runs distclean and builds WASM with WebGPU renderer"
@echo "$(GREEN)-------------------------------------------------------------------------------------------------$(NC)"
@echo
@echo "The following are make targets you might also find useful:"
Expand Down

0 comments on commit 83caad5

Please sign in to comment.