From d3f91a394dfb9f59a6dec49b4235ba4531251c8a Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 09:09:51 +0100 Subject: [PATCH 1/8] Fix linux CI by using ubuntu-latest instead of ubuntu-18.04 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c48710..5c1f968 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ on: [push, pull_request] jobs: build-linux-gcc: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: install dependencies @@ -16,7 +16,7 @@ jobs: env: CC: gcc build-linux-clang: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: install dependencies From 05e66facccfa9defa9bcc72494bc7902f2104e7c Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 10:25:00 +0100 Subject: [PATCH 2/8] Use CI matrix and include compiling with penger option in CI --- .github/workflows/ci.yml | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c1f968..32170f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,12 @@ name: CI on: [push, pull_request] jobs: - build-linux-gcc: + build-linux: runs-on: ubuntu-latest + strategy: + matrix: + compiler: [gcc, clang] + penger: [false, true] steps: - uses: actions/checkout@v1 - name: install dependencies @@ -12,31 +16,29 @@ jobs: sudo apt-get install -qq libsdl2-dev - name: build sowon run: | - make + if [ ${{ matrix.penger }} = true ]; then + make CFLAGS="-DPENGER" + else + make + fi env: - CC: gcc - build-linux-clang: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: install dependencies - run: | - sudo apt-get update - sudo apt-get install -qq libsdl2-dev - - name: build sowon - run: | - make - env: - CC: clang + CC: ${{ matrix.compiler }} build-macos: runs-on: macOS-latest + strategy: + matrix: + penger: [false, true] steps: - uses: actions/checkout@v1 - name: install dependencies run: brew install sdl2 pkg-config - name: build sowon run: | - make + if [ ${{ matrix.penger }} = true ]; then + make CFLAGS="-DPENGER" + else + make + fi env: CC: clang build-windows-msvc: From eb9eed42a4fbee2e3658bdda3790b3cc56b8191d Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 10:44:22 +0100 Subject: [PATCH 3/8] Use a dedicated PENGER variable in Makefile instead of using CFLAGS --- .github/workflows/ci.yml | 4 ++-- Makefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32170f9..5bd1550 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: build sowon run: | if [ ${{ matrix.penger }} = true ]; then - make CFLAGS="-DPENGER" + make PENGER=1 else make fi @@ -35,7 +35,7 @@ jobs: - name: build sowon run: | if [ ${{ matrix.penger }} = true ]; then - make CFLAGS="-DPENGER" + make PENGER=1 else make fi diff --git a/Makefile b/Makefile index 77a5e5b..bc257c7 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ COMMON_CFLAGS= -Wall -Wextra -std=c99 -pedantic -CFLAGS+= `pkg-config --cflags sdl2` $(COMMON_CFLAGS) +CFLAGS= `pkg-config --cflags sdl2` $(if $(PENGER),-DPENGER) $(COMMON_CFLAGS) COMMON_LIBS= -lm LIBS= `pkg-config --libs sdl2` $(COMMON_LIBS) PREFIX?= /usr/local @@ -8,7 +8,7 @@ INSTALL?= install .PHONY: all all: Makefile sowon man -sowon: main.c digits.h penger_walk_sheet.h +sowon: main.c digits.h $(if $(PENGER),penger_walk_sheet.h) $(CC) $(CFLAGS) -o sowon main.c $(LIBS) digits.h: png2c digits.png From 96a51e78b0b337f18c5f745be0c0f35de784df13 Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 10:49:16 +0100 Subject: [PATCH 4/8] Fix msvc build - fix SDL include for cross-platform compatibility - fix warnings about possible loss of data due to conversion --- .github/workflows/ci.yml | 11 +++++++++-- build_msvc.bat | 9 +++++++-- main.c | 10 +++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bd1550..76c50d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,10 @@ jobs: env: CC: clang build-windows-msvc: - runs-on: windows-2019 + runs-on: windows-latest + strategy: + matrix: + penger: [false, true] steps: - uses: actions/checkout@v1 # this runs vcvarsall for us, so we get the MSVC toolchain in PATH. @@ -55,7 +58,11 @@ jobs: - name: build sowon shell: cmd run: | - ./build_msvc.bat + if ${{ matrix.penger }} == true ( + build_msvc.bat PENGER + ) else ( + build_msvc.bat + ) # TODO: FreeBSD build is broken # build-freebsd: # runs-on: macos-latest diff --git a/build_msvc.bat b/build_msvc.bat index 39fc2d4..aed6d26 100644 --- a/build_msvc.bat +++ b/build_msvc.bat @@ -4,7 +4,12 @@ rem launch this from msvc-enabled console set CXXFLAGS=/std:c++17 /O2 /FC /W4 /WX /nologo set INCLUDES=/I SDL2\include set LIBS=SDL2\lib\x64\SDL2.lib SDL2\lib\x64\SDL2main.lib Shell32.lib - +if "%1"=="PENGER" ( + set CXXFLAGS=%CXXFLAGS% /DPENGER +) cl.exe %CXXFLAGS% /Fepng2c png2c.c /link Shell32.lib -SUBSYSTEM:console -png2c.exe digits.png > digits.h +png2c.exe digits.png digits > digits.h +if "%1"=="PENGER" ( + png2c.exe penger_walk_sheet.png penger > penger_walk_sheet.h +) cl.exe %CXXFLAGS% %INCLUDES% /Fesowon main.c /link %LIBS% -SUBSYSTEM:windows diff --git a/main.c b/main.c index 3d10146..13c9305 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,11 @@ #include #include +#ifdef _WIN32 +#include +#else #include +#endif #include "./digits.h" @@ -118,7 +122,7 @@ void render_penger_at(SDL_Renderer *renderer, SDL_Texture *penger, float time, i int step = (int)(time*sps)%(60*sps); //step index [0,60*sps-1] - float progress = step/(60.0*sps); // [0,1] + float progress = step/(60.0f*sps); // [0,1] int frame_index = step%2; @@ -134,8 +138,8 @@ void render_penger_at(SDL_Renderer *renderer, SDL_Texture *penger, float time, i }; SDL_Rect dst_rect = { - floorf((float)penger_walk_width * progress - penger_drawn_width), - window_height - (penger_height / PENGER_SCALE), + (int) (penger_walk_width * progress - penger_drawn_width), + (int) (window_height - (penger_height / PENGER_SCALE)), (int) (penger_width / 2) / PENGER_SCALE, (int) penger_height / PENGER_SCALE }; From aaa83b15e575e08efdaf0eaa27a1811248bdd34a Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 11:03:40 +0100 Subject: [PATCH 5/8] Refactor CI configuration --- .github/workflows/ci.yml | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76c50d2..039e9d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: compiler: [gcc, clang] - penger: [false, true] + penger: ["", "PENGER=1"] steps: - uses: actions/checkout@v1 - name: install dependencies @@ -16,36 +16,28 @@ jobs: sudo apt-get install -qq libsdl2-dev - name: build sowon run: | - if [ ${{ matrix.penger }} = true ]; then - make PENGER=1 - else - make - fi + make ${{ matrix.penger }} env: CC: ${{ matrix.compiler }} build-macos: runs-on: macOS-latest strategy: matrix: - penger: [false, true] + penger: ["", "PENGER=1"] steps: - uses: actions/checkout@v1 - name: install dependencies run: brew install sdl2 pkg-config - name: build sowon run: | - if [ ${{ matrix.penger }} = true ]; then - make PENGER=1 - else - make - fi + make ${{ matrix.penger }} env: CC: clang build-windows-msvc: runs-on: windows-latest strategy: matrix: - penger: [false, true] + penger: ["", "PENGER"] steps: - uses: actions/checkout@v1 # this runs vcvarsall for us, so we get the MSVC toolchain in PATH. @@ -58,11 +50,7 @@ jobs: - name: build sowon shell: cmd run: | - if ${{ matrix.penger }} == true ( - build_msvc.bat PENGER - ) else ( - build_msvc.bat - ) + build_msvc.bat ${{ matrix.penger }} # TODO: FreeBSD build is broken # build-freebsd: # runs-on: macos-latest From cce71ee987e69b25a6d92569c2f93f2d735d2dc5 Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 14:31:00 +0100 Subject: [PATCH 6/8] Fix FreeBSD CI config --- .github/workflows/ci.yml | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 039e9d7..5a5f9bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,18 +51,21 @@ jobs: shell: cmd run: | build_msvc.bat ${{ matrix.penger }} -# TODO: FreeBSD build is broken -# build-freebsd: -# runs-on: macos-latest -# name: FreeBSD LLVM Clang build -# steps: -# - uses: actions/checkout@v2 -# - name: Build on FreeBSD -# id: build -# uses: vmactions/freebsd-vm@v0.0.9 -# with: -# usesh: true -# prepare: pkg install -y sdl2 pkgconf -# run: | -# freebsd-version -# make + + build-freebsd: + runs-on: ubuntu-latest + name: FreeBSD LLVM Clang build + strategy: + matrix: + penger: ["", "PENGER=1"] + steps: + - uses: actions/checkout@v2 + - name: Build on FreeBSD + id: build + uses: vmactions/freebsd-vm@v1 + with: + usesh: true + prepare: pkg install -y sdl2 pkgconf + run: | + freebsd-version + make ${{ matrix.penger }} From 56a9d23e0ab3be62965268e4d78f4c422c796b67 Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 14:35:17 +0100 Subject: [PATCH 7/8] Update CI to use v4 of actions/checkout --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a5f9bb..0ba9500 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: compiler: [gcc, clang] penger: ["", "PENGER=1"] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: install dependencies run: | sudo apt-get update @@ -25,7 +25,7 @@ jobs: matrix: penger: ["", "PENGER=1"] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: install dependencies run: brew install sdl2 pkg-config - name: build sowon @@ -39,7 +39,7 @@ jobs: matrix: penger: ["", "PENGER"] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 # this runs vcvarsall for us, so we get the MSVC toolchain in PATH. - uses: seanmiddleditch/gha-setup-vsdevenv@master - name: download sdl2 @@ -59,7 +59,7 @@ jobs: matrix: penger: ["", "PENGER=1"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build on FreeBSD id: build uses: vmactions/freebsd-vm@v1 From 71f6d8dab3383d498fea792d325160f2d15e4d09 Mon Sep 17 00:00:00 2001 From: Jonas Keller Date: Wed, 13 Nov 2024 15:08:29 +0100 Subject: [PATCH 8/8] Update Makefile to append CFLAGS instead of overwriting --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bc257c7..cd9c13a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ COMMON_CFLAGS= -Wall -Wextra -std=c99 -pedantic -CFLAGS= `pkg-config --cflags sdl2` $(if $(PENGER),-DPENGER) $(COMMON_CFLAGS) +CFLAGS+= `pkg-config --cflags sdl2` $(if $(PENGER),-DPENGER) $(COMMON_CFLAGS) COMMON_LIBS= -lm LIBS= `pkg-config --libs sdl2` $(COMMON_LIBS) PREFIX?= /usr/local