Add cross-compile script

That will simply generate the win64 artifacts for those of us that run
DF under Proton on Steam for Linux.
develop
Kelvie Wong 2023-01-14 22:14:06 -08:00
parent 740abba621
commit aaaf2d9f22
3 changed files with 98 additions and 2 deletions

1
build/.gitignore vendored

@ -6,3 +6,4 @@ DF_PATH.txt
_CPack_Packages
*.tar.*
.cmake
win64-cross

@ -0,0 +1,39 @@
#!/usr/bin/env sh
# Number of jobs == core count
jobs=$(grep -c ^processor /proc/cpuinfo)
# Calculate absolute paths for docker to do mounts
srcdir=$(realpath "$(dirname "$(readlink -f "$0")")"/..)
cd "$srcdir"/build
mkdir -p win64-cross
mkdir -p win64-cross/output
# Assumes you built a container image called dfhack-build-msvc from
# https://github.com/BenLubar/build-env/tree/master/msvc, see
# docs/dev/compile/Compile.rst.
#
# NOTE: win64-cross is mounted in /src/build due to the hardcoded `cmake ..` in
# the Dockerfile
#
# TODO: make this work for rootless docker, i.e. remove the sudo for those that
# don't normally need to use sudo to run docker.
if ! sudo docker run --rm -it -v "$srcdir":/src -v "$srcdir/build/win64-cross/":/src/build \
--user buildmaster \
--name dfhack-win \
dfhack-build-msvc bash -c "cd /src/build && dfhack-configure windows 64 Release -DCMAKE_INSTALL_PREFIX=/src/build/output && dfhack-make -j$jobs install" \
; then
echo
echo "Build failed"
exit 1
else
echo
echo "Windows artifacts are at win64-cross/output. Copy or symlink them to"
echo "your steam DF directory to install dfhack (and optionally delete the"
echo "hack/ directory already present)"
echo
echo "Typically this can be done like this:"
echo " cp -r win64-cross/output/* \"$HOME/.local/share/Steam/steamapps/common/Dwarf Fortress\""
fi

@ -284,8 +284,8 @@ addition to the normal ``CC`` and ``CXX`` flags above::
export PATH=/usr/local/bin:$PATH
Windows cross compiling from Linux
==================================
Windows cross compiling from Linux (running DF inside docker)
=============================================================
.. highlight:: bash
@ -368,6 +368,62 @@ host when you want to reattach::
If you edit code and need to rebuild, run ``dfhack-make`` and then ``ninja install``.
That will handle all the wineserver management for you.
Cross-compiling windows files for running DF in Steam for Linux
===============================================================
.. highlight:: bash
If you wish, you can use Docker to build just the Windows files to copy to your
existing Steam installation on Linux.
.. contents::
:local:
:depth: 1
Step 1: Build the MSVC builder image
------------------------------------
It'll be called ``dfhack-build-msvc:latest`` after it's done building::
git clone https://github.com/BenLubar/build-env.git
cd build-env/msvc
docker build --build-arg BUILDER_UID=$(id -u) -t dfhack-build-msvc .
The ``BUILDER_UID`` argument is used to make sure the build user can access your
source code directory inside the container.
The docker build takes a while, but only needs to be done once, unless the build
environment changes.
Step 2: Get dfhack, and run the build script
--------------------------------------------
Check out ``dfhack`` into another directory, and run the build script::
git clone https://github.com/DFHack/dfhack.git
cd dfhack
git submodule update --init --recursive
cd build
./build-win64-from-linux.sh
The last step may ask you for your ``sudo`` password -- if you are able to run
``docker`` without ``sudo`` normally, you can remove the ``sudo`` from the build
script.
The script will mount your host's ``dfhack`` directory to docker, use it to
build the artifacts in ``build/win64-cross``, and put all the files needed to
install in ``build/win64-cross/output``.
Step 3: install dfhack to your Steam DF install
-----------------------------------------------
As the script will tell you, you can then copy the files into your DF folder::
# Optional -- remove the old hack directory in case we leave files behind
rm ~/.local/share/Steam/steamapps/common/"Dwarf Fortress"/hack
cp -r win64-cross/output/* ~/.local/share/Steam/steamapps/common/"Dwarf Fortress"/
Afterward, just run DF as normal.
.. _note-offline-builds:
Building DFHack Offline