Skip to content

Commit

Permalink
add workflow builds for emsdk, fix emsdk pthread link error
Browse files Browse the repository at this point in the history
  • Loading branch information
ITotalJustice committed Aug 29, 2022
1 parent b0a4ad1 commit 08c8837
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 242 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy_netlify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: deploy_netflify

on:
push:
branches: [ "master" ]

jobs:
build-web:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11

- name: Cmake Build
run: |
embuilder build zlib
# embuilder build zlib --lto
# embuilder build zlib --lto=thin
cmake --preset emsdk -DEM_USE_THREADS=ON
cmake --build --preset emsdk --parallel 4
- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
publish-dir: build/emsdk/bin
production-branch: master
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy from GitHub Actions"
enable-pull-request-comment: false
enable-commit-comment: false
overwrites-pull-request-comment: false
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1
32 changes: 32 additions & 0 deletions .github/workflows/deploy_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# gh pages build does not use threads / mutex's
# this offers wider browser support.
name: deploy_pages

on:
push:
branches: [ "master" ]

jobs:
build-web:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11

- name: Cmake Build
run: |
embuilder build zlib
# embuilder build zlib --lto
# embuilder build zlib --lto=thin
cmake --preset emsdk
cmake --build --preset emsdk --parallel 4
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: build/emsdk/bin # The folder the action should deploy.
single-commit: true # Start branch with no history
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ imgui.ini
CMakeUserPresets.json
rtc.md
n64-emu
deploy_netlify.yml
deploy_pages.yml
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ else()
message(STATUS "cant find clangd: not generating compile_commands.json")
endif()

if (LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)
if (ipo_supported)
message(STATUS "IPO / LTO enabled for ALL targets")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported")
endif()
endif()

# these needs to be globally set otherwise a link error happens when
# using std::filesystem::recursive_directory_iterator
if (EMSCRIPTEN AND EM_USE_THREADS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()

message(STATUS "SYSTEM: ${CMAKE_SYSTEM_NAME}")
message(STATUS "COMPILER: ${CMAKE_CXX_COMPILER_ID}")

Expand Down
4 changes: 4 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"LTO": true,
"SINGLE_FILE": true,
"IMGUI": true
}
Expand Down Expand Up @@ -48,6 +49,7 @@
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"LTO": true,
"SINGLE_FILE": true,
"SDL2": true
}
Expand All @@ -69,6 +71,7 @@
"toolchainFile": "$env{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"LTO": true,
"SINGLE_FILE": true,
"SDL2": true
}
Expand All @@ -92,6 +95,7 @@
"toolchainFile": "$env{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"LTO": true,
"SINGLE_FILE": true
}
},
Expand Down
25 changes: 0 additions & 25 deletions assets/web/README.md

This file was deleted.

100 changes: 39 additions & 61 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,54 +46,51 @@ endif()

list(APPEND clang_flags
-Wall
# -Wextra
-Wextra
-Wfatal-errors

# -Wpedantic
-fno-rtti -fno-exceptions
# -Wshadow
# -Wdouble-promotion
# -Wformat=2
# -Wundef
# -Wmissing-include-dirs
# -Wstrict-aliasing
# -Wstrict-overflow=5
# -Walloca
# -Wwrite-strings
# -Wdate-time
# -Wpacked
# -Wnested-externs
# -Wcast-qual
# -Wcast-align
# -Wunused-macros
# -Wreserved-id-macro
# -Wbad-function-cast
# -Wbitfield-enum-conversion

# -Wextra-semi-stmt
# -Wold-style-cast
# -Wcovered-switch-default

# -Wno-unused-parameter
# -Wno-unused-variable
# -Wextra-semi-stmt
# -Wold-style-cast
-Wpedantic
-Wshadow
-Wdouble-promotion
-Wformat=2
-Wundef
-Wmissing-include-dirs
-Wstrict-aliasing
-Wstrict-overflow=5
-Walloca
-Wwrite-strings
-Wdate-time
-Wpacked
-Wnested-externs
-Wcast-qual
-Wcast-align
-Wunused-macros
-Wreserved-id-macro
-Wbad-function-cast
-Wbitfield-enum-conversion

-Wextra-semi-stmt
-Wold-style-cast
-Wcovered-switch-default

-fno-rtti
-fno-exceptions

# # can try enabling this just to see what breaks (still compiles as of clang 11)
# # be sure to enable (well, disable) the below flags else a *lot* of "errors"
# # -Weverything
# -Wno-c++98-compat
# -Wno-c++98-compat-pedantic
# -Wno-c++20-compat
# -Wno-missing-braces # false positive
# -Wno-unused-parameter
# -Wno-unused-variable
# -Wno-conversion
# -Wno-sign-conversion
# -Wno-missing-prototypes
# -Wno-padded
# -Wno-switch-enum
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-c++20-compat
-Wno-missing-braces # false positive
-Wno-conversion
-Wno-sign-conversion
-Wno-missing-prototypes
-Wno-padded
-Wno-switch-enum
-Wno-unknown-attributes
-Wno-unused-parameter
-Wno-unused-variable
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand All @@ -120,27 +117,8 @@ endif()

include(CheckCXXCompilerFlag)
include(CheckLinkerFlag)
include(CheckIPOSupported)
include(FetchContent)

function(target_apply_lto target)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)
if (ipo_supported)
message(STATUS "IPO / LTO enabled for target: ${target}")
set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported: <${ipo_error}>")
endif()
endfunction()

