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
3 changes: 3 additions & 0 deletions .github/scripts/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ case "${1%-*}" in
export PATH="/opt/homebrew/opt/bison/bin:$PATH"
printf 'PATH=%s\n' "$PATH" >>"$GITHUB_ENV" # Make it available to later CI steps too
;;
freebsd)
pkg install -y bash bison cmake git png
;;
*)
echo "WARNING: Cannot install deps for OS '$1'"
;;
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,9 @@ jobs:
release: "14.3"
usesh: true
prepare: |
pkg install -y \
bash \
bison \
cmake \
git \
png
.github/scripts/install_deps.sh freebsd
run: | # FreeBSD `c++` compiler does not support `make develop` sanitizers ASan or UBSan
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=c++ -DUSE_EXTERNAL_TESTS=OFF -DOS=bsd
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=c++ -DUSE_EXTERNAL_TESTS=OFF -DTESTS_OS_NAME=bsd
cmake --build build -j4 --verbose
cmake --install build --verbose
cmake --build build --target test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
CMakeUserPresets.json
build/
*.dSYM/
callgrind.out.*
43 changes: 22 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# SPDX-License-Identifier: MIT
## SPDX-License-Identifier: MIT

# 3.9 required for LTO checks
# 3.17 optional for CMAKE_CTEST_ARGUMENTS
cmake_minimum_required(VERSION 3.9..3.17 FATAL_ERROR)
# 3.17 required for LTO checks messages
cmake_minimum_required(VERSION 3.17...4.2 FATAL_ERROR)

project(rgbds
LANGUAGES CXX)
LANGUAGES CXX
DESCRIPTION "Game Boy assembly toolchain"
HOMEPAGE_URL "https://rgbds.gbdev.io")

include(CTest)

Expand All @@ -20,31 +21,33 @@ if(srcdir STREQUAL bindir)
message(FATAL_ERROR "Terminating configuration")
endif()

option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
include(CMakeDependentOption)
option(SANITIZERS "Build with sanitizers enabled" OFF)
cmake_dependent_option(MORE_WARNINGS "Turn on more warnings" OFF !MSVC OFF)

if(MSVC)
# MSVC's own standard library triggers warning C5105,
# "macro expansion producing 'defined' has undefined behavior".
# Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`), none of ours being load-bearing.
# Warning C4996 is about using POSIX names, which we want to do for portability.
# We also opt into the C++20-conformant preprocessor.
add_compile_options(/MP /wd5105 /wd5030 /wd4996 /Zc:preprocessor)
add_compile_options(
/MP # Build multiple files in parallel.
# /wd5105 # MSVC's own standard library triggers warning C5105, "macro expansion producing 'defined' has undefined behavior".
/wd5030 # Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`), none of ours being load-bearing.
/wd4996 # Warning C4996 is about using POSIX names, which we want to do for portability.
/Zc:preprocessor # Opt into the C++20-conformant preprocessor.
)
Comment on lines +29 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are long enough that they could be header-style not inline-style (like the comment on -Wno-gnu-zero-variadic-macro-arguments below):

