Skip to content

Commit

Permalink
Merge branch 'pygame:main' into Poly_Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
u7156704 committed Oct 21, 2023
2 parents 5245759 + 4065a11 commit b76cbbe
Show file tree
Hide file tree
Showing 25 changed files with 338 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
key: macdep-${{ hashFiles('buildconfig/manylinux-build/**') }}-${{ hashFiles('buildconfig/macdependencies/*.sh') }}-${{ matrix.macarch }}

- name: Build and test wheels
uses: pypa/cibuildwheel@v2.13.1
uses: pypa/cibuildwheel@v2.16.1

- uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-manylinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
- uses: actions/checkout@v3.0.2

- name: Build and test wheels
uses: pypa/cibuildwheel@v2.13.1
uses: pypa/cibuildwheel@v2.16.1

# We upload the generated files under github actions assets
- name: Upload dist
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/build-msys2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: MSYS2 Windows

on:
release:
types: [created]
push:
branches: main
paths-ignore:
- "docs/**"
- "examples/**"
- ".gitignore"
- "*.rst"
- "*.md"
- ".github/workflows/*.yml"
# re-include current file to not be excluded
- "!.github/workflows/build-msys2.yml"

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

jobs:
build:
name: ${{ matrix.sys }} [${{ matrix.env }}]
runs-on: windows-latest

