Skip to content
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

Add meson flag for compiling with SDL3 #3141

Merged
merged 4 commits into from
Oct 6, 2024
Merged
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
88 changes: 88 additions & 0 deletions .github/workflows/build-sdl3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# SDL3 porting is WIP
name: SDL3 build

# Run CI only when a release is created, on changes to main branch, or any PR
# to main. Do not run CI on any other branch. Also, skip any non-source changes
# from running on CI
on:
push:
branches: main
paths-ignore:
- 'docs/**'
- 'examples/**'
- '.gitignore'
- '*.rst'
- '*.md'
- '.github/workflows/*.yml'
# re-include current file to not be excluded
- '!.github/workflows/build-sdl3.yml'

pull_request:
branches: main
paths-ignore:
- 'docs/**'
- 'examples/**'
- '.gitignore'
- '*.rst'
- '*.md'
- '.github/workflows/*.yml'
# re-include current file to not be excluded
- '!.github/workflows/build-sdl3.yml'

# the github release drafter can call this workflow
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-ubuntu-sdist
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # if a particular matrix build fails, don't skip the rest
matrix:
os: [ubuntu-24.04, windows-latest, macos-14]

env:
# Pip now forces us to either make a venv or set this flag, so we will do
# this
PIP_BREAK_SYSTEM_PACKAGES: 1
# We are using dependencies installed from apt
PG_DEPS_FROM_SYSTEM: 1

steps:
- uses: actions/[email protected]

- name: Install deps (linux)
if: matrix.os == 'ubuntu-24.04'
run: sudo apt-get install libfreetype6-dev libportmidi-dev python3-dev

- name: Install deps (mac)
if: matrix.os == 'macos-14'
run: brew install freetype portmidi

# taken from https://wiki.libsdl.org/SDL3/Installation
- name: Install SDL3
if: matrix.os != 'windows-latest'
run: |
git clone https://github.com/libsdl-org/SDL
cd SDL
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release --parallel
sudo cmake --install . --config Release

- name: Make sdist and install it
run: >
python3 -m pip install . -v -Csetup-args=-Dsdl_api=3
-Csetup-args=-Dimage=disabled
-Csetup-args=-Dmixer=disabled
-Csetup-args=-Dfont=disabled

# - name: Run tests
# env:
# SDL_VIDEODRIVER: "dummy"
# SDL_AUDIODRIVER: "disk"
# run: python3 -m pygame.tests -v --exclude opengl,music,timing --time_out 300
15 changes: 15 additions & 0 deletions buildconfig/download_win_prebuilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def get_urls(x86=True, x64=True):
'9121a66a4bc45d657d0c15300cee6c7f37ade51d',
],
[
'https://github.com/libsdl-org/SDL/releases/download/preview-3.1.3/SDL3-devel-3.1.3-VC.zip',
'8e4d7104193ba976406fe9968301de6f6b57f342'
],
[
'https://github.com/pygame-community/SDL_image/releases/download/2.8.2-pgce/SDL2_image-devel-2.8.2-VCpgce.zip',
'983484dd816abf25cdd5bce88ac69dbca1ea713a'
],
Expand Down Expand Up @@ -242,6 +246,17 @@ def copy(src, dst):
'SDL2-2.30.7'
)
)
copy(
os.path.join(
temp_dir,
'SDL3-devel-3.1.3-VC/SDL3-3.1.3'
),
os.path.join(
move_to_dir,
prebuilt_dir,
'SDL3-3.1.3'
)
)

def update(x86=True, x64=True):
move_to_dir = "."
Expand Down
130 changes: 74 additions & 56 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ endif

pg_dir = py.get_install_dir() / pg

sdl_api = get_option('sdl_api')
sdl = 'SDL@0@'.format(sdl_api)
sdl_mixer = '@0@_mixer'.format(sdl)
sdl_ttf = '@0@_ttf'.format(sdl)
sdl_image = '@0@_image'.format(sdl)

if sdl_api == 3
add_global_arguments('-DPG_SDL3=1', language: 'c')
endif

pg_inc_dirs = []
pg_lib_dirs = []
if plat == 'win' and host_machine.cpu_family().startswith('x86')
Expand All @@ -99,60 +109,68 @@ if plat == 'win' and host_machine.cpu_family().startswith('x86')
)
endif