Suggested change
add_compile_options(
/MP # Build multiple files in parallel.
/wd5105 # MSVC's own standard library triggers warning C5105, "macro expansion producing 'defined' has undefined behavior".
/wd5030 # Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`), none of ours being load-bearing.
/wd4996 # Warning C4996 is about using POSIX names, which we want to do for portability.
/Zc:preprocessor # Opt into the C++20-conformant preprocessor.
)
add_compile_options(
# Build multiple files in parallel
/MP
# MSVC's own standard library triggers warning C5105,
# "macro expansion producing 'defined' has undefined behavior"
/wd5105
# Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`),
# none of ours being load-bearing.
/wd5030
# Warning C4996 is about using POSIX names,
# which we want to do for portability.
/wd4996
# Opt into the C++20-conformant preprocessor.
/Zc:preprocessor
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the CMakeLists is quite long, I was trying to keep it more compact. But if you think that this is nonetheless better, I'd be fine with you committing this.

add_definitions(/D_CRT_SECURE_NO_WARNINGS)

if(SANITIZERS)
message(STATUS "ASan enabled")
set(SAN_FLAGS /fsanitize=address)
add_compile_options(${SAN_FLAGS})
add_link_options(${SAN_FLAGS})
endif()
else()
add_compile_options(-Wall -pedantic)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# C++20 allows macros to take zero variadic arguments, but Clang (aka AppleClang on macOS)
# does not recognize this yet.
add_compile_options(-Wno-gnu-zero-variadic-macro-arguments)
endif()
add_compile_options(-Wall -pedantic
# C++20 allows macros to take zero variadic arguments.
# Some versions of Clang don't recognize this, and treat them as a GNU extension.
-Wno-gnu-zero-variadic-macro-arguments)
if(SANITIZERS)
message(STATUS "ASan and UBSan enabled")
set(SAN_FLAGS -fsanitize=address -fsanitize=undefined
-fsanitize=float-divide-by-zero)
add_compile_options(${SAN_FLAGS})
Expand Down Expand Up @@ -102,8 +105,6 @@ add_subdirectory(src)
set(CMAKE_CTEST_ARGUMENTS "--verbose")
add_subdirectory(test)

# By default, build in Release mode; Debug mode must be explicitly requested
# (You may want to augment it with the options above)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(CHECK_START "Checking if LTO is supported")
include(CheckIPOSupported)
Expand Down
50 changes: 21 additions & 29 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

configure_file(version.cpp _version.cpp ESCAPE_QUOTES)

set(common_src
add_library(common OBJECT
"extern/getopt.cpp"
"cli.cpp"
"diagnostics.cpp"
"style.cpp"
"usage.cpp"
"util.cpp"
"_version.cpp"
)
)

find_package(BISON 3.0.0 REQUIRED)
set(BISON_FLAGS "-Wall -Dlr.type=ielr")
Expand All @@ -31,15 +31,8 @@ BISON_TARGET(ASM_PARSER "asm/parser.y"
"${PROJECT_SOURCE_DIR}/src/asm/parser.cpp"
COMPILE_FLAGS "${BISON_FLAGS}"
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/parser.hpp"
)

BISON_TARGET(LINKER_SCRIPT_PARSER "link/script.y"
"${PROJECT_SOURCE_DIR}/src/link/script.cpp"
COMPILE_FLAGS "${BISON_FLAGS}"
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/link/script.hpp"
)

set(rgbasm_src
)
add_executable(rgbasm $<TARGET_OBJECTS:common>
"${BISON_ASM_PARSER_OUTPUT_SOURCE}"
"asm/actions.cpp"
"asm/charmap.cpp"
Expand All @@ -60,9 +53,14 @@ set(rgbasm_src
"linkdefs.cpp"
"opmath.cpp"
"verbosity.cpp"
)
)

set(rgblink_src
BISON_TARGET(LINKER_SCRIPT_PARSER "link/script.y"
"${PROJECT_SOURCE_DIR}/src/link/script.cpp"
COMPILE_FLAGS "${BISON_FLAGS}"
DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/link/script.hpp"
)
add_executable(rgblink $<TARGET_OBJECTS:common>
"${BISON_LINKER_SCRIPT_PARSER_OUTPUT_SOURCE}"
"link/assign.cpp"
"link/fstack.cpp"
Expand All @@ -81,16 +79,16 @@ set(rgblink_src
"linkdefs.cpp"
"opmath.cpp"
"verbosity.cpp"
)
)

set(rgbfix_src
add_executable(rgbfix $<TARGET_OBJECTS:common>
"fix/fix.cpp"
"fix/main.cpp"
"fix/mbc.cpp"
"fix/warning.cpp"
)
)

set(rgbgfx_src
add_executable(rgbgfx $<TARGET_OBJECTS:common>
"gfx/color_set.cpp"
"gfx/main.cpp"
"gfx/pal_packing.cpp"
Expand All @@ -103,19 +101,13 @@ set(rgbgfx_src
"gfx/rgba.cpp"
"gfx/warning.cpp"
"verbosity.cpp"
)
)

foreach(PROG "asm" "fix" "gfx" "link")
add_executable(rgb${PROG}
${rgb${PROG}_src}
${common_src}
)
install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
# Required to run tests
set_target_properties(rgb${PROG} PROPERTIES
# hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory"
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)
endforeach()
install(TARGETS rgbasm rgblink rgbfix rgbgfx RUNTIME DESTINATION bin)
# Required to run tests
set_target_properties(rgbasm rgblink rgbfix rgbgfx PROPERTIES
# hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory"
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>)

if(LIBPNG_FOUND) # pkg-config
target_include_directories(rgbgfx PRIVATE ${LIBPNG_INCLUDE_DIRS})
Expand Down
13 changes: 4 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

option(USE_NONFREE_TESTS "run tests that build nonfree codebases" ON)
option(USE_EXTERNAL_TESTS "run tests that build external codebases" ON)
set(TESTS_OS_NAME "" CACHE STRING "skip running tests known to fail on this OS")

if(NOT USE_NONFREE_TESTS)
set(ONLY_FREE "--only-free")
endif()
if(NOT USE_EXTERNAL_TESTS)
set(ONLY_INTERNAL "--only-internal")
endif()
if(DEFINED OS)
set(OS_NAME "--os" "${OS}")
endif()
set(ONLY_FREE $<IF:$<BOOL:USE_NONFREE_TESTS>,,--only-free>)
set(ONLY_INTERNAL $<IF:$<BOOL:USE_EXTERNAL_TESTS>,,--only-internal>)
set(OS_NAME "$<IF:$<STREQUAL:${TESTS_OS_NAME},>,,--os;${TESTS_OS_NAME}>")
Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's some abstruse ternary syntax, but sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it might be breaking in FreeBSD?

  Run command: bash -c 'cd /home/runner/work/rgbds/rgbds/test; ./fetch-test-deps.sh $<IF:$<BOOL:USE_NONFREE_TESTS>,,--only-free> $<IF:$<BOOL:USE_EXTERNAL_TESTS>,,--only-internal>'
  bash: -c: line 1: syntax error near unexpected token `newline'
  bash: -c: line 1: `cd /home/runner/work/rgbds/rgbds/test; ./fetch-test-deps.sh $<IF:$<BOOL:USE_NONFREE_TESTS>,,--only-free> $<IF:$<BOOL:USE_EXTERNAL_TESTS>,,--only-internal>'
  Problem running command: bash -c 'cd /home/runner/work/rgbds/rgbds/test; ./fetch-test-deps.sh $<IF:$<BOOL:USE_NONFREE_TESTS>,,--only-free> $<IF:$<BOOL:USE_EXTERNAL_TESTS>,,--only-internal>'
  Problem executing pre-test command(s).
  Errors while running CTest

I'd be fine with using ordinary ifs here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this ternary synax looks a little icky, but I was trying to avoid five lines of conditional logic per option here, for readability. Tradeoffs tradeoffs...


add_executable(randtilegen gfx/randtilegen.cpp)
add_executable(rgbgfx_test gfx/rgbgfx_test.cpp)
Expand Down
18 changes: 10 additions & 8 deletions test/fetch-test-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ set -euo pipefail
cd "$(dirname "$0")"

usage() {
echo "Downloads source code of Game Boy programs used as RGBDS test cases."
echo "Options:"
echo " -h, --help show this help message"
echo " --only-free download only freely licensed codebases"
echo " --only-internal do not download any codebases"
echo " --get-deps install programs' own dependencies instead of themselves"
echo " --get-hash print programs' commit hashes instead of downloading them"
echo " --get-paths print programs' GitHub paths instead of downloading them"
cat <<"EOF"
Downloads source code of Game Boy programs used as RGBDS test cases.
Options:
-h, --help show this help message
--only-free download only freely licensed codebases
--only-internal do not download any codebases
--get-deps install programs' own dependencies instead of themselves
--get-hash print programs' commit hashes instead of downloading them
--get-paths print programs' GitHub paths instead of downloading them
EOF
}

# Parse options in pure Bash because macOS `getopt` is stuck
Expand Down
28 changes: 16 additions & 12 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ export SOURCE_DATE_EPOCH=609165296
cd "$(dirname "$0")"

usage() {
echo "Runs regression tests on RGBDS."
echo "Options:"
echo " -h, --help show this help message"
echo " --only-internal only run tests that build local examples"
echo " --only-external only run tests that build external codebases"
echo " --only-free skip tests that build nonfree codebases"
echo " --installed-rgbds use the system installed RGBDS"
echo " (only compatible with external codebases)"
cat <<"EOF"
Runs regression tests on RGBDS.
Options:
-h, --help show this help message
--only-internal only run tests that build local examples
--only-external only run tests that build external codebases
--only-free skip tests that build nonfree codebases
--os <os> skip tests known to fail on <os> (e.g. `macos-14`)
--installed-rgbds use the system installed RGBDS
(only compatible with external codebases)
EOF
}

# Parse options in pure Bash because macOS `getopt` is stuck
Expand Down Expand Up @@ -57,7 +60,7 @@ while [[ $# -gt 0 ]]; do
break
;;
*)
echo "$(basename "$0"): internal error"
echo "$(basename "$0"): unknown option '$1'"
exit 1
;;
esac
Expand Down Expand Up @@ -134,6 +137,7 @@ test_downstream pinobatch libbet all libbet.gb f117089aa056600e2d404bbcbac
test_downstream LIJI32 SameBoy bootroms build/bin/BootROMs/cgb_boot.bin 113903775a9d34b798c2f8076672da6626815a91
# gb-starter kit fails with any `make` on Windows: https://codeberg.org/ISSOtm/gb-starter-kit/issues/1
# gb-starter-kit fails with macOS/BSD `make`: https://codeberg.org/ISSOtm/gb-starter-kit/issues/29
if [[ "${osname%-*}" != "windows" && "${osname%-*}" != "macos" && "${osname%-*}" != "bsd" ]]; then
test_downstream ISSOtm gb-starter-kit all bin/boilerplate.gb b4f130169ba73284e0d0e71b53e7baa4eca2f7fe
fi
case "${osname%%-*}" in
windows | macos | bsd) ;;
*) test_downstream ISSOtm gb-starter-kit all bin/boilerplate.gb b4f130169ba73284e0d0e71b53e7baa4eca2f7fe;;
esac
Loading