Skip to content

Commit adf3f2d

Browse files
Fix assets conversion bug. Add running with docker docs
Using Cython < 3.0.10 leads to the runtime errors on assets conversion. Cython >= 3.0.10 shall be used. Update docker build file and add chapter in documentation about running image with Docker. Issue: #1766
1 parent 777163d commit adf3f2d

File tree

7 files changed

+127
-36
lines changed

7 files changed

+127
-36
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
3939

4040
# Python and Cython requirements
4141
set(PYTHON_MIN_VERSION 3.9)
42-
set(CYTHON_MIN_VERSION 0.29.31)
42+
set(CYTHON_MIN_VERSION 3.0.10)
4343

4444
# CMake policies
4545
foreach(pol

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ Quickstart
127127
make
128128
```
129129

130+
**Alternative approach:**
131+
You can build and run the project using Docker. See [Running with docker](/doc/build_instructions/docker.md) for more details.
132+
130133
* **I compiled everything. Now how do I run it?**
131134
* Execute `cd bin && ./run main`.
132135
* [The convert script](/doc/media_convert.md) will transform original assets into openage formats, which are a lot saner and more moddable.
@@ -145,7 +148,6 @@ To turn them off, use `./bin/run --dont-segfault --no-errors --dont-eat-dog`.
145148
If this still does not help, try our [troubleshooting guide](/doc/troubleshooting.md), the [contact section](#contact)
146149
or the [bug tracker](https://github.com/SFTtech/openage/issues).
147150

148-
149151
Contributing
150152
============
151153

buildsystem/HandlePythonOptions.cmake

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,74 @@
44

55
# the Python version number requirement is in modules/FindPython_test.cpp
66
find_package(Python ${PYTHON_MIN_VERSION} REQUIRED)
7-
find_package(Cython ${CYTHON_MIN_VERSION} REQUIRED)
7+
8+
# Define minimum and fallback versions for Cython
9+
set(CYTHON_MIN_VERSION 3.0.10)
10+
set(CYTHON_MIN_VERSION_FALLBACK 0.29.31)
11+
12+
find_package(Cython QUIET)
13+
if (CYTHON_FOUND AND
14+
((CYTHON_VERSION VERSION_GREATER_EQUAL ${CYTHON_MIN_VERSION}) OR
15+
(CYTHON_VERSION VERSION_GREATER ${CYTHON_MIN_VERSION_FALLBACK} AND CYTHON_VERSION VERSION_LESS 3.0.0)))
16+
message("Using Cython ${CYTHON_VERSION}")
17+
else()
18+
message(FATAL_ERROR "Not found Cython compatible version (>= ${CYTHON_MIN_VERSION} or > ${CYTHON_MIN_VERSION_FALLBACK} in 0.29.x).")
19+
endif()
820

921
py_get_config_var(EXT_SUFFIX PYEXT_SUFFIX)
1022
if(MINGW)
11-
string(REGEX REPLACE "dll" "pyd" PYEXT_SUFFIX "${PYEXT_SUFFIX}")
23+
string(REGEX REPLACE "dll" "pyd" PYEXT_SUFFIX "${PYEXT_SUFFIX}")
1224
endif()
1325

1426
# This is the only useful thing after cleaning up what python suggests
1527
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
16-
set(PYEXT_CXXFLAGS "-fwrapv")
28+
set(PYEXT_CXXFLAGS "-fwrapv")
1729
endif()
1830

1931

2032
# numpy deprecated api
2133
# http://docs.cython.org/en/latest/src/userguide/source_files_and_compilation.html#configuring-the-c-build
2234
if(CYTHON_VERSION VERSION_GREATER_EQUAL 3)
23-
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION")
35+
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION")
2436
else()
2537

26-
# suppress #warning about deprecated numpy api
27-
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
28-
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-cpp")
29-
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
30-
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-#warnings")
31-
endif()
38+
# suppress #warning about deprecated numpy api
39+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
40+
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-cpp")
41+
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
42+
set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-#warnings")
43+
endif()
3244
endif()
3345

3446
# silence cython+python3.8 tp_print deprecation warning
3547
# https://github.com/cython/cython/pull/3201
3648
# https://github.com/cython/cython/issues/3474
3749
if(PYTHON_VER VERSION_GREATER_EQUAL 3.8 AND PYTHON_VERSION VERSION_LESS 3.9)
38-
set(PYEXT_CXXCLAGS "${PYEXT_CXXCLAGS}" "-Wno-deprecated-declarations")
50+
set(PYEXT_CXXCLAGS "${PYEXT_CXXCLAGS}" "-Wno-deprecated-declarations")
3951
endif()
4052

4153
set(PYEXT_LIBRARY "${PYTHON_LIBRARIES}")
4254
message("PYTHON_LIBRARIES: " "${PYTHON_LIBRARIES}")
4355
#Windows always uses optimized version of Python lib
4456
if(WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
45-
#get index of string "optimized" and increment it by 1 so index points at the path of the optimized lib
46-
list (FIND PYEXT_LIBRARY "optimized" _index)
47-
if (${_index} GREATER -1)
48-
MATH(EXPR _index "${_index}+1")
49-
list(GET PYEXT_LIBRARY ${_index} PYEXT_LIBRARY)
50-
endif()
51-
message("force linking to python release lib, instead of debug lib when cythonising")
52-
set(force_optimized_lib_flag "--force_optimized_lib")
57+
#get index of string "optimized" and increment it by 1 so index points at the path of the optimized lib
58+
list(FIND PYEXT_LIBRARY "optimized" _index)
59+
if(${_index} GREATER -1)
60+
MATH(EXPR _index "${_index}+1")
61+
list(GET PYEXT_LIBRARY ${_index} PYEXT_LIBRARY)
62+
endif()
63+
message("force linking to python release lib, instead of debug lib when cythonising")
64+
set(force_optimized_lib_flag "--force_optimized_lib")
5365
endif()
5466

5567
set(PYEXT_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS};${NUMPY_INCLUDE_DIR}")
5668

5769
if(NOT CMAKE_PY_INSTALL_PREFIX)
58-
if(MSVC)
59-
set(CMAKE_PY_INSTALL_PREFIX "python")
60-
else()
61-
# get site-packages directory, prepended with cmake's install prefix
62-
py_exec("import sys, sysconfig, os; print(os.path.join('${CMAKE_INSTALL_PREFIX}', os.path.relpath(sysconfig.get_path('purelib'), os.path.normpath(sys.prefix))))" PREFIX)
63-
set(CMAKE_PY_INSTALL_PREFIX "${PREFIX}")
64-
endif()
70+
if(MSVC)
71+
set(CMAKE_PY_INSTALL_PREFIX "python")
72+
else()
73+
# get site-packages directory, prepended with cmake's install prefix
74+
py_exec("import sys, sysconfig, os; print(os.path.join('${CMAKE_INSTALL_PREFIX}', os.path.relpath(sysconfig.get_path('purelib'), os.path.normpath(sys.prefix))))" PREFIX)
75+
set(CMAKE_PY_INSTALL_PREFIX "${PREFIX}")
76+
endif()
6577
endif()

doc/build_instructions/docker.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
### Running with Docker
2+
3+
Docker simplifies the setup process by providing a consistent development environment. It allows you to build and run the project without manually installing dependencies. Currently provided [Dockerfile.ubuntu.2404](../../packaging/docker/devenv/Dockerfile.ubuntu.2404) supports Ubuntu 24.04 as the base operating system.
4+
5+
#### Prerequisites
6+
7+
- **Docker**: Ensure Docker is installed on your machine. Follow the [official documentation](https://docs.docker.com/) for installation instructions.
8+
- **Display Server**: This guide supports both **X11** and **Wayland** display servers for GUI applications.
9+
- **Tested Configuration**: These instructions were tested on Ubuntu 24.04 running on WSL2 on Windows 11.
10+
11+
#### Steps to Build and Run
12+
13+
1. **Enable GUI Support**
14+
15+
Depending on your display server, follow the appropriate steps:
16+
17+
- **For X11**:
18+
Allow the Docker container to access your X server:
19+
```bash
20+
xhost +local:root
21+
```
22+
23+
- **For Wayland**:
24+
Allow the Docker container to access your Wayland socket:
25+
```bash
26+
sudo chmod a+rw /run/user/$(id -u)/wayland-0
27+
```
28+
29+
2. **Build the Docker Image**
30+
31+
Build the Docker image using the provided Dockerfile:
32+
```bash
33+
sudo docker build -t openage -f packaging/docker/devenv/Dockerfile.ubuntu.2404 .
34+
```
35+
36+
3. **Run the Docker Container**
37+
38+
Start the Docker container with the appropriate configuration for your display server:
39+
40+
- **For X11**:
41+
```bash
42+
docker run -it \
43+
-e DISPLAY=$DISPLAY \
44+
-v /tmp/.X11-unix:/tmp/.X11-unix \
45+
-v $HOME/.Xauthority:/root/.Xauthority \
46+
--network host openage
47+
```
48+
49+
- **For Wayland**:
50+
```bash
51+
docker run -it \
52+
-e XDG_RUNTIME_DIR=/tmp \
53+
-e QT_QPA_PLATFORM=wayland \
54+
-e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
55+
-v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/tmp/$WAYLAND_DISPLAY \
56+
--user=$(id -u):$(id -g) \
57+
--network host openage
58+
```
59+
60+
4. **Follow the Regular Setup**
61+
62+
Once inside the container, follow the regular setup described in the [Development](../building.md#development) chapter. You can skip dependency installation since the Docker image already includes all required dependencies.
63+
64+
#### Notes
65+
66+
- **X11 vs. Wayland**: Ensure you know which display server your system is using. Most modern Linux distributions default to Wayland, but X11 is still widely used.
67+
- **Permissions**: For Wayland, you may need to adjust permissions for the Wayland socket (`/run/user/$(id -u)/wayland-0`) to allow Docker access.
68+
- **GUI Applications**: These configurations enable GUI applications to run inside the Docker container.
69+
70+
By following these steps, you can build and run the `openage` project in a Dockerized environment with support X11 or Wayland display servers.

doc/build_instructions/ubuntu.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
Run the following commands:
44

5-
- `sudo apt-get update`
6-
- `sudo apt-get install g++ cmake cython3 libeigen3-dev libepoxy-dev libfontconfig1-dev libfreetype-dev libharfbuzz-dev libogg-dev libopus-dev libopusfile-dev libpng-dev libtoml11-dev python3-dev python3-mako python3-numpy python3-lz4 python3-pil python3-pip python3-pygments python3-toml qml6-module-qtquick-controls qt6-declarative-dev qt6-multimedia-dev qml6-module-qtquick3d-spatialaudio`
5+
```bash
6+
sudo apt-get update
7+
sudo apt-get install g++ cmake cython3 libeigen3-dev libepoxy-dev libfontconfig1-dev libfreetype-dev libharfbuzz-dev libogg-dev libopus-dev libopusfile-dev libpng-dev libtoml11-dev python3-dev python3-mako python3-numpy python3-lz4 python3-pil python3-pip python3-pygments python3-toml qml6-module-qtquick-controls qt6-declarative-dev qt6-multimedia-dev qml6-module-qtquick3d-spatialaudio
8+
```
79

810
You will also need [nyan](https://github.com/SFTtech/nyan/blob/master/doc/building.md) and its dependencies.
911

10-
# Additional steps for Ubuntu 22.04 LTS
12+
# Additional steps for Ubuntu 22.04 LTS & 24.04 LTS
1113

12-
The available system version of Cython is too old in Ubuntu 22.04. You have to get the correct version
14+
The available system version of Cython is too old in Ubuntu 22.04 & 24.04. You have to get the correct version
1315
from pip:
1416

15-
```
17+
```bash
1618
pip3 install cython --break-system-packages
1719
```
1820

21+
Please note that project requires at least **Cython 3.0.10**.
22+
1923
# Linux Mint Issue
2024
Linux Mint has a [problem with `toml11`](https://github.com/SFTtech/openage/issues/1601), since CMake can't find it. To solve this, download the [toml11.zip](https://github.com/SFTtech/openage/files/13401192/toml11.zip), after, put the files in the `/usr/lib/x86_64-linux-gnu/cmake/toml11` path. (if the `toml11` directory doesn't exist, create it)

doc/building.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Dependency list:
2929

3030
C gcc >=10 or clang >=10
3131
CRA python >=3.9
32-
C cython >=0.29.31
32+
C cython >=3.0.10
3333
C cmake >=3.16
3434
A numpy
3535
A lz4
@@ -161,7 +161,6 @@ The reference package is [created for Gentoo](https://github.com/SFTtech/gentoo-
161161
- Use `make install DESTDIR=/tmp/your_temporary_packaging_dir`,
162162
which will then be packed/installed by your package manager.
163163

164-
165164
### Troubleshooting
166165

167166
- I wanna see compiler invocations

packaging/docker/devenv/Dockerfile.ubuntu.2404

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y sudo \
3636
qt6-multimedia-dev \
3737
qml6-module-qtquick3d-spatialaudio \
3838
&& sudo apt-get clean \
39-
&& truncate -s 0 ~/.bash_history
39+
&& truncate -s 0 ~/.bash_history
40+
41+
# At least cython >= 3.0.10 < 4.0.0 is required to avoid runtime errors
42+
# TODO: Remove this line once cython is upgraded in Ubuntu 24.04.3 (expected around August 2025)
43+
RUN pip install "cython>=3.0.10,<4.0.0" --break-system-packages

0 commit comments

Comments
 (0)