sdl_ver = '2.30.7'
sdl_ver = (sdl_api == 3) ? '3.1.3' : '2.30.7'
sdl_image_ver = '2.8.2'
sdl_mixer_ver = '2.8.0'
sdl_ttf_ver = '2.22.0'

dlls = []

# SDL2
sdl_dir = prebuilt_dir / 'SDL2-@0@'.format(sdl_ver)
# SDL
sdl_dir = prebuilt_dir / '@0@-@1@'.format(sdl, sdl_ver)
sdl_lib_dir = sdl_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_dir / 'include', base_dir)
pg_lib_dirs += sdl_lib_dir
dlls += sdl_lib_dir / 'SDL2.dll'

# SDL2_image
sdl_image_dir = prebuilt_dir / 'SDL2_image-@0@'.format(sdl_image_ver)
sdl_image_lib_dir = sdl_image_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_image_dir / 'include', base_dir)
pg_lib_dirs += sdl_image_lib_dir
dlls += [
sdl_image_lib_dir / 'SDL2_image.dll',
sdl_image_lib_dir / 'optional' / 'libjpeg-62.dll',
sdl_image_lib_dir / 'optional' / 'libpng16-16.dll',
sdl_image_lib_dir / 'optional' / 'libtiff-5.dll',
sdl_image_lib_dir / 'optional' / 'libwebp-7.dll',
sdl_image_lib_dir / 'optional' / 'libwebpdemux-2.dll',
]

# SDL2_mixer
sdl_mixer_dir = prebuilt_dir / 'SDL2_mixer-@0@'.format(sdl_mixer_ver)
sdl_mixer_lib_dir = sdl_mixer_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_mixer_dir / 'include', base_dir)
pg_lib_dirs += sdl_mixer_lib_dir
dlls += [
sdl_mixer_lib_dir / 'SDL2_mixer.dll',
sdl_mixer_lib_dir / 'optional' / 'libogg-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libopus-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libopusfile-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libwavpack-1.dll',
sdl_mixer_lib_dir / 'optional' / 'libxmp.dll',
]

# SDL2_ttf
sdl_ttf_dir = prebuilt_dir / 'SDL2_ttf-@0@'.format(sdl_ttf_ver)
sdl_ttf_lib_dir = sdl_ttf_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_ttf_dir / 'include', base_dir)
pg_lib_dirs += sdl_ttf_lib_dir
dlls += sdl_ttf_lib_dir / 'SDL2_ttf.dll'
dlls += sdl_lib_dir / '@[email protected]'.format(sdl)

# SDL_image
if get_option('image').enabled()
sdl_image_dir = prebuilt_dir / '@0@-@1@'.format(sdl_image, sdl_image_ver)
sdl_image_lib_dir = sdl_image_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_image_dir / 'include', base_dir)
pg_lib_dirs += sdl_image_lib_dir
dlls += [
sdl_image_lib_dir / '@[email protected]'.format(sdl_image),
sdl_image_lib_dir / 'optional' / 'libjpeg-62.dll',
sdl_image_lib_dir / 'optional' / 'libpng16-16.dll',
sdl_image_lib_dir / 'optional' / 'libtiff-5.dll',
sdl_image_lib_dir / 'optional' / 'libwebp-7.dll',
sdl_image_lib_dir / 'optional' / 'libwebpdemux-2.dll',
]
endif

# SDL_mixer
if get_option('mixer').enabled()
sdl_mixer_dir = prebuilt_dir / '@0@-@1@'.format(sdl_mixer, sdl_mixer_ver)
sdl_mixer_lib_dir = sdl_mixer_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_mixer_dir / 'include', base_dir)
pg_lib_dirs += sdl_mixer_lib_dir
dlls += [
sdl_mixer_lib_dir / '@[email protected]'.format(sdl_mixer),
sdl_mixer_lib_dir / 'optional' / 'libogg-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libopus-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libopusfile-0.dll',
sdl_mixer_lib_dir / 'optional' / 'libwavpack-1.dll',
sdl_mixer_lib_dir / 'optional' / 'libxmp.dll',
]
endif

# SDL_ttf
if get_option('font').enabled()
sdl_ttf_dir = prebuilt_dir / '@0@-@1@'.format(sdl_ttf, sdl_ttf_ver)
sdl_ttf_lib_dir = sdl_ttf_dir / 'lib' / arch_suffix
pg_inc_dirs += fs.relative_to(sdl_ttf_dir / 'include', base_dir)
pg_lib_dirs += sdl_ttf_lib_dir
dlls += sdl_ttf_lib_dir / '@[email protected]'.format(sdl_ttf)
endif

