Skip to content

Refactor Build Process #5

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

Draft
wants to merge 12 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
18 changes: 12 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
Expand Down Expand Up @@ -55,8 +57,8 @@ jobs:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
mkdir bundle/
strip build/gosu-mruby.exe
mv build/gosu-mruby.exe bundle/
strip build/src/gosu-mruby.exe
mv build/src/gosu-mruby.exe bundle/
mv D:/a/gosu-mruby-wrapper/gosu-mruby-wrapper/gosu/lib64/gosu-ffi.dll bundle/
mv D:/a/gosu-mruby-wrapper/gosu-mruby-wrapper/gosu/lib64/SDL2.dll bundle/
mv /ucrt64/bin/libstdc++-6.dll bundle/
Expand All @@ -74,6 +76,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install requirements of Gosu
run: brew install sdl2
Expand All @@ -98,8 +102,8 @@ jobs:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
mkdir bundle/
strip build/gosu-mruby
mv build/gosu-mruby bundle/
strip build/src/gosu-mruby
mv build/src/gosu-mruby bundle/
mv vendor/gosu/lib64/libgosu.dylib bundle/
mv vendor/gosu/lib64/libgosu-ffi.dylib bundle/
install_name_tool -add_rpath @executable_path/. bundle/gosu-mruby
Expand All @@ -115,6 +119,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install requirements of Gosu
run: sudo apt-get update && sudo apt-get install -y libsdl2-dev libgl1-mesa-dev libfontconfig1-dev xvfb
Expand All @@ -139,8 +145,8 @@ jobs:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
mkdir bundle/
strip build/gosu-mruby
mv build/gosu-mruby bundle/
strip build/src/gosu-mruby
mv build/src/gosu-mruby bundle/
mv vendor/gosu/lib64/libgosu.so bundle/
mv vendor/gosu/lib64/libgosu-ffi.so bundle/

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extern/physfs"]
path = extern/physfs
url = ../../icculus/physfs.git
74 changes: 3 additions & 71 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22.1)
cmake_minimum_required(VERSION 3.22.1...3.26.4 FATAL_ERROR) # Same as Gosu's

