Skip to content

Commit 06636b3

Browse files
authored
Merge pull request #14 from aymnms/dev
Implement Linux build and add artifacts to the release
2 parents 9f78294 + 0cfc364 commit 06636b3

File tree

19 files changed

+300
-106
lines changed

19 files changed

+300
-106
lines changed

.github/workflows/build-macos.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Build MarioISN (macOS & Linux)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: Build on ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [macos-latest, ubuntu-latest]
17+
# os: [macos-latest, ubuntu-latest, windows-latest]
18+
19+
runs-on: ${{ matrix.os }}
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
# ---------------------
28+
# Dependencies per OS
29+
# ---------------------
30+
- name: Install deps (macOS)
31+
if: runner.os == 'macOS'
32+
run: |
33+
brew update
34+
brew install cmake ninja sdl2 sdl2_image sdl2_mixer
35+
36+
- name: Install deps (Linux)
37+
if: runner.os == 'Linux'
38+
run: |
39+
sudo apt-get update
40+
sudo apt-get install -y cmake ninja-build pkg-config \
41+
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev
42+
43+
# - name: Install deps (Windows via vcpkg)
44+
# if: runner.os == 'Windows'
45+
# shell: bash
46+
# run: |
47+
# git clone https://github.com/microsoft/vcpkg.git
48+
# ./vcpkg/bootstrap-vcpkg.sh
49+
# ./vcpkg/vcpkg install sdl2 sdl2-image sdl2-mixer --triplet x64-windows
50+
# echo "CMAKE_TOOLCHAIN_FILE=$PWD/vcpkg/scripts/buildsystems/vcpkg.cmake" >> $GITHUB_ENV
51+
52+
# ---------------------
53+
# Configure & Build
54+
# ---------------------
55+
- name: Configure & Build (macOS)
56+
if: runner.os == 'macOS'
57+
run: |
58+
make prod-arm
59+
60+
- name: Configure & Build (Linux)
61+
if: runner.os == 'Linux'
62+
run: |
63+
make prod-linux
64+
65+
# - name: Configure & Build (Windows)
66+
# if: runner.os == 'Windows'
67+
# shell: bash
68+
# run: |
69+
# cmake -S . -B build-win -G Ninja -DCMAKE_BUILD_TYPE=Release \
70+
# -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}"
71+
# cmake --build build-win --config Release
72+
73+
# ---------------------
74+
# macOS-specific post steps
75+
# ---------------------
76+
- name: Ad-hoc sign app (macOS)
77+
if: runner.os == 'macOS'
78+
run: codesign --force --deep --sign - build-arm/mario_isn.app
79+
80+
- name: Package artifact (macOS)
81+
if: runner.os == 'macOS'
82+
run: |
83+
cd build-arm
84+
zip -r MarioISN-macos-arm.zip mario_isn.app
85+
86+
# ---------------------
87+
# Linux packaging
88+
# ---------------------
89+
- name: Package artifact (Linux)
90+
if: runner.os == 'Linux'
91+
run: |
92+
cd build-linux
93+
tar -czf MarioISN-linux.tar.gz mario_isn img musique bin || true
94+
95+
# - name: Package artifact (Windows)
96+
# if: runner.os == 'Windows'
97+
# shell: bash
98+
# run: |
99+
# cd build-win
100+
# 7z a MarioISN-windows.zip .\Release\mario_isn.exe
101+
102+
# ---------------------
103+
# Upload artifacts
104+
# ---------------------
105+
- name: Upload artifact (macOS)
106+
if: runner.os == 'macOS'
107+
uses: actions/upload-artifact@v4
108+
with:
109+
name: MarioISN-macos-arm
110+
path: build-arm/MarioISN-macos-arm.zip
111+
112+
- name: Upload artifact (Linux)
113+
if: runner.os == 'Linux'
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: MarioISN-linux
117+
path: build-linux/MarioISN-linux.tar.gz
118+
119+
# - name: Upload artifact (Windows)
120+
# if: runner.os == 'Windows'
121+
# uses: actions/upload-artifact@v4
122+
# with:
123+
# name: MarioISN-windows
124+
# path: build-win/MarioISN-windows.zip

.github/workflows/release.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name: Release
22
on:
3-
push:
4-
branches:
5-
- main
6-
workflow_dispatch:
3+
workflow_run:
4+
workflows: ["Build MarioISN (macOS & Linux)"] # nom du workflow build
5+
types: [completed]
76

87
permissions:
98
contents: write
109
issues: write
1110
pull-requests: write
11+
actions: read # nécessaire pour télécharger les artefacts d’un autre workflow run
1212

1313
jobs:
1414
release:
15+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1516
runs-on: ubuntu-latest
1617
steps:
1718
- name: Checkout
@@ -24,6 +25,13 @@ jobs:
2425
with:
2526
node-version: '20'
2627