strategy:
matrix:
include:
- { sys: mingw64, env: x86_64 }
# - { sys: mingw32, env: i686 }
# - { sys: ucrt64, env: ucrt-x86_64 }
# - { sys: clang64, env: clang-x86_64 }
steps:
- uses: actions/checkout@v3.0.2
- name: Install MSYS2
uses: msys2/setup-msys2@v2
with:
# update: true
msystem: ${{matrix.sys}}
install: >-
mingw-w64-${{matrix.env}}-python
- name: Install deps
shell: msys2 {0}
run: |
python buildconfig/download_msys2_prebuilt.py
- name: Compile Python Extension using MSYS2
shell: msys2 {0}
run: |
mkdir -p ./wheelhouse
# export PIP_CONFIG_FILE=buildconfig/pip_config.ini
echo "\nBuilding pygame wheel\n"
python setup.py docs
python -m pip wheel . --wheel-dir ./wheelhouse -vvv
echo "\nInstalling wheel\n"
python -m pip install --force-reinstall ./wheelhouse/pygame*.whl
echo "\nRun tests\n"
export SDL_VIDEODRIVER=dummy
export SDL_AUDIODRIVER=disk
python -m test -v --exclude opengl,music,timing --time_out 300
- uses: actions/upload-artifact@v3
with:
name: pygame-msys2-wheels
path: ~/wheelhouse/*.whl
4 changes: 2 additions & 2 deletions .github/workflows/build-ubuntu-sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ jobs:
# install numpy from pip and not apt because the one from pip is newer,
# and has typestubs
run: |
sudo apt-get update --fix-missing
sudo apt-get upgrade
# sudo apt-get update --fix-missing
# sudo apt-get upgrade
sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libfreetype6-dev libportmidi-dev libjpeg-dev python3-setuptools python3-dev
python3 -m pip install sphinx numpy>=1.21.0 Cython==3.0.0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:

- name: Install deps
run: |
sudo apt-get update --fix-missing
sudo apt-get upgrade
# sudo apt-get update --fix-missing
# sudo apt-get upgrade
sudo apt install cppcheck
- name: Run Static Checker
Expand Down
4 changes: 2 additions & 2 deletions buildconfig/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ environment:
- PYTHON: "C:\\Python312\\python"
PYTHONPATH: "C:\\Python312"
PYTHON_VERSION: "3.12.0"
PYTHON_SUFFIX: "b2"
PYTHON_SUFFIX: ""
PYTHON_ARCH: "32"
USE_ANALYZE: ""

Expand Down Expand Up @@ -76,7 +76,7 @@ environment:
- PYTHON: "C:\\Python312-x64\\python"
PYTHONPATH: "C:\\Python312-x64"
PYTHON_VERSION: "3.12.0"
PYTHON_SUFFIX: "b2"
PYTHON_SUFFIX: ""
PYTHON_ARCH: "64"
USE_ANALYZE: ""

Expand Down
23 changes: 14 additions & 9 deletions buildconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@ def writesetupfile(deps, basepath, additional_lines):
parts = l.split()
for al in additional_lines:
aparts = al.split()
if aparts and parts:
if aparts[0] == parts[0]:
#print('the same!' + repr(aparts) + repr(parts))
#the same, we should not add the old one.
#It will be overwritten by the new one.
addit = 0
if (aparts and parts) and (aparts[0] == parts[0]):
#print('the same!' + repr(aparts) + repr(parts))
#the same, we should not add the old one.
#It will be overwritten by the new one.
addit = 0
if addit:
new_lines.append(l)

Expand Down Expand Up @@ -161,6 +160,9 @@ def main(auto=False):
additional_platform_setup = []
conan = "-conan" in sys.argv

setup_path = os.path.join(BASE_PATH, 'Setup')
backup_path = os.path.join(BASE_PATH, 'Setup.bak')

if '-sdl2' in sys.argv:
sys.argv.remove('-sdl2')
if '-sdl1' in sys.argv:
Expand Down Expand Up @@ -223,10 +225,13 @@ def main(auto=False):
os.path.join(BASE_PATH, 'buildconfig', "Setup_Unix.in")).readlines()


if os.path.isfile('Setup'):
if auto:
if os.path.isfile(setup_path) and auto:
try:
logging.info('Backing up existing "Setup" file into Setup.bak')
shutil.copyfile(os.path.join(BASE_PATH, 'Setup'), os.path.join(BASE_PATH, 'Setup.bak'))
shutil.copyfile(setup_path, backup_path)
except Exception as e:
logging.error(f"Failed to backup 'Setup' file: {e}")


deps = CFG.main(**kwds, auto_config=auto)
if '-conan' in sys.argv:
Expand Down
15 changes: 2 additions & 13 deletions buildconfig/config_msys2.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ def setup_prebuilt_sdl2(prebuilt_dir):


def main(auto_config=False):
machine_type = get_machine_type()

# config MSYS2 always requires prebuilt dependencies, in the
# form of packages available in MSYS2.
download_prebuilt = 'PYGAME_DOWNLOAD_PREBUILT' in os.environ
Expand All @@ -479,25 +477,16 @@ def main(auto_config=False):
except ImportError:
import download_msys2_prebuilt

download_kwargs = {
'x86': False,
'x64': False,
}
download_kwargs[machine_type] = True
if download_prebuilt:
download_msys2_prebuilt.update(**download_kwargs)
download_msys2_prebuilt.update()

# MSYS2 config only supports setup with prebuilt dependencies
# The prebuilt dir is the MinGW root from the MSYS2
# installation path. Since we're currently running in a native
# binary, this Python has no notion of MSYS2 or MinGW paths, so
# we convert the prebuilt dir to a Windows absolute path.
# e.g. /mingw64 (MSYS2) -> C:/msys64/mingw64 (Windows)
prebuilt_msys_dir = {
'x86': '/mingw32',
'x64': '/mingw64'
}
prebuilt_dir = get_absolute_win_path(prebuilt_msys_dir[machine_type])
prebuilt_dir = get_absolute_win_path("/" + download_msys2_prebuilt.detect_arch())
return setup_prebuilt_sdl2(prebuilt_dir)


Expand Down
2 changes: 2 additions & 0 deletions buildconfig/config_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __init__(self, name, envname, exename, minver, defaultlibs, version_flag="--
config = (os.popen(command + ' ' + version_flag).readlines() +
os.popen(command + ' --cflags').readlines() +
os.popen(command + ' --libs').readlines())
if not config or len(config) < 3:
raise ValueError(f'Unexpected output from "{command}"')
flags = ' '.join(config[1:]).split()

# remove this GNU_SOURCE if there... since python has it already,
Expand Down
139 changes: 102 additions & 37 deletions buildconfig/download_msys2_prebuilt.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,134 @@
"""
This script install prebuilt dependencies for MSYS2.
It uses pacman to install the dependencies.
See documentation about different environments here:
https://www.msys2.org/docs/environments/
"""
import logging
import os
import subprocess
import sys


def install_pacman_package(pkg_name):
""" This installs a package in the current MSYS2 environment
"""This installs a package in the current MSYS2 environment
Does not download again if the package is already installed
and if the version is the latest available in MSYS2
"""
output = subprocess.run(['pacman', '-S', '--noconfirm', pkg_name],
capture_output=True, text=True)
output = subprocess.run(
["pacman", "-S", "--noconfirm", pkg_name], capture_output=True, text=True
)
if output.returncode != 0:
logging.error(
"Error {} while downloading package {}: \n{}".
format(output.returncode, pkg_name, output.stderr))
"Error {} while downloading package {}: \n{}".format(
output.returncode, pkg_name, output.stderr
)
)

return output.returncode != 0


def get_packages(x86=True, x64=True):
def get_packages(arch: str) -> list:
"""
Returns a list of package names formatted with the specific architecture prefix.
:param arch: The architecture identifier string, e.g., "mingw64", "clang32", etc.
It is used to select the appropriate prefix for package names.
:return: A list of fully formatted package names based on the given architecture.
Example:
If the 'arch' parameter is "mingw32", the return value will be a list like:
[
'mingw-w64-i686-SDL2',
'mingw-w64-i686-SDL2_ttf',
'mingw-w64-i686-SDL2_image',
...
]
"""
deps = [
'mingw-w64-{}-SDL2',
'mingw-w64-{}-SDL2_ttf',
'mingw-w64-{}-SDL2_image',
'mingw-w64-{}-SDL2_mixer',
'mingw-w64-{}-portmidi',
'mingw-w64-{}-libpng',
'mingw-w64-{}-libjpeg-turbo',
'mingw-w64-{}-libtiff',
'mingw-w64-{}-zlib',
'mingw-w64-{}-libwebp',
'mingw-w64-{}-libvorbis',
'mingw-w64-{}-libogg',
'mingw-w64-{}-flac',
'mingw-w64-{}-libmodplug',
'mingw-w64-{}-mpg123',
'mingw-w64-{}-opus',
'mingw-w64-{}-opusfile',
'mingw-w64-{}-freetype'
"{}-SDL2",
"{}-SDL2_ttf",
"{}-SDL2_image",
"{}-SDL2_mixer",
"{}-portmidi",
"{}-libpng",
"{}-libjpeg-turbo",
"{}-libtiff",
"{}-zlib",
"{}-libwebp",
"{}-libvorbis",
"{}-libogg",
"{}-flac",
"{}-libmodplug",
"{}-mpg123",
"{}-opus",
"{}-opusfile",
"{}-freetype",
"{}-python-build",
"{}-python-installer",
"{}-python-setuptools",
"{}-python-wheel",
"{}-python-pip",
"{}-python-numpy",
"{}-python-sphinx",
"{}-cmake",
"{}-cc",
"{}-cython",
]

packages = []
if x86:
packages.extend([x.format('i686') for x in deps])
if x64:
packages.extend([x.format('x86_64') for x in deps])
return packages
full_arch_names = {
"clang32": "mingw-w64-clang-i686",
"clang64": "mingw-w64-clang-x86_64",
"mingw32": "mingw-w64-i686",
"mingw64": "mingw-w64-x86_64",
"ucrt64": "mingw-w64-ucrt-x86_64",
"clangarm64": "mingw-w64-clang-aarch64",
}

return [x.format(full_arch_names[arch]) for x in deps]

def install_prebuilts(x86=True, x64=True):
""" For installing prebuilt dependencies.
"""

def install_prebuilts(arch):
"""For installing prebuilt dependencies."""
errors = False
print("Installing pre-built dependencies")
for pkg in get_packages(x86=x86, x64=x64):
for pkg in get_packages(arch):
print(f"Installing {pkg}")
error = install_pacman_package(pkg)
errors = errors or error
if errors:
raise Exception("Some dependencies could not be installed")


def update(x86=True, x64=True):
install_prebuilts(x86=x86, x64=x64)
def detect_arch():
"""Returns one of: "clang32", "clang64", "mingw32", "mingw64", "ucrt64", "clangarm64".
Based on the MSYSTEM environment variable with a fallback.
"""
msystem = os.environ.get("MSYSTEM", "")
if msystem.startswith("MINGW32"):
return "mingw32"
elif msystem.startswith("MINGW64"):
return "mingw64"
elif msystem.startswith("UCRT64"):
return "ucrt64"
elif msystem.startswith("CLANG32"):
return "clang32"
elif msystem.startswith("CLANGARM64"):
return "clangarm64"
elif msystem.startswith("CLANG64"):
return "clang64"
else:
if sys.maxsize > 2**32:
return "mingw64"
else:
return "mingw32"


def update(arch=None):
install_prebuilts(arch if arch else detect_arch())


if __name__ == '__main__':
if __name__ == "__main__":
update()
Loading

0 comments on commit b76cbbe

Please sign in to comment.