project(GosuMRubyWrapper
VERSION 0.0.7
Expand Down Expand Up @@ -32,48 +32,10 @@ if(GIT_FOUND)
endif()
configure_file(include/config.h.in config.h)

set(WARNINGS -pedantic -Wall -Wextra -Wshadow -Wpointer-arith
-Wcast-qual -Wno-unused-parameter)
set(DEFINES MRB_INT64 MRB_USE_CXX_EXCEPTION MRB_USE_CXX_ABI
MRB_USE_BIGINT)

# Source files
set(SOURCE src/main.c src/fused.c)
set(WHEREAMI_SOURCE vendor/whereami/src/whereami.c)
file(GLOB PHYSFS_SOURCE vendor/physfs/src/*.c)
if(APPLE)
list(APPEND PHYSFS_SOURCE vendor/physfs/src/physfs_platform_apple.m)
endif()

# Disable warning for PhysFS
set_source_files_properties(${PHYSFS_SOURCE}
PROPERTIES
COMPILE_FLAGS "-w")

# Windows resource file
if(NOT APPLE AND NOT UNIX)
# Set RC as language so it is seen and compiled as a resource file
set_source_files_properties(${CMAKE_SOURCE_DIR}/assets/gosu_mruby_wrapper.rc LANGUAGE RC)
list(APPEND SOURCE ${CMAKE_SOURCE_DIR}/assets/gosu_mruby_wrapper.rc)

# We have to enable compile flags for MinGW
# FIXME: This should be probably in an if(MINGW) however the check fails on MSYS2 for some reason,
# once I come around to fixing other compilation caveats on MSYS2 I'll get around to fixing
# this
set(CMAKE_RC_COMPILER_INIT windres)
enable_language(RC)
set(CMAKE_RC_COMPILE_OBJECT
"<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()
add_subdirectory(extern/physfs)

# TODO: Build Gosu?

# Building PhysFS
add_library(PhysFS ${PHYSFS_SOURCE})
if(APPLE)
target_link_libraries(PhysFS ${IOKIT_LIBRARY} ${FOUNDATION_LIBRARY})
endif()

# Building MRuby
set(MRUBY_DIR ${CMAKE_SOURCE_DIR}/vendor/mruby)
set(MRUBY_LIB ${MRUBY_DIR}/build/host/lib/libmruby.a)
Expand All @@ -95,34 +57,4 @@ ExternalProject_Add(MRuby
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${MRUBY_LIB})

# The main executable
add_executable(GosuMRuby ${SOURCE} ${WHEREAMI_SOURCE})
add_dependencies(GosuMRuby MRuby PhysFS)

set_target_properties(GosuMRuby PROPERTIES OUTPUT_NAME "gosu-mruby")

target_compile_definitions(GosuMRuby PRIVATE ${DEFINES})
target_compile_options(GosuMRuby PRIVATE -x c++ ${WARNINGS})

target_include_directories(GosuMRuby PRIVATE include/)
target_include_directories(GosuMRuby PRIVATE "${PROJECT_BINARY_DIR}")

target_include_directories(GosuMRuby SYSTEM PRIVATE vendor/mruby/include/)
target_include_directories(GosuMRuby SYSTEM PRIVATE vendor/whereami/include/)
target_include_directories(GosuMRuby SYSTEM PRIVATE vendor/physfs/src/)

target_link_directories(GosuMRuby PRIVATE vendor/gosu/lib64)
target_link_directories(GosuMRuby PRIVATE vendor/mruby/build/host/lib)

target_link_libraries(GosuMRuby PhysFS ${MRUBY_LIB} gosu-ffi gosu stdc++)

if(APPLE)
target_link_libraries(GosuMRuby ${IOKIT_LIBRARY} ${FOUNDATION_LIBRARY}
m ${CMAKE_DL_LIBS})
elseif(UNIX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
target_link_libraries(GosuMRuby m ${CMAKE_DL_LIBS})
else() # Assume Windows
target_link_options(GosuMRuby PRIVATE -mwindows) # Hide console
target_link_libraries(GosuMRuby ws2_32 wsock32 gcc)
endif()
add_subdirectory(src/)
1 change: 1 addition & 0 deletions extern/physfs
Submodule physfs added at b1a2f1
1 change: 1 addition & 0 deletions scripts/mruby/gosu.gembox
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ MRuby::GemBox.new do |conf|
conf.gembox 'default'

conf.gem github: 'chadowo/mruby-gosu'

conf.gem github: 'katzer/mruby-logger'
conf.gem github: 'iij/mruby-env'
# FIXME: Fails to compile on Windows, I assume it's got to do with this line
Expand Down
4 changes: 2 additions & 2 deletions scripts/mruby/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
conf.gembox File.expand_path('gosu', File.dirname(__FILE__))

# C compiler settings
conf.cc.defines += %w[MRB_INT64]
conf.cc.flags += %w[-fpermissive -O3]
conf.defines << 'MRB_INT64'
conf.cc.flags += %w[-fpermissive -O2]

conf.enable_cxx_abi
end
4 changes: 2 additions & 2 deletions scripts/mruby/macos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
conf.gembox File.expand_path('gosu', File.dirname(__FILE__))

# C compiler settings
conf.cc.defines += %w[MRB_INT64]
conf.cc.flags += %w[-fpermissive -O3]
conf.defines << 'MRB_INT64'
conf.cc.flags += %w[-fpermissive -O2]

conf.enable_cxx_abi
end
4 changes: 2 additions & 2 deletions scripts/mruby/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
conf.gembox File.expand_path('gosu', File.dirname(__FILE__))

# C compiler settings
conf.cc.defines += %w[MRB_INT64]
conf.cc.flags += %w[-fpermissive -O3]
conf.defines << 'MRB_INT64'
conf.cc.flags += %w[-fpermissive -O2]

linker.libraries.push('ws2_32')

Expand Down
33 changes: 33 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(WHEREAMI_SOURCE ../vendor/whereami/src/whereami.c)
add_executable(gosu_mruby_bin main.c fused.c ${WHEREAMI_SOURCE})
add_dependencies(gosu_mruby_bin MRuby)

set_target_properties(gosu_mruby_bin PROPERTIES OUTPUT_NAME "gosu-mruby")

target_include_directories(gosu_mruby_bin PRIVATE ../include)
target_include_directories(gosu_mruby_bin PRIVATE "${PROJECT_BINARY_DIR}")
target_include_directories(gosu_mruby_bin SYSTEM PRIVATE ../vendor/mruby/include/)
target_include_directories(gosu_mruby_bin SYSTEM PRIVATE ../vendor/whereami/include/)
target_include_directories(gosu_mruby_bin SYSTEM PRIVATE ../vendor/physfs/src/)

target_link_directories(gosu_mruby_bin PRIVATE ../vendor/gosu/lib64)
target_link_directories(gosu_mruby_bin PRIVATE ../vendor/mruby/build/host/lib)

set(WARNINGS -pedantic -Wall -Wextra -Wshadow -Wpointer-arith
-Wcast-qual -Wno-unused-parameter)
set(DEFINES MRB_INT64 MRB_USE_CXX_ABI
MRB_USE_BIGINT MRB_USE_RATIONAL MRB_USE_COMPLEX)
target_compile_options(gosu_mruby_bin PRIVATE -x c++ ${WARNINGS})
target_compile_definitions(gosu_mruby_bin PRIVATE ${DEFINES})

target_link_libraries(gosu_mruby_bin PRIVATE PhysFS::PhysFS-static ${MRUBY_LIB} gosu-ffi gosu stdc++)
if(APPLE)
target_link_libraries(gosu_mruby_bin PRIVATE ${IOKIT_LIBRARY} ${FOUNDATION_LIBRARY}
m ${CMAKE_DL_LIBS})
elseif(UNIX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
target_link_libraries(gosu_mruby_bin PRIVATE m ${CMAKE_DL_LIBS})
else() # Assume Windows
target_link_options(gosu_mruby_bin PRIVATE -mwindows) # Hide console
target_link_libraries(gosu_mruby_bin PRIVATE ws2_32 wsock32 gcc)
endif()
Loading
Loading