Skip to content

Commit

Permalink
Merge pull request #24 from OpenBrickProtocolFoundation/clang-build-a…
Browse files Browse the repository at this point in the history
…nd-ci

Clang build and ci
  • Loading branch information
mgerhold authored Jul 21, 2024
2 parents b6e036b + 73c188d commit 9a045b7
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 10 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: C++ CI

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build-linux:
runs-on: ubuntu-24.04
strategy:
matrix:
include:
- compiler-name: GCC 13
cc: gcc-13
cxx: g++-13
install-script: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt update
sudo apt install -y g++-13
build-type: Debug
- compiler-name: GCC 13
cc: gcc-13
cxx: g++-13
install-script: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt update
sudo apt install -y g++-13
build-type: Release
- compiler-name: Clang 18
cc: clang-18
cxx: clang++-18
install-script: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo apt install libstdc++-13-dev
build-type: Debug
- compiler-name: Clang 18
cc: clang-18
cxx: clang++-18
install-script: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo apt install libstdc++-13-dev
build-type: Release

steps:
- uses: actions/checkout@v3
- name: Install compiler (${{ matrix.compiler-name }})
run: |
${{ matrix.install-script }}
- name: Configure CMake
run: |
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/${{ matrix.cc }} 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/${{ matrix.cxx }} 100
cmake -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
- name: Fix kernel mmap rnd bits
# Asan in llvm 14 provided in ubuntu 22.04 is incompatible with
# high-entropy ASLR in much newer kernels that GitHub runners are
# using leading to random crashes: https://reviews.llvm.org/D148280
run: sudo sysctl vm.mmap_rnd_bits=28
- name: Build
run: cmake --build build
- name: Install
run: cmake --install build --prefix install
- name: Run Tests
run: ctest --test-dir build --verbose --output-on-failure

build-windows:
runs-on: windows-latest
strategy:
matrix:
build-type: [ Debug, Release ]
steps:
- uses: actions/checkout@v3
- name: Install Ninja
run: choco install ninja
- name: Install CMake
run: choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
- name: Set up Visual Studio Environment
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Configure CMake with Ninja and C++23
run: cmake -B build -G "Ninja" -DCMAKE_CXX_STANDARD=23 -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
- name: Build with Ninja
run: cmake --build build
- name: Install
run: cmake --install build --prefix install
- name: Run Tests
run: ctest --test-dir build --verbose --output-on-failure
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ include(project_options.cmake)
add_subdirectory(src bin)

if (${obpf_build_tests})
enable_testing()
add_subdirectory(test)
endif ()
4 changes: 0 additions & 4 deletions cmake/warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ function(obpf_simulator_set_warnings target_name warnings_as_errors)
/permissive- # standards conformance mode for MSVC compiler.
)

if (WIN32)
add_compile_definitions("_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING")
endif ()

set(clang_warnings
-Wall
-Wextra # reasonable and standard
Expand Down
2 changes: 1 addition & 1 deletion dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function(obpf_simulator_setup_dependencies)
CPMAddPackage(
NAME SPDLOG
GITHUB_REPOSITORY gabime/spdlog
VERSION 1.12.0
VERSION 1.14.1
OPTIONS
"SPDLOG_BUILD_EXAMPLE OFF"
"SPDLOG_BUILD_TESTS OFF"
Expand Down
4 changes: 4 additions & 0 deletions src/simulator/include/simulator/entry_delay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ class EntryDelay final {
void start() {
m_countdown = entry_delay;
}

void spawn_next_frame() {
m_countdown = 1;
}
};
4 changes: 4 additions & 0 deletions src/simulator/include/simulator/lock_delay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ class LockDelayState final {
}
return LockDelayPollResult::ShouldNotLock;
}

void clear() {
*this = {};
}
};
20 changes: 17 additions & 3 deletions src/simulator/tetrion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void ObpfTetrion::simulate_next_frame(KeyState const key_state) {
switch (m_entry_delay.poll()) {
case EntryDelayPollResult::ShouldSpawn:
spawn_next_tetromino();
m_lock_delay_state.clear();
break;
case EntryDelayPollResult::ShouldNotSpawn:
break;
Expand All @@ -69,6 +70,7 @@ void ObpfTetrion::simulate_next_frame(KeyState const key_state) {
switch (m_lock_delay_state.poll()) {
case LockDelayPollResult::ShouldLock:
freeze_and_destroy_active_tetromino();
m_is_hold_possible = false;
m_entry_delay.start();
break;
case LockDelayPollResult::ShouldNotLock:
Expand Down Expand Up @@ -132,10 +134,17 @@ void ObpfTetrion::freeze_and_destroy_active_tetromino() {
[[nodiscard]] bool ObpfTetrion::is_tetromino_position_valid(Tetromino const& tetromino) const {
auto const mino_positions = get_mino_positions(tetromino);
for (auto const position : mino_positions) {
if (position.x < 0 or position.x >= gsl::narrow<i32>(Matrix::width)
or position.y >= gsl::narrow<i32>(Matrix::height) or m_matrix[position] != TetrominoType::Empty) {
// clang-format off
if (
position.x < 0
or position.x >= gsl::narrow<i32>(Matrix::width)
or position.y < 0
or position.y >= gsl::narrow<i32>(Matrix::height)
or m_matrix[position] != TetrominoType::Empty
) {
return false;
}
// clang-format on
}
return true;
}
Expand Down Expand Up @@ -321,9 +330,13 @@ void ObpfTetrion::drop() {

void ObpfTetrion::hold() {
if (m_is_hold_possible) {
if (m_hold_piece.has_value()) {
m_entry_delay.spawn_next_frame();
} else {
m_entry_delay.start();
}
m_old_hold_piece = std::exchange(m_hold_piece, m_active_tetromino.value().type);
m_active_tetromino = std::nullopt;
m_entry_delay.start();
m_is_hold_possible = false;
}
}
Expand All @@ -340,6 +353,7 @@ void ObpfTetrion::determine_lines_to_clear() {
}

if (not lines_to_clear.empty()) {
m_is_hold_possible = false;
m_line_clear_delay.start(lines_to_clear);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/sandbox.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "utils.hpp"
#include <crapper/crapper.hpp>
#include <crapper/headers.hpp>
#include <network/lobby_server.hpp>
Expand All @@ -7,6 +6,7 @@
#include <sockets/detail/message_buffer.hpp>
#include <sockets/sockets.hpp>
#include <thread>
#include "utils.hpp"

struct CreateLobbyRequest final {
std::string name;
Expand Down Expand Up @@ -90,6 +90,6 @@ int main() {
std::this_thread::sleep_for(std::chrono::seconds(2));

// host
auto const result = lobby_server.destroy_lobby(user, std::move(lobby));
[[maybe_unused]] auto const result = lobby_server.destroy_lobby(user, std::move(lobby));
assert(result.has_value());
}

0 comments on commit 9a045b7

Please sign in to comment.