Skip to content

Commit

Permalink
#1017: added RPi build to Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed Oct 15, 2020
1 parent d769029 commit ee40393
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 46 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,40 @@ jobs:
name: 'tic80-ubuntu-18'
path: build/tic80.deb

# === Raspberry PI ===
rpi:
runs-on: ubuntu-latest
env:
RPI_HOME: ${{GITHUB.WORKSPACE}}/build/rpi
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0

- name: Install
run: |
cd $RPI_HOME
git clone --depth 1 https://github.com/raspberrypi/tools.git tools
mkdir sysroot && cd sysroot
wget http://downloads.raspberrypi.org/raspbian/root.tar.xz
wget https://buildbot.libsdl.org/sdl-builds/sdl-raspberrypi/sdl-raspberrypi-224.tar.xz
sudo tar xf root.tar.xz
sudo tar xf sdl-raspberrypi-224.tar.xz
- name: Build
run: |
cd build
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. -DCMAKE_TOOLCHAIN_FILE=rpi/toolchain.cmake
sudo cmake --build . --parallel --config $BUILD_TYPE
sudo cpack
- name: Deploy
uses: actions/upload-artifact@v2
with:
name: 'tic80-rpi'
path: build/tic80.deb

# === MacOS 10.15 ===
macos:
runs-on: macos-10.15
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ lib/
*.cmake
CMakeCache.txt
Makefile
!build/rpi/*
!build/baremetalpi/Makefile
!build/baremetalpi/boot/Makefile
build/android/.gradle/
Expand Down
92 changes: 51 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ message("PROJECT_VERSION: ${PROJECT_VERSION}${VERSION_STATUS}")

configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h")

if(ANDROID OR EMSCRIPTEN OR N3DS)
if(ANDROID OR EMSCRIPTEN OR N3DS OR RPI)
set(BUILD_LIBRETRO_DEFAULT OFF)
set(BUILD_DEMO_CARTS_DEFAULT OFF)
set(BUILD_PLAYER_DEFAULT OFF)
Expand All @@ -58,6 +58,10 @@ option(BUILD_PRO "Build PRO version" FALSE)
option(BUILD_PLAYER "Build standalone players" ${BUILD_PLAYER_DEFAULT})
option(BUILD_TOUCH_INPUT "Build with touch input support" ${BUILD_TOUCH_INPUT_DEFAULT})

if(RPI)
set(DISABLE_NETWORKING TRUE)
endif()

if(NOT BUILD_SDL)
set(BUILD_SDLGPU OFF)
endif()
Expand Down Expand Up @@ -367,7 +371,7 @@ endif()
################################
# SDL2
################################
if(BUILD_SDL AND NOT EMSCRIPTEN)
if(BUILD_SDL AND NOT EMSCRIPTEN AND NOT RPI)

if(WIN32)
set(HAVE_LIBC TRUE)
Expand All @@ -387,7 +391,7 @@ endif()
# SDL2 standalone cart player
################################

if(BUILD_SDL AND BUILD_PLAYER)
if(BUILD_SDL AND BUILD_PLAYER AND NOT RPI)

add_executable(player-sdl WIN32 ${CMAKE_SOURCE_DIR}/src/player/sdl.c)

Expand Down Expand Up @@ -664,12 +668,39 @@ set(TIC80LIB_SRC
${TIC80LIB_DIR}/ext/gif.c
${TIC80LIB_DIR}/ext/history.c
${TIC80LIB_DIR}/ext/net.c
${TIC80LIB_DIR}/ext/file_dialog.c
)

set(TIC80_OUTPUT tic80)

if(LINUX)
include(FindPkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(WARNING "We need pkg-config to detect GTK libs")
else()
pkg_check_modules(GTK gtk+-3.0)

if(${GTK_FOUND})
target_include_directories(${TIC80_OUTPUT}lib PRIVATE ${GTK_INCLUDE_DIRS})
target_link_libraries(${TIC80_OUTPUT}lib ${GTK_LIBRARIES})
endif()
endif()
endif()

if(APPLE)
set(TIC80LIB_SRC ${TIC80LIB_SRC} ${TIC80LIB_DIR}/ext/file_dialog.m)
endif()

add_library(${TIC80_OUTPUT}lib STATIC ${TIC80LIB_SRC} ${DEMO_CARTS_OUT})

if(LINUX)
if(${GTK_FOUND})
target_compile_definitions(${TIC80_OUTPUT}lib PUBLIC FILE_DIALOGS_SUPPORT)
endif()
else()
target_compile_definitions(${TIC80_OUTPUT}lib PUBLIC FILE_DIALOGS_SUPPORT)
endif()

if(WIN32)
target_include_directories(${TIC80_OUTPUT}lib PRIVATE ${THIRDPARTY_DIR}/dirent/include)
endif()
Expand Down Expand Up @@ -775,13 +806,7 @@ endif()

if(BUILD_SDL)

set(TIC80_SRC ${CMAKE_SOURCE_DIR}/src/ext/file_dialog.c)

if(APPLE)
set(TIC80_SRC ${TIC80_SRC} ${CMAKE_SOURCE_DIR}/src/ext/file_dialog.m)
endif()

set(TIC80_SRC ${TIC80_SRC} src/system/sdl/main.c)
set(TIC80_SRC src/system/sdl/main.c)

if(WIN32)

Expand Down Expand Up @@ -830,23 +855,24 @@ if(BUILD_SDL)
target_compile_definitions(${TIC80_OUTPUT} PRIVATE TOUCH_INPUT_SUPPORT)
endif()

if(RPI)
target_include_directories(${TIC80_OUTPUT} PRIVATE ${SYSROOT_PATH}/usr/local/include/SDL2)
target_link_directories(${TIC80_OUTPUT} PRIVATE ${SYSROOT_PATH}/usr/local/lib ${SYSROOT_PATH}/opt/vc/lib)
endif()

if(BUILD_SDLGPU)
target_link_libraries(${TIC80_OUTPUT} sdlgpu)
target_compile_definitions(${TIC80_OUTPUT} PRIVATE CRT_SHADER_SUPPORT)
elseif(NOT EMSCRIPTEN)
target_link_libraries(${TIC80_OUTPUT} ${TIC80_OUTPUT}lib SDL2-static)
else()
if(EMSCRIPTEN)
elseif(RPI)
target_link_libraries(${TIC80_OUTPUT} SDL2 bcm_host)
else()
target_link_libraries(${TIC80_OUTPUT} SDL2-static)
endif()
endif()

if(LINUX)
include(FindPkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(FATAL_ERROR "We need pkg-config to compile this project")
endif()

pkg_check_modules(GTK REQUIRED gtk+-3.0)

target_include_directories(${TIC80_OUTPUT} PRIVATE ${GTK_INCLUDE_DIRS})
target_link_libraries(${TIC80_OUTPUT} ${GTK_LIBRARIES})

install(TARGETS ${TIC80_OUTPUT} DESTINATION bin)

Expand All @@ -858,7 +884,6 @@ if(BUILD_SDL)
install (FILES ${PROJECT_SOURCE_DIR}/build/linux/tic80.png DESTINATION ${TIC80_PIXMAPS_DIR})

endif()

endif()

################################
Expand All @@ -867,13 +892,7 @@ endif()

if(BUILD_SOKOL)

set(TIC80_SRC ${CMAKE_SOURCE_DIR}/src/ext/file_dialog.c)

if(APPLE)
set(TIC80_SRC ${TIC80_SRC} ${CMAKE_SOURCE_DIR}/src/ext/file_dialog.m)
endif()

set(TIC80_SRC ${TIC80_SRC} ${CMAKE_SOURCE_DIR}/src/system/sokol/sokol.c)
set(TIC80_SRC ${CMAKE_SOURCE_DIR}/src/system/sokol/sokol.c)

if(WIN32)

Expand All @@ -897,18 +916,6 @@ if(BUILD_SOKOL)

target_link_libraries(${TIC80_OUTPUT}-sokol ${TIC80_OUTPUT}lib sokol)

if(LINUX)
include(FindPkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(FATAL_ERROR "We need pkg-config to compile this project")
endif()

pkg_check_modules(GTK REQUIRED gtk+-3.0)

target_include_directories(${TIC80_OUTPUT}-sokol PRIVATE ${GTK_INCLUDE_DIRS})
target_link_libraries(${TIC80_OUTPUT}-sokol ${GTK_LIBRARIES})
endif()

endif()

################################
Expand Down Expand Up @@ -982,6 +989,9 @@ elseif (LINUX)
set(CPACK_DEBIAN_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Nesbox <grigoruk@gmail.com>")
set(CPACK_DEBIAN_PACKAGE_SECTION "education")
if(RPI)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE armhf)
endif()

install(CODE "set(CMAKE_INSTALL_LOCAL_ONLY true)")
include(CPack)
Expand Down
23 changes: 23 additions & 0 deletions build/rpi/toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Define our host system
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)
set(RPI_HOME $ENV{RPI_HOME})
set(SYSROOT_PATH ${RPI_HOME}/sysroot)

# Define the cross compiler locations
SET(CMAKE_C_COMPILER ${RPI_HOME}/tools/arm-bcm2708/${CMAKE_LIBRARY_ARCHITECTURE}/bin/${CMAKE_LIBRARY_ARCHITECTURE}-gcc)
SET(CMAKE_CXX_COMPILER ${RPI_HOME}/tools/arm-bcm2708/${CMAKE_LIBRARY_ARCHITECTURE}/bin/${CMAKE_LIBRARY_ARCHITECTURE}-g++)

# Define the sysroot path for the RaspberryPi distribution in our tools folder
SET(CMAKE_FIND_ROOT_PATH ${SYSROOT_PATH})

# Use our definitions for compiler tools
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# Search for libraries and headers in the target directories only
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )

set(RPI TRUE)
9 changes: 4 additions & 5 deletions src/ext/file_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <tic80_config.h>

#if defined(FILE_DIALOGS_SUPPORT)

#if defined(__TIC_WINDOWS__)

#include <windows.h>
Expand Down Expand Up @@ -454,9 +456,6 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
(*env)->ReleaseStringUTFChars(env, jPath, filename);
}

#else

void file_dialog_load(file_dialog_load_callback callback, void* data) {}
void file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode) {}

#endif

#endif // FILE_DIALOGS_SUPPORT
5 changes: 5 additions & 0 deletions src/system/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,13 @@ static System systemInterface =
.httpGetSync = httpGetSync,
.httpGet = httpGet,

#if defined(FILE_DIALOGS_SUPPORT)
.fileDialogLoad = file_dialog_load,
.fileDialogSave = file_dialog_save,
#else
.fileDialogLoad = NULL,
.fileDialogSave = NULL,
#endif

.goFullscreen = goFullscreen,
.showMessageBox = showMessageBox,
Expand Down
5 changes: 5 additions & 0 deletions src/system/sokol/sokol.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,13 @@ static System systemInterface =
.httpGetSync = httpGetSync,
.httpGet = httpGet,

#if defined(FILE_DIALOGS_SUPPORT)
.fileDialogLoad = file_dialog_load,
.fileDialogSave = file_dialog_save,
#else
.fileDialogLoad = NULL,
.fileDialogSave = NULL,
#endif

.goFullscreen = goFullscreen,
.showMessageBox = showMessageBox,
Expand Down

0 comments on commit ee40393

Please sign in to comment.