28+
# Télécharge les artefacts du run qui vient de finir
29+
- name: Download artifacts from build run
30+
uses: actions/download-artifact@v4
31+
with:
32+
run-id: ${{ github.event.workflow_run.id }}
33+
path: dist
34+
2735
- name: Install
2836
run: npm ci
2937

.releaserc.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" }],
1010
["@semantic-release/exec", { "prepareCmd": "scripts/update_version.sh ${nextRelease.version}" }],
1111
["@semantic-release/git", { "assets": ["CHANGELOG.md", "CMakeLists.txt"] }],
12-
"@semantic-release/github"
12+
["@semantic-release/git",
13+
{ "assets": ["CHANGELOG.md"],
14+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" }
15+
],
16+
["@semantic-release/github",
17+
{ "assets": [
18+
{ "path": "dist/MarioISN-macos-arm.zip", "label": "macOS (Apple Silicon)" },
19+
{ "path": "dist/MarioISN-linux.tar.gz", "label": "Linux" }
20+
]
21+
}
22+
]
1323
]
1424
}

CMakeLists.txt

Lines changed: 113 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
1+
12
cmake_minimum_required(VERSION 3.20)
23
project(mario_isn C)
34

4-
# Langage & bundle macOS
5+
# =====================================
6+
# Language / IDE helpers
7+
# =====================================
58
set(CMAKE_C_STANDARD 99)
6-
set(CMAKE_MACOSX_BUNDLE TRUE)
7-
set(MACOSX_BUNDLE_BUNDLE_NAME "MarioISN")
8-
set(MACOSX_BUNDLE_GUI_IDENTIFIER "fr.aymnms.marioisn")
9-
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0.0")
10-
set(MACOSX_BUNDLE_LONG_VERSION_STRING "1.0")
11-
set(MACOSX_BUNDLE_BUNDLE_VERSION "1.0.0")
12-
set(MACOSX_BUNDLE_ICON_FILE MyIcon.icns)
13-
14-
# Pour VS Code / IntelliSense
159
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1610

17-
# Trouver SDL2 via les packages CMake fournis par Homebrew
18-
find_package(SDL2 REQUIRED CONFIG)
19-
find_package(SDL2_image REQUIRED CONFIG)
20-
find_package(SDL2_mixer REQUIRED CONFIG)
11+
# =====================================
12+
# Platform-specific bundle/target settings
13+
# =====================================
14+
# On macOS we build an .app bundle; on other OSes we build a regular executable
15+
if(APPLE)
16+
set(PLATFORM_BUNDLE MACOSX_BUNDLE)
17+
set(CMAKE_MACOSX_BUNDLE TRUE)
18+
set(MACOSX_BUNDLE_BUNDLE_NAME "MarioISN")
19+
set(MACOSX_BUNDLE_GUI_IDENTIFIER "fr.aymnms.marioisn")
20+
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0.0")
21+
set(MACOSX_BUNDLE_LONG_VERSION_STRING "1.0")
22+
set(MACOSX_BUNDLE_BUNDLE_VERSION "1.0.0")
23+
set(MACOSX_BUNDLE_ICON_FILE MyIcon.icns)
24+
endif()
25+
26+
# =====================================
27+
# Dependencies: SDL2 family
28+
# Try CMake config packages first (Homebrew/vcpkg), fallback to pkg-config (Linux)
29+
# =====================================
30+
find_package(SDL2 QUIET CONFIG)
31+
find_package(SDL2_image QUIET CONFIG)
32+
find_package(SDL2_mixer QUIET CONFIG)
2133

