Merge pull request #2612 from kelvie/ccompile-script

Add cross-compile script
develop
Myk 2023-01-22 17:16:33 -08:00 committed by GitHub
commit 2e9a826d21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 114 additions and 2 deletions

1
build/.gitignore vendored

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

@ -0,0 +1,56 @@
#!/bin/bash
set -e
# 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
builder_uid=$(id -u)
mkdir -p win64-cross
mkdir -p win64-cross/output
# Check for sudo; we want to use the real user
if [[ $(id -u) -eq 0 ]]; then
if [[ -z "$SUDO_UID" || "$SUDO_UID" -eq 0 ]]; then
echo "Please don't run this script directly as root, use sudo instead:"
echo
echo " sudo $0"
# This is because we can't change the buildmaster UID in the container to 0 --
# that's already taken by root.
exit 1
fi
# If this was run using sudo, let's make sure the directories are owned by the
# real user (and set the BUILDER_UID to it)
builder_uid=$SUDO_UID
chown $builder_uid win64-cross win64-cross/output
fi
# 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
if ! docker run --rm -it -v "$srcdir":/src -v "$srcdir/build/win64-cross/":/src/build \
-e BUILDER_UID=$builder_uid \
--name dfhack-win \
dfhack-build-msvc bash -c "cd /src/build && dfhack-configure windows 64 Release -DCMAKE_INSTALL_PREFIX=/src/build/output cmake .. -DBUILD_DOCS=1 && 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/* ~/.local/share/Steam/steamapps/common/\"Dwarf Fortress\""
fi

@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Fixes ## Fixes
## Misc Improvements ## Misc Improvements
- A new cross-compile build script was added for building the Windows files from a Linux Docker builder (see the Compile instructions in the docs)
- `hotkeys`: clicking on the DFHack logo no longer closes the popup menu - `hotkeys`: clicking on the DFHack logo no longer closes the popup menu
- `orders`: orders plugin functionality is now offered via an overlay widget when the manager orders screen is open - `orders`: orders plugin functionality is now offered via an overlay widget when the manager orders screen is open

@ -284,8 +284,8 @@ addition to the normal ``CC`` and ``CXX`` flags above::
export PATH=/usr/local/bin:$PATH export PATH=/usr/local/bin:$PATH
Windows cross compiling from Linux Windows cross compiling from Linux (running DF inside docker)
================================== =============================================================
.. highlight:: bash .. highlight:: bash
@ -368,6 +368,60 @@ host when you want to reattach::
If you edit code and need to rebuild, run ``dfhack-make`` and then ``ninja install``. If you edit code and need to rebuild, run ``dfhack-make`` and then ``ninja install``.
That will handle all the wineserver management for you. 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 -t dfhack-build-msvc .
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 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``.
If you need to run ``docker`` using ``sudo``, run the script using ``sudo``
rather than directly::
sudo ./build-win64-from-linux.sh
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: .. _note-offline-builds:
Building DFHack Offline Building DFHack Offline