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

Draft: use conan for dependencies #1818

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ endif (RECOIL_DETAILED_TRACY_ZONING)

# Note the missing REQUIRED, as headless & dedi may not depend on those.
# So req. checks are done in the build target's CMakeLists.txt.
find_package(SDL2)
find_package(SDL2 MODULE)

find_package_static(DevIL 1.8.0 REQUIRED)

Expand Down
89 changes: 89 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from conan import ConanFile, __version__ as conan_version
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.files import load
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
import os

required_conan_version = ">=2.0.0"

class RecoilConan(ConanFile):
name = "recoil"
license = "GPL-2.0-or-later"
homepage = "https://github.com/beyond-all-reason/spring"
description = "Recoil is an open source real time strategy game engine."
topics = ("game-engine", "open-source")
package_type = "application"
version="105.0"

exports_sources = "CMakeLists.txt", "src/*", "cmake/*", "cpack/*", "docs/*", "examples/*", "share/*", "tests/*",\
"VERSION", "README.md"
no_copy_source = True
settings = "os", "compiler", "build_type", "arch"
options = {
}
default_options = {
}

@property
def _testing_enabled(self):
return not self.conf.get("tools.build:skip_test", default=True, check_type=bool)

def requirements(self):
self.requires("opengl/system")
self.requires("glew/2.2.0")
self.requires("zlib/1.2.13")
self.requires("devil/1.8.0")
self.requires("libunwind/1.8.1", force=True)
self.requires("zstd/1.5.6", override=True)
#self.requires("libpng/1.6.37")
#self.requires("giflib/5.2.1")
self.requires("ogg/1.3.5")
self.requires("vorbis/1.3.7")
self.requires("sdl/2.0.20")
self.requires("libcurl/7.88.1")
self.requires("openal-soft/1.23.1")

def configure(self):
self.options["glew"].with_glu = "system"
self.options["openal-soft"].shared = True
if self.settings.os == "Linux":
self.options["sdl"].wayland = False # Disable wayland build for now
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I use engine natively on Wayland

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now I had a lot of issues with the SDL recipe to actually build with wayland. I'll try and get it working before making the PR ready

self.options["sdl"].pulse = False
self.options["sdl"].alsa = False

def build_requirements(self):
pass

def generate(self):
tc = CMakeToolchain(self)
tc.user_presets_path = False
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def validate(self):
check_min_cppstd(self, "20")

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

if self._testing_enabled:
cmake.test()

def package(self):
cmake = CMake(self)
cmake.install()

def layout(self):
cmake_layout(self)
build_folder = self.conf.get("user.cmake.cmake_layout:build_folder",
default=f"cmake-build-{str(self.settings.build_type).lower()}")

self.folders.build = build_folder
self.folders.generators = f"{build_folder}/conan"
self.folders.source = "."
self.cpp.source.includedirs = "src"
36 changes: 29 additions & 7 deletions docker-build-v2/amd64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,33 @@ RUN apt-get update \
&& add-apt-repository ppa:ubuntu-toolchain-r/test --yes \
&& apt-get update \
&& apt-get install --no-install-recommends --yes \
curl gcc-13 g++-13 git ninja-build curl p7zip-full python3-pip python3-setuptools \
libsdl2-dev libopenal-dev libfreetype6-dev libfontconfig1-dev \
curl gcc-13 g++-13 git ninja-build p7zip-full python3.8 python3.8-distutils \
xz-utils build-essential \
libgl-dev \
libglu-dev \
xorg-dev \
libxcb1-dev \
libxcb-util-dev \
libxcb-render-util0-dev \
libxcb-xkb-dev \
libxcb-icccm4-dev \
libxcb-image0-dev \
libxcb-keysyms1-dev \
libxcb-xinerama0-dev \
libxcb-cursor-dev \
libxcb-composite0-dev \
libxcb-ewmh-dev \
libxcb-res0-dev \
Comment on lines +14 to +28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are added because conan's xorg/system package uses system packages.