22-
# Exécutable (cible)
23-
add_executable(mario_isn MACOSX_BUNDLE
34+
if(NOT SDL2_FOUND OR NOT SDL2_image_FOUND OR NOT SDL2_mixer_FOUND)
35+
find_package(PkgConfig REQUIRED)
36+
pkg_check_modules(SDL2 REQUIRED sdl2)
37+
pkg_check_modules(SDL2_image REQUIRED SDL2_image)
38+
pkg_check_modules(SDL2_mixer REQUIRED SDL2_mixer)
39+
set(HAVE_SDL_PKGCFG TRUE)
40+
endif()
41+
42+
# =====================================
43+
# Executable target
44+
# =====================================
45+
add_executable(mario_isn ${PLATFORM_BUNDLE}
46+
src/globals.c
2447
src/main.c
2548
src/display.c
2649
src/path.c
2750
src/menu/init_menu.c
28-
src/menu/menu.c
51+
src/menu/MENU.c
2952
src/game/init_game.c
3053
src/game/GAME.c
3154
src/game/conditions.c
@@ -39,29 +62,83 @@ add_executable(mario_isn MACOSX_BUNDLE
3962
src/game/joueur/music.c
4063
src/game/joueur/niveau.c
4164
src/game/joueur/saut_joueur.c
42-
${CMAKE_SOURCE_DIR}/ressources/MyIcon.icns
4365
)
4466

45-
# Indique où la placer dans le bundle
46-
set_source_files_properties(${CMAKE_SOURCE_DIR}/ressources/MyIcon.icns
47-
PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
67+
# Autorise les définitions communes (rétro-compatibilité GCC <10)
68+
if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
69+
target_compile_options(mario_isn PRIVATE -fcommon)
70+
endif()
4871

49-
# Portée des includes du projet (headers locaux)
50-
target_include_directories(mario_isn PRIVATE
51-
${CMAKE_SOURCE_DIR}/include
52-
)
72+
# Add headers include path (project-local)
73+
target_include_directories(mario_isn PRIVATE ${CMAKE_SOURCE_DIR}/include)
5374

54-
# Lien contre SDL2 (targets importées = include + libs + defines gérés)
55-
target_link_libraries(mario_isn PRIVATE
75+
# Link SDL depending on how it was found
76+
if(NOT HAVE_SDL_PKGCFG)
77+
target_link_libraries(mario_isn PRIVATE
5678
SDL2::SDL2
5779
SDL2_image::SDL2_image
58-
SDL2_mixer::SDL2_mixer
59-
)
80+
SDL2_mixer::SDL2_mixer)
81+
else()
82+
target_include_directories(mario_isn PRIVATE
83+
${SDL2_INCLUDE_DIRS} ${SDL2_image_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIRS})
84+
target_link_libraries(mario_isn PRIVATE
85+
${SDL2_LINK_LIBRARIES} ${SDL2_image_LINK_LIBRARIES} ${SDL2_mixer_LINK_LIBRARIES})
86+
endif()
6087

61-
# Copie des assets dans le bundle .app (Resources)
62-
add_custom_command(TARGET mario_isn POST_BUILD
63-
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources
64-
COMMAND ${CMAKE_COMMAND} -E copy_directory
65-
${CMAKE_SOURCE_DIR}/ressources
66-
$<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources
67-
)
88+
# =====================================
89+
# Resources / Assets
90+
# =====================================
91+
# Project resources layout at source:
92+
# ressources/
93+
# MyIcon.icns
94+
# img/ musique/ bin/
95+
96+
if(APPLE)
97+
# Add icon into the bundle and place it under Contents/Resources
98+
target_sources(mario_isn PRIVATE ${CMAKE_SOURCE_DIR}/ressources/MyIcon.icns)
99+
set_source_files_properties(${CMAKE_SOURCE_DIR}/ressources/MyIcon.icns
100+
PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
101+
102+
# Copy assets into the app bundle Resources so SDL_GetBasePath() finds img/, musique/, bin/
103+
add_custom_command(TARGET mario_isn POST_BUILD
104+
COMMAND ${CMAKE_COMMAND} -E make_directory
105+
$<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources
106+
COMMAND ${CMAKE_COMMAND} -E copy_directory
107+
${CMAKE_SOURCE_DIR}/ressources/img
108+
$<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources/img
109+
COMMAND ${CMAKE_COMMAND} -E copy_directory
110+
${CMAKE_SOURCE_DIR}/ressources/musique
111+
$<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources/musique
112+
COMMAND ${CMAKE_COMMAND} -E copy_directory
113+
${CMAKE_SOURCE_DIR}/ressources/bin
114+
$<TARGET_BUNDLE_CONTENT_DIR:mario_isn>/Resources/bin
115+
)
116+
117+
elseif(WIN32)
118+
# On Windows, copy assets next to the .exe
119+
add_custom_command(TARGET mario_isn POST_BUILD
120+
COMMAND ${CMAKE_COMMAND} -E copy_directory
121+
${CMAKE_SOURCE_DIR}/ressources/img
122+
$<TARGET_FILE_DIR:mario_isn>/img
123+
COMMAND ${CMAKE_COMMAND} -E copy_directory
124+
${CMAKE_SOURCE_DIR}/ressources/musique
125+
$<TARGET_FILE_DIR:mario_isn>/musique
126+
COMMAND ${CMAKE_COMMAND} -E copy_directory
127+
${CMAKE_SOURCE_DIR}/ressources/bin
128+
$<TARGET_FILE_DIR:mario_isn>/bin
129+
)
130+
131+
elseif(UNIX)
132+
# On Linux, copy assets next to the executable
133+
add_custom_command(TARGET mario_isn POST_BUILD
134+
COMMAND ${CMAKE_COMMAND} -E copy_directory
135+
${CMAKE_SOURCE_DIR}/ressources/img
136+
$<TARGET_FILE_DIR:mario_isn>/img
137+
COMMAND ${CMAKE_COMMAND} -E copy_directory
138+
${CMAKE_SOURCE_DIR}/ressources/musique
139+
$<TARGET_FILE_DIR:mario_isn>/musique
140+
COMMAND ${CMAKE_COMMAND} -E copy_directory
141+
${CMAKE_SOURCE_DIR}/ressources/bin
142+
$<TARGET_FILE_DIR:mario_isn>/bin
143+
)
144+
endif()

0 commit comments

Comments
 (0)