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

Build automation #70

Merged
merged 12 commits into from
Jul 20, 2023
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ newworld/
## Non-static Minetest directories or symlinks to these
/bin/
/games/*
!/games/minetest_game/
!/games/devtest/
/cache
/textures/*
Expand Down Expand Up @@ -102,7 +103,6 @@ doc/mkdocs/mkdocs.yml
build/
build_headless/
CMakeFiles
Makefile
cmake_install.cmake
CMakeCache.txt
CPackConfig.cmake
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
[submodule "lib/zmqpp"]
path = lib/zmqpp
url = [email protected]:zeromq/zmqpp.git
[submodule "games/minetest_game"]
path = games/minetest_game
url = [email protected]:minetest/minetest_game.git
[submodule "lib/SDL"]
path = lib/SDL
url = [email protected]:libsdl-org/SDL.git
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.PHONY: all deps repos sdl2 package zmqpp minetester minetest install demo proto clean

MINETESTER_VERSION := 0.0.1
SDL2_CMAKE_FILE := lib/SDL/build/lib/cmake/SDL2/sdl2-config.cmake
ZMQPP_LIB_FILE := lib/zmqpp/build/max-g++/libzmqpp.a
MINETEST_BINARY := bin/minetest
MINETESTER_WHEEL := build/package/wheel/minetester-$(MINETESTER_VERSION)-py3-none-manylinux_2_35_x86_64.whl

default: minetest

deb_deps:
# Install debian dependencies
util/minetester/install_deps.sh

python_build_deps:
# Install python build dependencies
pip install -r build_requirements.txt

repos:
# Init all submodules
git submodule update --init --recursive

$(SDL2_CMAKE_FILE):
# compile sdl2
util/minetester/build_sdl2.sh

sdl2: $(SDL2_CMAKE_FILE)

proto:
#create protobuf c++ and python files
util/minetester/compile_proto.sh

$(ZMQPP_LIB_FILE):
#compile zmqpp
util/minetester/build_zmqpp.sh

zmqpp: $(ZMQPP_LIB_FILE)


$(MINETEST_BINARY):
#build minetest binary
util/minetester/build_minetest.sh

minetest: $(MINETEST_BINARY)

$(MINETESTER_WHEEL):
#build minetester python library
util/minetester/build_minetester.sh

minetester: $(MINETESTER_WHEEL)

install:
#install python library
pip install $(MINETESTER_WHEEL)

demo:
#install run demo script
python -m minetester.scripts.test_loop

clean:
#clean up repo
util/minetester/clean.sh
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ To verify the installation run
python -m minetester.scripts.test_loop
```

Quick Build Instructions for Linux
==================================

Run these make commands in order to build and install minetester.
If anything goes wrong during install, inspect the relevant entry/script in the Makefile to see what it's trying to do.

```bash
make deb_deps #install debian dependencies, equivalent commands are nessesary for other distros
make python_build_deps #install build dependencies into the local python environment (we reccomend using a venv)
make repos #init submodules
make sdl2 #build sdl2
make zmqpp #build zmqpp
make proto #create c++ and python protobuf files
make minetest #build minetest binary
make minetester #build minetester python library
make install #install python library into local environment along with nessesary dependencies
make demo #run the demo script
make clean #clean up build artifacts
```

Minetest
========

Expand Down
3 changes: 3 additions & 0 deletions build_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setuptools
build
auditwheel
1 change: 1 addition & 0 deletions games/minetest_game
Submodule minetest_game added at 110c23
1 change: 1 addition & 0 deletions lib/SDL
Submodule SDL added at f070c8
2 changes: 0 additions & 2 deletions scripts/compile_proto.sh

This file was deleted.

22 changes: 19 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from setuptools import setup
from setuptools import setup, find_packages

setup(
name='Minetester',
name='minetester',
version='0.0.1',
description='Complex environments based on Minetest.',
author='EleutherAI',
author_email='',
packages=['minetester'],
packages=find_packages(),
install_requires=[
'gym',
'numpy',
Expand All @@ -15,4 +15,20 @@
'protobuf==3.20.1',
'psutil',
],
package_data={
'minetester': [
'minetest/bin/minetest',
rk1a marked this conversation as resolved.
Show resolved Hide resolved
'minetest/client/**/*',
'minetest/clientmods/**/*',
'minetest/cursors/**/*',
'minetest/games/**/*',
'minetest/mods/**/*',
'minetest/textures/**/*',
'minetest/po/**/*',
'minetest/builtin/**/*',
'minetest/misc/**/*',
'minetest/fonts/**/*'
],
},

)
9 changes: 7 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ if(ENABLE_PROTOBUF)
get_filename_component(directory ${file} DIRECTORY)
get_filename_component(truename ${directory}/${basename} ABSOLUTE)
file(RELATIVE_PATH relname ${PROTO_PARENT}/proto ${truename})
set(outnames ${PROJECT_SOURCE_DIR}/${relname}.pb.h ${PROJECT_SOURCE_DIR}/${relname}.pb.cc)
set(outnames ${CMAKE_CURRENT_BINARY_DIR}/${relname}.pb.h ${CMAKE_CURRENT_BINARY_DIR}/${relname}.pb.cc)
add_custom_command(OUTPUT ${outnames}
COMMAND protobuf::protoc
ARGS --cpp_out=. --proto_path ${PROTO_PARENT}/proto ${file}
Expand Down Expand Up @@ -496,7 +496,6 @@ endif(BUILD_CLIENT)

set(client_SRCS
${client_SRCS}
${proto_targets}
${common_SRCS}
${gui_SRCS}
${client_network_SRCS}
Expand All @@ -523,10 +522,16 @@ list(SORT server_SRCS)
# Avoid source_group on broken CMake version.
# see issue #7074 #7075
if (CMAKE_VERSION VERSION_GREATER 3.8.1)
source_group(TREE ${CMAKE_CURRENT_BINARY_DIR} PREFIX "ProtoBuf Source Files" FILES ${proto_targets})
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "Source Files" FILES ${client_SRCS})
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "Source Files" FILES ${server_SRCS})
endif()