# freetype, portmidi and porttime
common_lib_dir = prebuilt_dir / 'lib'
pg_inc_dirs += fs.relative_to(prebuilt_dir / 'include', base_dir)
pg_lib_dirs += common_lib_dir
dlls += [common_lib_dir / 'freetype.dll', common_lib_dir / 'portmidi.dll']
if get_option('freetype').enabled() and get_option('midi').enabled()
common_lib_dir = prebuilt_dir / 'lib'
pg_inc_dirs += fs.relative_to(prebuilt_dir / 'include', base_dir)
pg_lib_dirs += common_lib_dir
dlls += [common_lib_dir / 'freetype.dll', common_lib_dir / 'portmidi.dll']
endif

# clean unneeded file that causes build issues
unneeded_file = common_lib_dir / 'libportmidi.dll.a'
Expand Down Expand Up @@ -183,7 +201,7 @@ else
foreach inc_dir : bases
foreach sub_inc : [
'',
'/SDL2',
'/@0@'.format(sdl),
'/freetype2',
]
full_inc = inc_dir / 'include' + sub_inc
Expand All @@ -204,45 +222,45 @@ else
endif

# TODO: add version constraints?
sdl_dep = dependency('sdl2', required: false)
sdl_dep = dependency(sdl, required: false)
if not sdl_dep.found()
sdl_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library('SDL2', dirs: pg_lib_dirs),
dependencies: cc.find_library(sdl, dirs: pg_lib_dirs),
)
endif

# optional
sdl_image_dep = dependency('SDL2_image', required: false)
sdl_image_dep = dependency(sdl_image, required: false)
if not sdl_image_dep.found()
sdl_image_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
'SDL2_image',
sdl_image,
dirs: pg_lib_dirs,
required: get_option('image'),
),
)
endif

sdl_mixer_dep = dependency('SDL2_mixer', required: false)
sdl_mixer_dep = dependency(sdl_mixer, required: false)
if not sdl_mixer_dep.found()
sdl_mixer_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
'SDL2_mixer',
sdl_mixer,
dirs: pg_lib_dirs,
required: get_option('mixer'),
),
)
endif

sdl_ttf_dep = dependency('SDL2_ttf', required: false)
sdl_ttf_dep = dependency(sdl_ttf, required: false)
if not sdl_ttf_dep.found()
sdl_ttf_dep = declare_dependency(
include_directories: pg_inc_dirs,
dependencies: cc.find_library(
'SDL2_ttf',
sdl_ttf,
dirs: pg_lib_dirs,
required: get_option('font'),
),
Expand Down Expand Up @@ -296,10 +314,10 @@ pg_base_deps = [sdl_dep, py_dep]

summary(
{
'SDL2': sdl_dep.found(),
'SDL2_image': sdl_image_dep.found(),
'SDL2_mixer': sdl_mixer_dep.found(),
'SDL2_ttf': sdl_ttf_dep.found(),
sdl: sdl_dep.found(),
sdl_image: sdl_image_dep.found(),
sdl_mixer: sdl_mixer_dep.found(),
sdl_ttf: sdl_ttf_dep.found(),
'freetype2': freetype_dep.found(),
'portmidi': portmidi_dep.found(),
'porttime': portmidi_dep.found() ? porttime_dep.found() : false,
Expand Down
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ option('error_docs_missing', type: 'boolean', value: 'false')
# Controls whether to do a coverage build.
# This argument must be used together with the editable install.
option('coverage', type: 'boolean', value: false)

# Controls whether to use SDL3 instead of SDL2. The default is to use SDL2
option('sdl_api', type: 'integer', min: 2, max: 3, value: 2)
6 changes: 5 additions & 1 deletion src_c/SDL_gfx/SDL_gfxPrimitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ LGPL (c) A. Schiffler
#define M_PI 3.1415926535897932384626433832795
#endif

#include "SDL.h"
#ifdef PG_SDL3
#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif

/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
Expand Down
4 changes: 4 additions & 0 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
#undef PYPY_VERSION
#endif

#ifdef PG_SDL3
#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif

#if SDL_VERSION_ATLEAST(3, 0, 0)
#define PG_ShowCursor SDL_ShowCursor
Expand Down
Loading
Loading