Skip to content
Open
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
71 changes: 43 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ on:
- main
pull_request:

env:
EM_VERSION: 4.0.8
EM_CACHE_FOLDER: 'emsdk-cache'

jobs:
build:
name: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/setup-python@v1
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
submodules: true

- name: install packages (linux)
run: |
sudo apt-get update
Expand All @@ -38,7 +42,7 @@ jobs:
if: matrix.os == 'windows-latest'

- name: download sdl2 (windows)
uses: albin-johansson/download-sdl2@v1
uses: albin-johansson/download-sdl2@v2
with:
version: 2.0.14
sources_destination: .
Expand All @@ -65,35 +69,46 @@ jobs:
python scripts/tester.py -vv --exe bin/binjgb-tester
if: matrix.os != 'windows-latest'

build-wasm:
name: build-wasm
build-wasm-variants:
name: build-${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [wasm, rgbds-live, gbstudio]
include:
- target: wasm
cmake_flags: ""
- target: rgbds-live
cmake_flags: '-DWERROR=ON -DTHIRDPARTY_HOOKS=ON -DCMAKE_C_FLAGS="-DBREAKPOINTS_MAX_BANKS_NUMBER=256"'
- target: gbstudio
cmake_flags: "-DWERROR=ON -DGBSTUDIO=ON"

steps:
- uses: actions/checkout@v1
with:
submodules: true
- uses: actions/checkout@v4
with:
submodules: true

- name: install packages
run: sudo apt-get install ninja-build
- name: install packages
run: sudo apt-get install ninja-build

- name: emsdk install
run: |
mkdir $HOME/emsdk
git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk
$HOME/emsdk/emsdk update-tags
$HOME/emsdk/emsdk install tot
$HOME/emsdk/emsdk activate tot
- name: setup cache
uses: actions/cache@v4
with:
path: ${{ env.EM_CACHE_FOLDER }}
key: ${{ env.EM_VERSION }}-${{ runner.os }}

- name: update path
run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV
- name: emsdk install
uses: mymindstorm/setup-emsdk@v14
with:
version: ${{ env.EM_VERSION }}
actions-cache-folder: ${{ env.EM_CACHE_FOLDER }}

- name: mkdir
run: mkdir -p out
- name: mkdir
run: mkdir -p out

- name: cmake
run: cmake -S . -B out -G Ninja -DCMAKE_TOOLCHAIN_FILE=$HOME/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -DWASM=true
- name: cmake
run: emcmake cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DWASM=true ${{ matrix.cmake_flags }}

- name: build
run: |
source $HOME/emsdk/emsdk_env.sh
cmake --build out
- name: build
run: emmake cmake --build out
49 changes: 28 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,43 +143,50 @@ else (EMSCRIPTEN)
add_executable(binjgb
src/memory.c
src/common.c
src/emulator.c
src/joypad.c
src/rewind.c
src/emscripten/wrapper.c)
set(EXPORTED_JSON ${PROJECT_SOURCE_DIR}/src/emscripten/exported.json)
target_include_directories(binjgb PUBLIC ${PROJECT_SOURCE_DIR}/src)

if (RGBDS_LIVE)
target_compile_definitions(binjgb PUBLIC RGBDS_LIVE)
endif ()
set(BINJGB_THIRDPARTY_HOOKS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/src/emscripten/thirdparty-default-hooks.c"
CACHE FILEPATH "Path to the emulator hooks implementation file")

if (GBSTUDIO)
# If GBSTUDIO is set, set RGBDS_LIVE too
target_compile_definitions(binjgb PUBLIC GBSTUDIO RGBDS_LIVE)
set(THIRDPARTY_HOOKS ON)
target_compile_definitions(binjgb PUBLIC GBSTUDIO)
endif ()

set(LINK_FLAGS
-s EXPORTED_FUNCTIONS=\"@${EXPORTED_JSON}\"
-s MALLOC=emmalloc
-s ASSERTIONS=0
-s ENVIRONMENT=web
-s FILESYSTEM=0
-s EXIT_RUNTIME=0
-s MODULARIZE=1
-s EXPORT_NAME="Binjgb"
)
if (THIRDPARTY_HOOKS)
target_sources(binjgb PRIVATE ${BINJGB_THIRDPARTY_HOOKS_FILE})
else()
target_sources(binjgb PRIVATE src/emulator.c)
endif()

if(NOT BINJGB_LINKER_OPTIONS)
set(BINJGB_LINKER_OPTIONS
-sMALLOC=emmalloc
-sASSERTIONS=0
-sENVIRONMENT=web
-sFILESYSTEM=0
-sEXIT_RUNTIME=0
-sMODULARIZE=1
-sEXPORT_NAME=Binjgb
)
endif()

if (WASM)
set(LINK_FLAGS ${LINK_FLAGS} -s WASM=1)
else ()
set(LINK_FLAGS ${LINK_FLAGS} -s WASM=0)
list(APPEND BINJGB_LINKER_OPTIONS -sWASM=1)
else()
list(APPEND BINJGB_LINKER_OPTIONS -sWASM=0)
endif ()

string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
list(APPEND BINJGB_LINKER_OPTIONS -sEXPORTED_FUNCTIONS=@${EXPORTED_JSON})

target_link_options(binjgb PRIVATE ${BINJGB_LINKER_OPTIONS})

set_target_properties(binjgb
PROPERTIES
LINK_FLAGS "${LINK_FLAGS_STR}"
LINK_DEPENDS "${EXPORTED_JSON}"
)
endif ()
2 changes: 1 addition & 1 deletion scripts/build_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def BuildWlaGb():
Run('cmake', '-G', 'NMake Makefiles', '-DCMAKE_BUILD_TYPE=Release', WLA_DX_DIR, cwd=WLA_DX_BUILD_DIR)
Run('nmake', cwd=WLA_DX_BUILD_DIR)
else:
Run('cmake', WLA_DX_DIR, cwd=WLA_DX_BUILD_DIR)
Run('cmake', '-DCMAKE_POLICY_VERSION_MINIMUM=3.5', '-DCMAKE_C_FLAGS=-Wno-strict-prototypes', WLA_DX_DIR, cwd=WLA_DX_BUILD_DIR)
Run('make', cwd=WLA_DX_BUILD_DIR)
# Test that wla-gb was build OK.
Run(os.path.join(WLA_DX_BIN_DIR, 'wla-gb'))
Expand Down
6 changes: 0 additions & 6 deletions src/emscripten/exported.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[
"_emulator_clear_breakpoints",
"_emulator_delete",
"_emulator_get_A",
"_emulator_get_BC",
"_emulator_get_banked_PC",
"_emulator_get_DE",
"_emulator_get_F",
"_emulator_get_HL",
Expand All @@ -16,10 +14,7 @@
"_emulator_read_ext_ram",
"_emulator_read_mem",
"_emulator_read_state",
"_emulator_render_background",
"_emulator_render_vram",
"_emulator_run_until_f64",
"_emulator_set_breakpoint",
"_emulator_set_builtin_palette",
"_emulator_set_bw_palette_simple",
"_emulator_set_default_joypad_callback",
Expand Down Expand Up @@ -54,7 +49,6 @@
"_rewind_get_oldest_ticks_f64",
"_rewind_new_simple",
"_rewind_to_ticks_wrapper",
"_set_audio_channel_mute",
"_set_joyp_A",
"_set_joyp_B",
"_set_joyp_down",
Expand Down
Loading
Loading