set(client_SRCS
${client_SRCS}
${proto_targets}
)

include_directories(
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}
Expand Down
24 changes: 24 additions & 0 deletions util/minetester/build_minetest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ROOT=$(pwd)

mkdir -p build/normal
mkdir -p build/headless

cd build/headless


SDL2_DIR=${ROOT}/lib/SDL/build/lib/cmake/SDL2/

echo ${SDL2_DIR}

cmake ../.. -DRUN_IN_PLACE=TRUE -DBUILD_HEADLESS=1 -DSDL2_DIR=${SDL2_DIR}
make -j$(( $(nproc) > 1 ? $(nproc) - 1 : 1 )) #use max(nproc - 1,1) threads

cd ../..

mv bin/minetest bin/minetest_headless

cd build/normal
cmake ../.. -DRUN_IN_PLACE=TRUE -DBUILD_HEADLESS=0 -DSDL2_DIR=
make -j$(( $(nproc) > 1 ? $(nproc) - 1 : 1 )) #use max(nproc - 1,1) threads


32 changes: 32 additions & 0 deletions util/minetester/build_minetester.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
mkdir -p build/package
cp setup.py build/package/
cp -r minetester build/package/
mkdir build/package/minetester/minetest

#Copy minetest data
cp -r bin build/package/minetester/minetest
cp -r builtin build/package/minetester/minetest
cp -r client build/package/minetester/minetest
cp -r clientmods build/package/minetester/minetest
cp -r cursors build/package/minetester/minetest
cp -r fonts build/package/minetester/minetest
cp -r games build/package/minetester/minetest
cp -r misc build/package/minetester/minetest
cp -r mods build/package/minetester/minetest
cp -r po build/package/minetester/minetest
cp -r textures build/package/minetester/minetest

#Make wheel
cd build/package
python -m build

#Update RPATHS and add relevant libraries to wheel
cd dist
auditwheel repair minetester-*.*.*-py3-none-any.whl --plat manylinux_2_35_x86_64

cd ../../..

mkdir build/package/wheel

cp build/package/dist/wheelhouse/minetester-*.*.*-py3-none-manylinux_2_35_x86_64.whl build/package/wheel

4 changes: 4 additions & 0 deletions util/minetester/build_sdl2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cd lib/SDL
mkdir build
cd build
../configure --prefix=`pwd` && make && make install
2 changes: 2 additions & 0 deletions util/minetester/build_zmqpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd lib/zmqpp
make
2 changes: 2 additions & 0 deletions util/minetester/clean.sh
rk1a marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm -r build
rm bin/*
rk1a marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions util/minetester/compile_proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
protoc -I=proto/ --python_out=minetester/proto --cpp_out=src proto/*.proto
15 changes: 15 additions & 0 deletions util/minetester/install_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Get the operating system name
OS=$(lsb_release -si)

# Check if the OS is Ubuntu
if [ "$OS" == "Ubuntu" ]; then
# If it's Ubuntu, execute the command
echo "You are running Ubuntu. Executing command..."
sudo apt-get install xvfb g++ make libzmq3-dev libtool pkg-config build-essential autoconf automake libc6-dev cmake libpng-dev libjpeg-dev libxi-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev libzstd-dev libluajit-5.1-dev protobuf-compiler patchelf
else
# If it's not Ubuntu, print a message and exit
echo "This script only works on Ubuntu. Exiting."
exit 1
fi