function(target_apply_lto_in_release target)
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
target_apply_lto(${target})
else()
message(STATUS "IPO / LTO not enabled in debug build")
endif()
endfunction()

function(target_add_compiler_flag target flag scope)
# check_cxx_compiler_flag() adds a macro to the test.c file such that
# it'll look like # will be shown as "#define COMPILER_SUPPORTS_-Wdouble-promotion"
Expand Down
4 changes: 0 additions & 4 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,3 @@ target_compile_definitions(GBA PRIVATE
)

set_target_properties(GBA PROPERTIES CXX_STANDARD 23)

# enable LTO (only in release builds)
# this greatly reduces template bloat as well
target_apply_lto_in_release(GBA)
13 changes: 6 additions & 7 deletions src/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set_target_properties(frontend_base PROPERTIES CXX_STANDARD 23)


target_add_common_cflags(frontend_base PRIVATE)
target_apply_lto_in_release(frontend_base)

include(FetchContent)
Set(FETCHCONTENT_QUIET FALSE)
Expand All @@ -29,7 +28,7 @@ set(FOUND_MINIZIP FALSE)
# set(DISABLE_INSTALL_TOOLS ON)
# find_package(minizip CONFIG)
# if (DEFINED minizip_FOUND)
# target_link_libraries(frontend_base PUBLIC minizip::minizip)
# target_link_libraries(frontend_base PRIVATE minizip::minizip)

# set(FOUND_MINIZIP TRUE)
# message(STATUS "using vcpkg minizip")
Expand All @@ -42,8 +41,8 @@ set(FOUND_MINIZIP FALSE)
find_path(minizip_inc minizip)

if (minizip_lib AND minizip_inc)
target_link_libraries(frontend_base PUBLIC ${minizip_lib})
target_include_directories(frontend_base PUBLIC ${minizip_inc})
target_link_libraries(frontend_base PRIVATE ${minizip_lib})
target_include_directories(frontend_base PRIVATE ${minizip_inc})

# this has to be linked after minizip!
find_package(ZLIB REQUIRED)
Expand All @@ -70,13 +69,13 @@ if (NOT FOUND_MINIZIP)
${minizip_SOURCE_DIR}/contrib/minizip/unzip.c
)

target_include_directories(minizip PUBLIC ${minizip_SOURCE_DIR}/contrib/minizip/)
target_include_directories(minizip PRIVATE ${minizip_SOURCE_DIR}/contrib/minizip/)
# need the paths to be minizip/unzip.h
target_include_directories(minizip PUBLIC ${minizip_SOURCE_DIR}/contrib/)

find_package(ZLIB REQUIRED)
target_link_libraries(minizip PUBLIC ZLIB::ZLIB)
target_link_libraries(frontend_base PUBLIC minizip)
target_link_libraries(minizip PRIVATE ZLIB::ZLIB)
target_link_libraries(frontend_base PRIVATE minizip)

message(STATUS "using github minizip")
endif()
Expand Down
9 changes: 6 additions & 3 deletions src/frontend/emscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ add_executable(notorious_beeg_EMSDK main.cpp)
target_link_libraries(notorious_beeg_EMSDK PRIVATE sdl2_base)

target_add_common_cflags(notorious_beeg_EMSDK PRIVATE)
target_apply_lto_in_release(notorious_beeg_EMSDK)

set_target_properties(notorious_beeg_EMSDK PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
Expand All @@ -25,16 +24,20 @@ option(EM_USE_THREADS
option(EMRUN "build with emrun support, used for testing" OFF)

if (EM_USE_THREADS)
target_link_options(notorious_beeg_EMSDK PRIVATE "-pthread")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
# target_link_options(notorious_beeg_EMSDK PRIVATE "-pthread")
# target_compile_options(notorious_beeg_EMSDK PRIVATE "-pthread")
target_compile_definitions(notorious_beeg_EMSDK PRIVATE EM_THREADS=1)
endif()

if (EMRUN)
target_link_options(notorious_beeg_EMSDK PRIVATE "--emrun")
target_compile_definitions(notorious_beeg_EMSDK PRIVATE EMRUN=1)
endif()

file(COPY "${CMAKE_SOURCE_DIR}/assets/buttons" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/assets")
file(COPY "${CMAKE_SOURCE_DIR}/assets/menu" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/assets")
file(COPY "${CMAKE_SOURCE_DIR}/assets/web" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(COPY "${CMAKE_SOURCE_DIR}/assets/web/" DESTINATION "${CMAKE_BINARY_DIR}/bin/")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/netlify.toml" DESTINATION "${CMAKE_BINARY_DIR}/bin/")

target_link_options(notorious_beeg_EMSDK PRIVATE
Expand Down
Loading

0 comments on commit 08c8837

Please sign in to comment.