uuid-dev \
&& apt-get remove --purge --yes software-properties-common \
&& apt-get autoremove --purge --yes \
&& apt-get upgrade --yes \
&& rm -rf /var/lib/apt/lists/*

# pip for python3.8
RUN curl -L -O https://bootstrap.pypa.io/get-pip.py && python3.8 get-pip.py && rm get-pip.py
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 10

# We need a newer ccache for compression support
ARG CCACHE_VERSION="4.10.2"
RUN curl -L -O https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-x86_64.tar.xz \
Expand All @@ -33,16 +53,17 @@ RUN git clone --depth 1 --branch v1.5.6 https://github.com/facebook/zstd.git \

RUN pip3 install --upgrade pip \
&& pip3 install scikit-build \
&& pip3 install cmake==3.27.*
&& pip3 install cmake==3.27.* \
&& pip3 install conan==2.10.2

WORKDIR /build
RUN mkdir src cache out artifacts && chmod a+rwx cache out artifacts

# Fetch library dependencies and configure resolution
RUN git clone --depth=1 https://github.com/beyond-all-reason/spring-static-libs.git -b 18.04 spring-static-libs
ENV PKG_CONFIG_LIBDIR=/build/spring-static-libs/lib/pkgconfig
ENV PKG_CONFIG="pkg-config --define-prefix --static"
ENV CMAKE_PREFIX_PATH=/build/spring-static-libs/
#RUN git clone --depth=1 https://github.com/beyond-all-reason/spring-static-libs.git -b 18.04 spring-static-libs
#ENV PKG_CONFIG_LIBDIR=/build/spring-static-libs/lib/pkgconfig
#ENV PKG_CONFIG="pkg-config --define-prefix --static"
#ENV CMAKE_PREFIX_PATH=/build/spring-static-libs/
ENV PREFER_STATIC_LIBS=TRUE

# Set up default cmake toolchain
Expand All @@ -54,3 +75,4 @@ COPY ccache.conf .
ENV CCACHE_CONFIGPATH=/build/ccache.conf
ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache
ENV CMAKE_C_COMPILER_LAUNCHER=ccache
ENV CONAN_HOME=/build/.conan2
14 changes: 14 additions & 0 deletions docker-build-v2/amd64-linux/conan_build_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[settings]
arch=x86_64
build_type=RelWithDebInfo
compiler=gcc
compiler.cppstd=gnu20
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux

[conf]
tools.build:compiler_executables={'c': '/usr/bin/gcc-13', 'cpp': '/usr/bin/g++-13' }
tools.cmake.cmaketoolchain:user_toolchain+=/build/toolchain.cmake
user.cmake.cmake_layout:build_folder=/build/out
tools.build.cross_building:cross_build=True
40 changes: 34 additions & 6 deletions docker-build-v2/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

set -e -u -o pipefail

USAGE="Usage: $0 [--help] [--configure|--compile] {windows|linux} [cmake_flag...]"
USAGE="Usage: $0 [--help] [--deps|--configure|--compile] {windows|linux} [cmake_flag...]"
export DEPS=true
export CONFIGURE=true
export COMPILE=true
OS=
export OS=
for arg in "$@"; do
case $arg in
--deps)
DEPS=true
CONFIGURE=false
COMPILE=false
shift
;;
--configure)
DEPS=false
CONFIGURE=true
COMPILE=false
shift
;;
--compile)
DEPS=false
CONFIGURE=false
COMPILE=true
shift
Expand All @@ -22,6 +31,7 @@ for arg in "$@"; do
echo $USAGE
echo "Options:"
echo " --help print this help message"
echo " --deps only install conan dependencies, don't configure or compile"
echo " --configure only configure, don't compile"
echo " --compile only compile, don't configure"
exit 0
Expand All @@ -40,7 +50,9 @@ if [[ -z $OS ]]; then
fi

cd "$(dirname "$(readlink -f "$0")")/.."
mkdir -p build-$OS .cache/ccache-$OS
mkdir -p build-$OS .cache/ccache-$OS .conan2-$OS/profiles
cp docker-build-v2/conan_profile .conan2-$OS/profiles
cp docker-build-v2/amd64-$OS/conan_build_profile .conan2-$OS/profiles

# Use localy build image if available, and pull from upstream if not
image=recoil-build-amd64-$OS:latest
Expand All @@ -49,21 +61,37 @@ if [[ -z "$(docker images -q $image 2> /dev/null)" ]]; then
docker pull $image
fi

docker run -it --rm \
-v /etc/passwd:/etc/passwd:ro \
# Podman assigns root id to the user so trying to set the user
# Won't work
check_is_podman() {
docker --version | grep -c "podman version"
}
set_usr_args=""
if [[ "$(check_is_podman)" -eq 0 ]]; then
echo "Using non-emulated docker"
set_usr_args="-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
--user=$(id -u):$(id -g) \
--user=$(id -u):$(id -g)"
fi

docker run -it --rm \
-v $(pwd):/build/src:ro \
${set_usr_args} \
-v $(pwd)/.cache/ccache-$OS:/build/cache:rw \
-v $(pwd)/build-$OS:/build/out:rw \
-v $(pwd)/.conan2-$OS:/build/.conan2:rw \
-e CONFIGURE \
-e COMPILE \
-e OS \
$image \
bash -c '
set -e
echo "$@"
cd /build/src/docker-build-v2/scripts
$DEPS && ./graph-deps.sh "$@"
$DEPS && ./deps.sh "$@"
$CONFIGURE && ./configure.sh "$@"
export OS
if $COMPILE; then
./compile.sh
# When compiling for windows, we must strip debug info because windows does
Expand Down
14 changes: 14 additions & 0 deletions docker-build-v2/conan_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[settings]
arch=x86_64
build_type=RelWithDebInfo
compiler=gcc
compiler.cppstd=gnu20
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux

[conf]
tools.build:compiler_executables={'c': '/usr/bin/gcc-13', 'cpp': '/usr/bin/g++-13' }
tools.cmake.cmaketoolchain:user_toolchain+=/build/toolchain.cmake
user.cmake.cmake_layout:build_folder=/build/out
tools.build.cross_building:cross_build=True
2 changes: 2 additions & 0 deletions docker-build-v2/scripts/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ cmake --fresh -S /build/src -B /build/out \
-DCMAKE_INSTALL_PREFIX:PATH=/build/out/install \
-DAI_EXCLUDE_REGEX="^CppTestAI$" \
-DUSERDOCS_PLAIN=ON \
-DPR_DOWNLOADER_FIND_CURL_NO_PKGCONFIG=ON \
-DCMAKE_BUILD_TYPE=RELWITHDEBINFO \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O3 -g -DNDEBUG" \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O3 -g -DNDEBUG" \
-DCMAKE_TOOLCHAIN_FILE="conan/conan_toolchain.cmake" \
-G Ninja \
"$@"
11 changes: 11 additions & 0 deletions docker-build-v2/scripts/deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

export CMAKE_TOOLCHAIN_FILE=

conan install \
-u \
-r conancenter \
-pr:h conan_profile \
-pr:b conan_build_profile \
--build=missing \
/build/src
9 changes: 9 additions & 0 deletions docker-build-v2/scripts/graph-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

conan graph info \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prints out useful info (i.e. what all packages are being built and what packages are depending on other packages)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's non-obvious enough to require a comment here, it probably warrants a proper comment in the file. Ditto for the other one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do so, I mostly commented as I'm not sure how familiar people are with conan

-u \
-r conancenter \
-pr:h conan_profile \
-pr:b conan_build_profile \
--format=html \
/build/src > /build/out/graph.html
1 change: 0 additions & 1 deletion rts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ endif (UNIX AND NOT MINGW)

find_package_static(ZLIB 1.2.7 REQUIRED)
list(APPEND engineCommonLibraries DevIL::IL)

list(APPEND engineCommonLibraries 7zip prd::jsoncpp ${SPRING_MINIZIP_LIBRARY} ZLIB::ZLIB Tracy::TracyClient)
list(APPEND engineCommonLibraries lua luasocket archives assimp
gflags_nothreads_static)
Expand Down
7 changes: 4 additions & 3 deletions rts/Sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ add_library(engineSim STATIC
"${CMAKE_CURRENT_SOURCE_DIR}/Weapons/WeaponTarget.cpp"
)

target_include_directories(engineSim
PRIVATE ${SDL2_INCLUDE_DIR})
target_link_libraries(engineSim Tracy::TracyClient)
target_link_libraries(engineSim SDL2::SDL2 Tracy::TracyClient)

find_package_static(GLEW 2.2.0 REQUIRED)
target_link_libraries(engineSim $<COMPILE_ONLY:GLEW::GLEW>)

if( CMAKE_COMPILER_IS_GNUCXX)
# FIXME: hack to avoid linkers to remove not referenced symbols. required because of
Expand Down
13 changes: 7 additions & 6 deletions rts/System/Sound/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ if (NOT NO_SOUND)
OpenAL/VorbisShared.cpp
)

find_package_static(OpenAL REQUIRED)
include_directories(${OPENAL_INCLUDE_DIR})
find_package_static(OpenAL 1.18.2 REQUIRED)
find_package_static(OggVorbis 1.3.4 REQUIRED)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
find_package_static(GLEW 2.2.0 REQUIRED)
find_package(SDL2 MODULE REQUIRED)

include_directories(${CMAKE_SOURCE_DIR}/include/)
include_directories(${CMAKE_SOURCE_DIR}/include/AL)

add_library(sound STATIC EXCLUDE_FROM_ALL ${soundSources})
target_link_libraries(sound SDL2::SDL2)
target_link_libraries(sound vorbis::vorbisfile vorbis::vorbis Ogg::ogg)
target_link_libraries(sound ${OPENAL_LIBRARY})
target_link_libraries(sound OpenAL::OpenAL)
target_link_libraries(sound Tracy::TracyClient)
target_link_libraries(sound $<COMPILE_ONLY:GLEW::GLEW>)
endif (NOT NO_SOUND)
Loading
Loading