Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with Emscripten for WebAssembly #6

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/emsdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build InfiniSim LVGL Simulator using emscripten
# Run on all branches
push:
branches: []

# Also run this Workflow when a Pull Request is created or updated in the "main" and "develop" Branch
pull_request:
branches: [ main, develop ]

jobs:
emscripten:
runs-on: ubuntu-latest
steps:

#########################################################################################
# Download and Install Dependencies

- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
with:
# Make sure to set a version number!
version: 3.1.8
# This is the name of the cache folder.
# The cache folder will be placed in the build directory,
# so make sure it doesn't conflict with anything!
actions-cache-folder: 'emsdk-cache'

- name: Tell emsdk to use SDL with pthread proxy fix
run: sed -i -e "s/^TAG =.*/TAG = 'ea7d5307acfb1daf9af6104b60b75114b15bcd27'/" -e "s/HASH =.*/HASH = 'b7d58124f0d1145f23338abfdb6aa07855ac74ed80b3a5b613d23b4930c84d04d1794a62aab2ca2680ba369128ee2028ea51236fab4aaf70556036172fa59e6a'/" emsdk-cache/upstream/emscripten/tools/ports/sdl2.py

- name: Verify
run: emcc -v

- name: Install cmake
uses: lukka/[email protected]

#########################################################################################
# Checkout

- name: Checkout source files
uses: actions/checkout@v2
with:
submodules: recursive

#########################################################################################
# CMake

- name: CMake
run: |
emcmake cmake -S . -B build_em -DCMAKE_BUILD_TYPE=Release

#########################################################################################
# Build and Upload simulator wasm files

- name: Build simulator executable
run: |
cmake --build build_lv_sim

- name: Upload simulator executable
uses: actions/upload-artifact@v3
with:
name: infinisim_emscripten
path: |
build_em/infinisim.html
build_em/infinisim.js
build_em/infinisim.wasm
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "InfiniTime"]
path = InfiniTime
url = ../../InfiniTimeOrg/InfiniTime.git
url = ../../NeroBurner/InfiniTime.git
[submodule "lv_drivers"]
path = lv_drivers
url = ../../lvgl/lv_drivers.git
Expand Down
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,30 @@ target_sources(infinisim PUBLIC
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Special case for SDL2 dependency, goal is to find a config that exports SDL2::SDL2 target
# libsdl2-dev has a `sdl2-config.cmake` that doesn't export this, but vcpkg does..
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
# emcmake cmake -S . -B _build_em
set(USE_FLAGS "-s USE_PTHREADS=1 -pthread")
set(USE_FLAGS "${USE_FLAGS} -s USE_SDL=2")
set(USE_FLAGS "${USE_FLAGS} -fwasm-exceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s PTHREAD_POOL_SIZE=4 -s PROXY_TO_PTHREAD=1")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s INITIAL_MEMORY=30736384") # 30MB memory
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ABORTING_MALLOC=0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORTED_RUNTIME_METHODS=[\"printErr\"]")
set(CMAKE_EXECUTABLE_SUFFIX .html)
target_include_directories(infinisim PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(infinisim PRIVATE ${SDL2_LIBRARIES})
#set_target_properties(infinisim PROPERTIES LINK_FLAGS "--shell-file ${PROJECT_SOURCE_DIR}/lvgl_shell.html")
else()
find_package(SDL2 CONFIG QUIET)
if(NOT TARGET SDL2::SDL2)
find_package(SDL2 MODULE REQUIRED)
endif()
target_link_libraries(infinisim PRIVATE SDL2::SDL2)
endif()

# Get the latest abbreviated commit hash of the working branch
execute_process(
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ class Framework {
int main(int argc, char **argv)
{
// parse arguments
bool fw_status_window_visible = true;
bool fw_status_window_visible = false;
bool arg_help = false;
for (int i=1; i<argc; i++)
{
Expand Down