From a72b26c4f2a6a68a93828ced319ccca31babcc5c Mon Sep 17 00:00:00 2001 From: Kelvie Wong Date: Tue, 24 Jan 2023 16:17:49 -0800 Subject: [PATCH 1/4] GHA: Add win64 cross compile build This also removes -t from docker run, as we don't actually require a terminal, this was just muscle memory. This also archives the artifacts for testing. --- .github/workflows/build.yml | 23 +++++++++++++++++++++++ build/build-win64-from-linux.sh | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7819cf2ec..4e959249a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -125,6 +125,29 @@ jobs: run: | rm -rf "$DF_FOLDER" + build-cross-win64: + name: Build MSVC win64 + runs-on: ubuntu-22.04 + steps: + - name: Clone DFHack + uses: actions/checkout@v3 + with: + submodules: true + fetch-depth: 0 + - name: Cross-compile win64 artifacts + run: | + cd build + bash -x build-win64-from-linux.sh + - name: Format artifact name + id: artifactname + run: | + echo name=$(date +%Y%m%d)-$(git rev-parse --short $GITHUB_REF) >> $GITHUB_OUTPUT + - name: Upload win64 artifacts + uses: actions/upload-artifact@v3 + with: + name: dfhack-win64-build-${{ steps.artifactname.outputs.name }} + path: build/win64-cross/output/* + docs: runs-on: ubuntu-18.04 steps: diff --git a/build/build-win64-from-linux.sh b/build/build-win64-from-linux.sh index 08ea88793..65c9f2f58 100755 --- a/build/build-win64-from-linux.sh +++ b/build/build-win64-from-linux.sh @@ -37,10 +37,11 @@ fi # # 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 \ +if ! docker run --rm -i -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" \ + ghcr.io/dfhack/build-env: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" From cf11280b8b917294ff7f950b531d8f220ac0c047 Mon Sep 17 00:00:00 2001 From: Kelvie Wong Date: Tue, 24 Jan 2023 16:22:22 -0800 Subject: [PATCH 2/4] Simplify cross-compile instructions Now that users don't have to build the image. --- docs/dev/compile/Compile.rst | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/docs/dev/compile/Compile.rst b/docs/dev/compile/Compile.rst index f91c43c07..22b9a7b1a 100644 --- a/docs/dev/compile/Compile.rst +++ b/docs/dev/compile/Compile.rst @@ -296,18 +296,13 @@ on a Linux host system. :local: :depth: 1 -Step 1: prepare a docker image ------------------------------- +Step 1: prepare a build container +--------------------------------- On your Linux host, install and run the docker daemon and then run these commands:: xhost +local:root - git clone https://github.com/BenLubar/build-env.git - cd build-env/msvc - docker build . - docker image ls - IMAGE_ID= - docker run -it --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume=/tmp/.X11-unix:/tmp/.X11-unix --user buildmaster --name dfhack-win $IMAGE_ID + docker run -it --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume=/tmp/.X11-unix:/tmp/.X11-unix --user buildmaster --name dfhack-win ghcr.io/dfhack/build-env:msvc The ``xhost`` command and ``--env`` parameters are there so you can eventually run Dwarf Fortress from the container and have it display on your host. @@ -380,19 +375,7 @@ existing Steam installation on Linux. :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 +Step 1: Get dfhack, and run the build script -------------------------------------------- Check out ``dfhack`` into another directory, and run the build script:: @@ -412,7 +395,7 @@ rather than directly:: sudo ./build-win64-from-linux.sh -Step 3: install dfhack to your Steam DF install +Step 2: install dfhack to your Steam DF install ----------------------------------------------- As the script will tell you, you can then copy the files into your DF folder:: From a496f88a296356b15f8fa7208ee58051bf17369d Mon Sep 17 00:00:00 2001 From: Kelvie Wong Date: Tue, 24 Jan 2023 18:48:06 -0800 Subject: [PATCH 3/4] Change $GITHUB_REF to HEAD GITHUB_REF apparently doesn't work in PR builds. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e959249a..b7aeddc70 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -141,7 +141,7 @@ jobs: - name: Format artifact name id: artifactname run: | - echo name=$(date +%Y%m%d)-$(git rev-parse --short $GITHUB_REF) >> $GITHUB_OUTPUT + echo name=$(date +%Y%m%d)-$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT - name: Upload win64 artifacts uses: actions/upload-artifact@v3 with: From 5227d29f1fe7693703ad9b9bcebaaf384d200243 Mon Sep 17 00:00:00 2001 From: Kelvie Wong Date: Tue, 24 Jan 2023 19:27:12 -0800 Subject: [PATCH 4/4] Use GHA caching with ccache --- .github/workflows/build.yml | 8 ++++++++ build/build-win64-from-linux.sh | 2 ++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7aeddc70..9b8892882 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -134,6 +134,14 @@ jobs: with: submodules: true fetch-depth: 0 + - name: Fetch ccache + uses: actions/cache@v3 + with: + path: build/win64-cross/ccache + key: ccache-win64-cross-msvc-${{ github.ref_name }}-${{ github.sha }} + restore-keys: | + ccache-win64-cross-msvc-${{ github.ref_name }} + ccache-win64-cross-msvc - name: Cross-compile win64 artifacts run: | cd build diff --git a/build/build-win64-from-linux.sh b/build/build-win64-from-linux.sh index 65c9f2f58..eb366e83e 100755 --- a/build/build-win64-from-linux.sh +++ b/build/build-win64-from-linux.sh @@ -13,6 +13,7 @@ builder_uid=$(id -u) mkdir -p win64-cross mkdir -p win64-cross/output +mkdir -p win64-cross/ccache # Check for sudo; we want to use the real user if [[ $(id -u) -eq 0 ]]; then @@ -39,6 +40,7 @@ fi # the Dockerfile if ! docker run --rm -i -v "$srcdir":/src -v "$srcdir/build/win64-cross/":/src/build \ -e BUILDER_UID=$builder_uid \ + -e CCACHE_DIR=/src/build/ccache \ --name dfhack-win \ ghcr.io/dfhack/build-env: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" \