#!/usr/bin/env bash set -euo pipefail # Content copied into the Windows destination after a successful build. SRC_DIR="/home/squid/Documents/Moorly/target/x86_64-pc-windows-gnu/" DEST_DIR="/nextcloud/Stefan/Moorly/Build/" usage() { cat <<'EOF' Usage: ./build.sh Arguments: linux|windows|all Target platform ("all" builds linux, then windows) debug|release Build profile Examples: ./build.sh linux debug ./build.sh linux release ./build.sh windows debug ./build.sh windows release ./build.sh all release On a successful Windows build, the contents of SRC_DIR are copied into a new timestamped (yyyymmdd_hhmmss) folder inside DEST_DIR. Both are configured at the top of this script. Windows builds cross-compile to x86_64-pc-windows-gnu and require: rustup target add x86_64-pc-windows-gnu sudo apt install mingw-w64 EOF } if [ "$#" -ne 2 ]; then usage exit 1 fi case "$1" in linux) ;; windows) ;; all) ;; *) usage exit 1 ;; esac case "$2" in debug) ;; release) ;; *) usage exit 1 ;; esac build() { local os="$1" local profile="$2" local args=(build) [ "$profile" = "release" ] && args+=(--release) [ "$os" = "windows" ] && args+=(--target x86_64-pc-windows-gnu) echo "Building $os ($profile): cargo ${args[*]}" cargo "${args[@]}" } copy_to_destination() { if [ ! -d "$SRC_DIR" ]; then echo "Cannot copy: source folder '$SRC_DIR' does not exist." return 1 fi if [ ! -d "$DEST_DIR" ]; then echo "Cannot copy: destination folder '$DEST_DIR' does not exist." return 1 fi local build_dir="$DEST_DIR/$(date +%Y%m%d_%H%M%S)" mkdir -p "$build_dir" echo "Copying '$SRC_DIR' contents to '$build_dir'..." cp -a "$SRC_DIR"/. "$build_dir"/ echo "Copy completed." } build_windows() { local profile="$1" if ! build windows "$profile"; then echo "Cannot copy: Windows build failed." exit 1 fi copy_to_destination } case "$1" in linux) build linux "$2" ;; windows) build_windows "$2" ;; all) build linux "$2" build_windows "$2" ;; esac