mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-27 23:59:37 -05:00
The helper exited before reading its handoff because wx's command-line parser rejected --handoff. Windows portable updates failed on tar.exe lookup, a working directory inside the install, and the nightly zip's top-level folder. The AppImage helper now ships with its own libraries. - Restrict downloads to https GitHub release URLs, verify TLS on the version check, set CA certificates and FAILONERROR in the downloader. - Rename the verified download to its asset name, hold it open on Windows, and relaunch the app when an update fails before the swap. - Use nowide paths in the helper for non-ASCII Windows user names. - Roll back by renaming the new tree aside; stage Linux copies beside the target; drop the predictable macOS marker file. - Require $APPDIR for AppImage detection; reject read-only macOS volumes. - Check for updates once after Preferences closes, and drop stale results. - Offer releases without a matching asset, key Nightly skips by version, and let Pre-Release offer a newer final release. - Find pending.json from a .backup copy and keep the backup unless the new build is running from the target. - Move the build timestamp into its own generated header so it no longer invalidates ccache on every CI run.
669 lines
23 KiB
Bash
Executable File
669 lines
23 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e # Exit immediately if a command exits with a non-zero status.
|
|
SECONDS=0
|
|
|
|
SCRIPT_NAME=$(basename "$0")
|
|
SCRIPT_PATH=$(dirname "$(readlink -f "${0}")")
|
|
|
|
pushd "${SCRIPT_PATH}" > /dev/null
|
|
|
|
function usage() {
|
|
echo "Usage: ./${SCRIPT_NAME} [-1][-b][-c][-d][-D][-e][-F][-g][-h][-i][-j N][-J N][-p][-r][-s][-t][-u][-l][-L] [-- CMAKE_ARGS...]"
|
|
echo " -1: limit builds to one core (where possible)"
|
|
echo " -j N: limit builds to N cores (where possible)"
|
|
echo " -J N: build up to N dependencies at a time, each still using -j jobs (default: 1)"
|
|
echo " -b: build in Debug mode"
|
|
echo " -c: force a clean build"
|
|
echo " -C: enable ANSI-colored compile output (GNU/Clang only)"
|
|
echo " -d: download and build dependencies in ./deps/ (build prerequisite)"
|
|
echo " -D: dry run"
|
|
echo " -e: build in RelWithDebInfo mode"
|
|
echo " -F: rebuild the cached Docker/Podman runner image from scratch when used with -g"
|
|
echo " -g: run the requested build steps inside a Docker/Podman Ubuntu 24.04 container similar to the GitHub Actions Linux runner"
|
|
echo " -h: prints this help text"
|
|
echo " -i: build the Orca Slicer AppImage (optional)"
|
|
echo " -p: disable precompiled headers (on by default): more ccache hits after header changes, slower misses"
|
|
echo " -r: skip RAM and disk checks (low RAM compiling)"
|
|
echo " -s: build the Orca Slicer (optional)"
|
|
echo " -t: build tests (optional), requires -s flag"
|
|
echo " -u: install system dependencies (asks for sudo password; build prerequisite)"
|
|
echo " -l: use Clang instead of GCC (default: GCC)"
|
|
echo " -L: use ld.lld as linker (if available)"
|
|
echo " -- CMAKE_ARGS...: pass everything after '--' to the cmake configure step of the deps (-d) and OrcaSlicer (-s/-t) builds,"
|
|
echo " e.g. -DCMAKE_CXX_FLAGS=\"-O2 -march=native\", -DCMAKE_CXX_COMPILER=g++-14, -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=mold."
|
|
echo " They come last on the cmake command line, so they override what -l and -L set."
|
|
echo "For a first use, you want to './${SCRIPT_NAME} -u'"
|
|
echo " and then './${SCRIPT_NAME} -dsi'"
|
|
echo "For a GitHub Actions-like Linux build locally, use './${SCRIPT_NAME} -g -istrlL'"
|
|
echo "Use './${SCRIPT_NAME} -gF -istrlL' to rebuild the cached runner image first."
|
|
echo "Set ORCA_CONTAINER_CLI, ORCA_DOCKER_IMAGE, ORCA_DOCKER_BASE_IMAGE, or ORCA_DOCKER_CMAKE_VERSION to override the container runtime, cached image tag, base image, or CMake version."
|
|
echo "DEPS_EXTRA_BUILD_ARGS and ORCA_EXTRA_BUILD_ARGS add whitespace-separated cmake configure arguments to the deps and OrcaSlicer builds; prefer '--' for arguments that contain spaces."
|
|
}
|
|
|
|
SLIC3R_PRECOMPILED_HEADERS="ON"
|
|
DEPS_PARALLEL=""
|
|
|
|
unset name
|
|
BUILD_DIR=build
|
|
BUILD_CONFIG=Release
|
|
FORWARDED_ARGS=()
|
|
while getopts ":1j:J:bcCdDeFghiprstulL" opt ; do
|
|
case ${opt} in
|
|
1 )
|
|
export CMAKE_BUILD_PARALLEL_LEVEL=1
|
|
FORWARDED_ARGS+=("-1")
|
|
;;
|
|
j )
|
|
export CMAKE_BUILD_PARALLEL_LEVEL=$OPTARG
|
|
FORWARDED_ARGS+=("-j" "$OPTARG")
|
|
;;
|
|
J )
|
|
DEPS_PARALLEL=$OPTARG
|
|
FORWARDED_ARGS+=("-J" "$OPTARG")
|
|
;;
|
|
b )
|
|
BUILD_DIR=build-dbg
|
|
BUILD_CONFIG=Debug
|
|
FORWARDED_ARGS+=("-b")
|
|
;;
|
|
c )
|
|
CLEAN_BUILD=1
|
|
FORWARDED_ARGS+=("-c")
|
|
;;
|
|
C )
|
|
COLORED_OUTPUT="-DCOLORED_OUTPUT=ON"
|
|
FORWARDED_ARGS+=("-C")
|
|
;;
|
|
d )
|
|
BUILD_DEPS="1"
|
|
FORWARDED_ARGS+=("-d")
|
|
;;
|
|
D )
|
|
DRY_RUN="1"
|
|
FORWARDED_ARGS+=("-D")
|
|
;;
|
|
e )
|
|
BUILD_DIR=build-dbginfo
|
|
BUILD_CONFIG=RelWithDebInfo
|
|
FORWARDED_ARGS+=("-e")
|
|
;;
|
|
F )
|
|
CLEAN_DOCKER_IMAGE="1"
|
|
;;
|
|
g )
|
|
USE_DOCKER="1"
|
|
;;
|
|
h ) usage
|
|
exit 1
|
|
;;
|
|
i )
|
|
BUILD_IMAGE="1"
|
|
FORWARDED_ARGS+=("-i")
|
|
;;
|
|
p )
|
|
SLIC3R_PRECOMPILED_HEADERS="OFF"
|
|
FORWARDED_ARGS+=("-p")
|
|
;;
|
|
r )
|
|
SKIP_RAM_CHECK="1"
|
|
FORWARDED_ARGS+=("-r")
|
|
;;
|
|
s )
|
|
BUILD_ORCA="1"
|
|
FORWARDED_ARGS+=("-s")
|
|
;;
|
|
t )
|
|
BUILD_TESTS="1"
|
|
FORWARDED_ARGS+=("-t")
|
|
;;
|
|
u )
|
|
export UPDATE_LIB="1"
|
|
FORWARDED_ARGS+=("-u")
|
|
;;
|
|
l )
|
|
USE_CLANG="1"
|
|
FORWARDED_ARGS+=("-l")
|
|
;;
|
|
L )
|
|
USE_LLD="1"
|
|
FORWARDED_ARGS+=("-L")
|
|
;;
|
|
* )
|
|
echo "Unknown argument '${opt}', aborting."
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# getopts stops at '--'; whatever follows is handed to cmake unchanged.
|
|
if [[ ${OPTIND} -le $# ]] ; then
|
|
separator_index=$((OPTIND-1))
|
|
if [[ "${!separator_index}" != "--" ]] ; then
|
|
echo "Unexpected argument '${!OPTIND}': cmake arguments must follow '--', aborting."
|
|
exit 1
|
|
fi
|
|
fi
|
|
shift $((OPTIND-1))
|
|
EXTRA_CMAKE_ARGS=("$@")
|
|
if [[ ${#EXTRA_CMAKE_ARGS[@]} -gt 0 ]] ; then
|
|
FORWARDED_ARGS+=("--" "${EXTRA_CMAKE_ARGS[@]}")
|
|
fi
|
|
|
|
if [ ${OPTIND} -eq 1 ] ; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -n "${CLEAN_DOCKER_IMAGE}" ]] && [[ -z "${USE_DOCKER}" ]] ; then
|
|
echo "Error: -F requires -g."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -n "${DEPS_PARALLEL}" ]] && ! [[ "${DEPS_PARALLEL}" =~ ^[1-9][0-9]*$ ]] ; then
|
|
echo "Error: -J expects a positive integer."
|
|
exit 1
|
|
fi
|
|
|
|
function check_available_memory_and_disk() {
|
|
FREE_MEM_GB=$(free --gibi --total | grep 'Mem' | rev | cut --delimiter=" " --fields=1 | rev)
|
|
MIN_MEM_GB=10
|
|
|
|
FREE_DISK_KB=$(df --block-size=1K . | tail -1 | awk '{print $4}')
|
|
MIN_DISK_KB=$((10 * 1024 * 1024))
|
|
|
|
if [[ ${FREE_MEM_GB} -le ${MIN_MEM_GB} ]] ; then
|
|
echo -e "\nERROR: Orca Slicer Builder requires at least ${MIN_MEM_GB}G of 'available' mem (system has only ${FREE_MEM_GB}G available)"
|
|
echo && free --human && echo
|
|
echo "Invoke with -r to skip RAM and disk checks."
|
|
exit 2
|
|
fi
|
|
|
|
if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]] ; then
|
|
echo -e "\nERROR: Orca Slicer Builder requires at least $(echo "${MIN_DISK_KB}" |awk '{ printf "%.1fG\n", $1/1024/1024; }') (system has only $(echo "${FREE_DISK_KB}" | awk '{ printf "%.1fG\n", $1/1024/1024; }') disk free)"
|
|
echo && df --human-readable . && echo
|
|
echo "Invoke with -r to skip ram and disk checks."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function print_and_run() {
|
|
cmd=()
|
|
# Remove empty arguments, leading and trailing spaces
|
|
for item in "$@" ; do
|
|
if [[ -n $item ]]; then
|
|
cmd+=( "$(echo "${item}" | xargs)" )
|
|
fi
|
|
done
|
|
|
|
echo "${cmd[@]}"
|
|
if [[ -z "${DRY_RUN}" ]] ; then
|
|
"${cmd[@]}"
|
|
fi
|
|
}
|
|
|
|
function resolve_container_cli() {
|
|
if [[ -n "${ORCA_CONTAINER_CLI}" ]] ; then
|
|
if ! command -v "${ORCA_CONTAINER_CLI}" >/dev/null 2>&1 ; then
|
|
echo "Error: container runtime '${ORCA_CONTAINER_CLI}' was not found." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "${ORCA_CONTAINER_CLI}"
|
|
return
|
|
fi
|
|
|
|
if command -v docker >/dev/null 2>&1 ; then
|
|
echo "docker"
|
|
return
|
|
fi
|
|
|
|
if command -v podman >/dev/null 2>&1 ; then
|
|
echo "podman"
|
|
return
|
|
fi
|
|
|
|
echo "Error: neither docker nor podman is available. Install one of them or set ORCA_CONTAINER_CLI." >&2
|
|
exit 1
|
|
}
|
|
|
|
function get_docker_runner_image() {
|
|
local base_image
|
|
local docker_cmake_version
|
|
local recipe_hash
|
|
local sanitized_base_image
|
|
local sanitized_cmake_version
|
|
|
|
if [[ -n "${ORCA_DOCKER_IMAGE}" ]] ; then
|
|
echo "${ORCA_DOCKER_IMAGE}"
|
|
return
|
|
fi
|
|
|
|
base_image="${ORCA_DOCKER_BASE_IMAGE:-ubuntu:24.04}"
|
|
docker_cmake_version="${ORCA_DOCKER_CMAKE_VERSION-4.3.0}"
|
|
recipe_hash=$(find "${SCRIPT_PATH}/build_linux.sh" "${SCRIPT_PATH}/scripts/linux.d" -type f -print0 | sort -z | xargs -0 cat | sha256sum | cut -c1-12)
|
|
sanitized_base_image=$(echo "${base_image}" | tr '/:@' '---' | tr -cs 'A-Za-z0-9_.-' '-')
|
|
sanitized_cmake_version=$(echo "${docker_cmake_version:-system}" | tr -cs 'A-Za-z0-9_.-' '-')
|
|
echo "orcaslicer-linux-builder:${sanitized_base_image}-cmake-${sanitized_cmake_version}-${recipe_hash}"
|
|
}
|
|
|
|
function docker_runner_dockerfile() {
|
|
cat <<'EOF'
|
|
ARG BASE_IMAGE=ubuntu:24.04
|
|
FROM ${BASE_IMAGE}
|
|
|
|
ARG CMAKE_VERSION=4.3.0
|
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
SHELL ["/bin/bash", "-c"]
|
|
|
|
RUN apt-get update && apt-get install -y sudo ca-certificates curl tar
|
|
|
|
COPY build_linux.sh /tmp/orcaslicer/build_linux.sh
|
|
COPY scripts/linux.d /tmp/orcaslicer/scripts/linux.d
|
|
|
|
WORKDIR /tmp/orcaslicer
|
|
|
|
RUN chmod +x ./build_linux.sh
|
|
RUN ./build_linux.sh -ur
|
|
RUN if [[ -n "${CMAKE_VERSION}" ]] ; then \
|
|
case "$(uname -m)" in \
|
|
x86_64|amd64) cmake_arch="x86_64" ;; \
|
|
aarch64|arm64) cmake_arch="aarch64" ;; \
|
|
*) cmake_arch="" ;; \
|
|
esac ; \
|
|
if [[ -n "${cmake_arch}" ]] ; then \
|
|
cmake_root="/opt/cmake-${CMAKE_VERSION}-linux-${cmake_arch}" ; \
|
|
if ! curl -fsSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-${cmake_arch}.tar.gz" | tar -xz -C /opt ; then \
|
|
echo "Warning: failed to install CMake ${CMAKE_VERSION}; falling back to the distro cmake package." ; \
|
|
elif [[ -d "${cmake_root}" ]] ; then \
|
|
ln -sf "${cmake_root}/bin/"* /usr/local/bin/ ; \
|
|
fi ; \
|
|
else \
|
|
echo "Skipping GitHub Actions CMake install for unsupported architecture $(uname -m)." ; \
|
|
fi ; \
|
|
fi
|
|
RUN rm -rf /var/lib/apt/lists/* /tmp/orcaslicer
|
|
EOF
|
|
}
|
|
|
|
function ensure_docker_runner_image() {
|
|
local container_cli
|
|
local base_image
|
|
local runner_image
|
|
local docker_cmake_version
|
|
local image_exists="0"
|
|
local force_rebuild="0"
|
|
local -a build_cmd
|
|
|
|
container_cli="$1"
|
|
runner_image="$2"
|
|
base_image="${ORCA_DOCKER_BASE_IMAGE:-ubuntu:24.04}"
|
|
docker_cmake_version="${ORCA_DOCKER_CMAKE_VERSION-4.3.0}"
|
|
|
|
if "${container_cli}" image inspect "${runner_image}" >/dev/null 2>&1 ; then
|
|
image_exists="1"
|
|
fi
|
|
|
|
if [[ -n "${CLEAN_DOCKER_IMAGE}" ]] ; then
|
|
force_rebuild="1"
|
|
if [[ "${image_exists}" == "1" ]] ; then
|
|
echo "Removing cached container image ${runner_image} ..."
|
|
if [[ -z "${DRY_RUN}" ]] ; then
|
|
"${container_cli}" image rm -f "${runner_image}" >/dev/null
|
|
else
|
|
printf '%q ' "${container_cli}" image rm -f "${runner_image}"
|
|
echo
|
|
fi
|
|
image_exists="0"
|
|
fi
|
|
fi
|
|
|
|
if [[ "${image_exists}" == "1" ]] ; then
|
|
echo "Using cached container image ${runner_image}"
|
|
return
|
|
fi
|
|
|
|
build_cmd=(
|
|
"${container_cli}" build --pull
|
|
-t "${runner_image}"
|
|
--build-arg "BASE_IMAGE=${base_image}"
|
|
--build-arg "CMAKE_VERSION=${docker_cmake_version}"
|
|
)
|
|
if [[ "${force_rebuild}" == "1" ]] ; then
|
|
build_cmd+=(--no-cache)
|
|
fi
|
|
build_cmd+=(-f - "${SCRIPT_PATH}")
|
|
|
|
printf '%q ' "${build_cmd[@]}"
|
|
echo
|
|
if [[ -n "${DRY_RUN}" ]] ; then
|
|
return
|
|
fi
|
|
|
|
docker_runner_dockerfile | "${build_cmd[@]}"
|
|
}
|
|
|
|
function run_in_docker() {
|
|
local container_cli
|
|
local runner_image
|
|
local container_workspace
|
|
local host_uid
|
|
local host_gid
|
|
local host_user
|
|
local -a build_args
|
|
local -a container_env
|
|
|
|
container_cli=$(resolve_container_cli)
|
|
runner_image=$(get_docker_runner_image)
|
|
host_uid=$(id -u)
|
|
host_gid=$(id -g)
|
|
host_user="${USER:-orca}"
|
|
container_workspace="/__w/OrcaSlicer/OrcaSlicer"
|
|
build_args=()
|
|
for item in "${FORWARDED_ARGS[@]}" ; do
|
|
if [[ "${item}" == "-u" ]] || [[ "${item}" == "-D" ]] ; then
|
|
continue
|
|
fi
|
|
|
|
build_args+=("${item}")
|
|
done
|
|
|
|
container_env=(
|
|
-e "CI=true"
|
|
-e "GITHUB_ACTIONS=true"
|
|
-e "GITHUB_WORKSPACE=${container_workspace}"
|
|
-e "RUNNER_OS=Linux"
|
|
-e "RUNNER_TEMP=/tmp"
|
|
-e "HOST_UID=${host_uid}"
|
|
-e "HOST_GID=${host_gid}"
|
|
-e "HOST_USER=${host_user}"
|
|
)
|
|
if [[ -n "${CMAKE_BUILD_PARALLEL_LEVEL}" ]] ; then
|
|
container_env+=( -e "CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL}" )
|
|
fi
|
|
if [[ -n "${ORCA_UPDATER_SIG_KEY}" ]] ; then
|
|
container_env+=( -e "ORCA_UPDATER_SIG_KEY=${ORCA_UPDATER_SIG_KEY}" )
|
|
fi
|
|
if [[ -n "${ORCA_BUILD_TIMESTAMP}" ]] ; then
|
|
container_env+=( -e "ORCA_BUILD_TIMESTAMP=${ORCA_BUILD_TIMESTAMP}" )
|
|
fi
|
|
|
|
ensure_docker_runner_image "${container_cli}" "${runner_image}"
|
|
|
|
printf '%q ' "${container_cli}" run --rm -i \
|
|
-v "${SCRIPT_PATH}:${container_workspace}" \
|
|
-w "${container_workspace}" \
|
|
"${container_env[@]}" \
|
|
"${runner_image}" \
|
|
bash -s -- "${build_args[@]}"
|
|
echo
|
|
if [[ -n "${DRY_RUN}" ]] ; then
|
|
return
|
|
fi
|
|
|
|
"${container_cli}" run --rm -i \
|
|
-v "${SCRIPT_PATH}:${container_workspace}" \
|
|
-w "${container_workspace}" \
|
|
"${container_env[@]}" \
|
|
"${runner_image}" \
|
|
bash -s -- "${build_args[@]}" <<'EOF'
|
|
set -e
|
|
|
|
function create_builder_user() {
|
|
if [[ "${HOST_UID}" == "0" ]] ; then
|
|
HOST_USER=root
|
|
return
|
|
fi
|
|
|
|
if getent group "${HOST_GID}" >/dev/null 2>&1 ; then
|
|
HOST_GROUP=$(getent group "${HOST_GID}" | cut -d: -f1)
|
|
else
|
|
HOST_GROUP="orca-builder"
|
|
if getent group "${HOST_GROUP}" >/dev/null 2>&1 ; then
|
|
HOST_GROUP="orca-builder-${HOST_GID}"
|
|
fi
|
|
groupadd -g "${HOST_GID}" "${HOST_GROUP}"
|
|
fi
|
|
|
|
if getent passwd "${HOST_UID}" >/dev/null 2>&1 ; then
|
|
HOST_USER=$(getent passwd "${HOST_UID}" | cut -d: -f1)
|
|
usermod -g "${HOST_GROUP}" "${HOST_USER}"
|
|
elif id -u "${HOST_USER}" >/dev/null 2>&1 ; then
|
|
usermod -u "${HOST_UID}" -g "${HOST_GROUP}" "${HOST_USER}"
|
|
else
|
|
useradd -m -u "${HOST_UID}" -g "${HOST_GROUP}" -s /bin/bash "${HOST_USER}"
|
|
fi
|
|
|
|
echo "${HOST_USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/orcaslicer-builder
|
|
chmod 0440 /etc/sudoers.d/orcaslicer-builder
|
|
}
|
|
|
|
create_builder_user
|
|
mkdir -p "${GITHUB_WORKSPACE}/deps/build/destdir"
|
|
chown -R "${HOST_UID}:${HOST_GID}" "${GITHUB_WORKSPACE}/deps/build"
|
|
if [[ -d "${GITHUB_WORKSPACE}/build" ]] ; then
|
|
chown -R "${HOST_UID}:${HOST_GID}" "${GITHUB_WORKSPACE}/build"
|
|
fi
|
|
if [[ -d "${GITHUB_WORKSPACE}/build-dbg" ]] ; then
|
|
chown -R "${HOST_UID}:${HOST_GID}" "${GITHUB_WORKSPACE}/build-dbg"
|
|
fi
|
|
if [[ -d "${GITHUB_WORKSPACE}/build-dbginfo" ]] ; then
|
|
chown -R "${HOST_UID}:${HOST_GID}" "${GITHUB_WORKSPACE}/build-dbginfo"
|
|
fi
|
|
|
|
sudo -H -u "${HOST_USER}" env \
|
|
CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL-}" \
|
|
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" \
|
|
ORCA_UPDATER_SIG_KEY="${ORCA_UPDATER_SIG_KEY-}" \
|
|
bash -c '
|
|
set -e
|
|
cd "${GITHUB_WORKSPACE}"
|
|
if [[ "$#" -gt 0 ]] ; then
|
|
./build_linux.sh "$@"
|
|
else
|
|
echo "No build steps were requested after container setup."
|
|
fi
|
|
' bash "$@"
|
|
EOF
|
|
}
|
|
|
|
if [[ -n "${USE_DOCKER}" ]] ; then
|
|
run_in_docker
|
|
popd > /dev/null # ${SCRIPT_PATH}
|
|
exit 0
|
|
fi
|
|
|
|
# cmake 4.x compatibility workaround
|
|
export CMAKE_POLICY_VERSION_MINIMUM=3.5
|
|
|
|
DISTRIBUTION=$(awk -F= '/^ID=/ {print $2}' /etc/os-release | tr -d "'\"")
|
|
DISTRIBUTION_LIKE=$(awk -F= '/^ID_LIKE=/ {print $2}' /etc/os-release | tr -d "'\"")
|
|
# Check for direct distribution match to Ubuntu/Debian
|
|
if [ "${DISTRIBUTION}" == "ubuntu" ] || [ "${DISTRIBUTION}" == "linuxmint" ] ; then
|
|
DISTRIBUTION="debian"
|
|
# Check if distribution is Debian/Ubuntu-like based on ID_LIKE
|
|
elif [[ "${DISTRIBUTION_LIKE}" == *"debian"* ]] || [[ "${DISTRIBUTION_LIKE}" == *"ubuntu"* ]] ; then
|
|
DISTRIBUTION="debian"
|
|
elif [[ "${DISTRIBUTION_LIKE}" == *"arch"* ]] ; then
|
|
DISTRIBUTION="arch"
|
|
elif [[ "${DISTRIBUTION_LIKE}" == *"suse"* ]] ; then
|
|
DISTRIBUTION="suse"
|
|
fi
|
|
|
|
if [ ! -f "./scripts/linux.d/${DISTRIBUTION}" ] ; then
|
|
echo "Your distribution \"${DISTRIBUTION}\" is not supported by system-dependency scripts in ./scripts/linux.d/"
|
|
echo "Please resolve dependencies manually and contribute a script for your distribution to upstream."
|
|
exit 1
|
|
else
|
|
echo "resolving system dependencies for distribution \"${DISTRIBUTION}\" ..."
|
|
# shellcheck source=/dev/null
|
|
source "./scripts/linux.d/${DISTRIBUTION}"
|
|
fi
|
|
|
|
echo "FOUND_GTK3_DEV=${FOUND_GTK3_DEV}"
|
|
if [[ -z "${FOUND_GTK3_DEV}" ]] ; then
|
|
echo "Error, you must install the dependencies before."
|
|
echo "Use option -u with sudo"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Changing date in version..."
|
|
{
|
|
# change date in version
|
|
sed --in-place "s/+UNKNOWN/_$(date '+%F')/" version.inc
|
|
}
|
|
echo "done"
|
|
|
|
|
|
if [[ -z "${SKIP_RAM_CHECK}" ]] ; then
|
|
check_available_memory_and_disk
|
|
fi
|
|
|
|
export CMAKE_C_CXX_COMPILER_CLANG=()
|
|
if [[ -n "${USE_CLANG}" ]] ; then
|
|
export CMAKE_C_CXX_COMPILER_CLANG=(-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++)
|
|
fi
|
|
|
|
# Configure use of ld.lld as the linker when requested
|
|
export CMAKE_LLD_LINKER_ARGS=()
|
|
if [[ -n "${USE_LLD}" ]] ; then
|
|
if command -v ld.lld >/dev/null 2>&1 ; then
|
|
LLD_BIN=$(command -v ld.lld)
|
|
export CMAKE_LLD_LINKER_ARGS=(-DCMAKE_LINKER="${LLD_BIN}" -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld)
|
|
else
|
|
echo "Error: ld.lld not found. Please install the 'lld' package (e.g., sudo apt install lld) or omit -L."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
export CMAKE_CCACHE_ARGS=()
|
|
CMAKE_CCACHE=${CMAKE_CCACHE:-}
|
|
if [ -n "$CMAKE_CCACHE" ]; then
|
|
echo "Checking ${CMAKE_CCACHE} environment variable for compiler cache program..."
|
|
CMAKE_CCACHE=$(command -v "${CMAKE_CCACHE}") || {
|
|
echo "CMAKE_CCACHE environment variable is set to '${CMAKE_CCACHE}' but it was not found in PATH."
|
|
CMAKE_CCACHE=""
|
|
}
|
|
elif command -v sccache >/dev/null 2>&1 ; then
|
|
CMAKE_CCACHE=$(command -v sccache)
|
|
elif command -v ccache >/dev/null 2>&1 ; then
|
|
CMAKE_CCACHE=$(command -v ccache)
|
|
fi
|
|
if [ -n "${CMAKE_CCACHE}" ] ; then
|
|
echo "${CMAKE_CCACHE} found, enabling compiler caching..."
|
|
export CMAKE_CCACHE_ARGS=(-DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_CCACHE}" -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CCACHE}")
|
|
# The same ccache settings as the CI build. Without this sloppiness ccache refuses every
|
|
# compile that uses the precompiled header, which is most of OrcaSlicer, and skips headers
|
|
# a checkout has just written. It is added to the sloppiness already configured, and
|
|
# CCACHE_SLOPPINESS or CCACHE_(NO)DEPEND set in the environment win.
|
|
if [[ "$(basename "${CMAKE_CCACHE}")" == ccache ]] ; then
|
|
if [[ -z "${CCACHE_SLOPPINESS+x}" ]] ; then
|
|
CCACHE_SLOPPINESS=$("${CMAKE_CCACHE}" --get-config sloppiness 2>/dev/null || true)
|
|
export CCACHE_SLOPPINESS="${CCACHE_SLOPPINESS:+${CCACHE_SLOPPINESS},}pch_defines,time_macros,include_file_mtime,include_file_ctime"
|
|
fi
|
|
# Hash the includes the compiler reports instead of preprocessing every miss.
|
|
if [[ -z "${CCACHE_DEPEND+x}${CCACHE_NODEPEND+x}" ]] ; then
|
|
export CCACHE_DEPEND=1
|
|
fi
|
|
fi
|
|
else
|
|
echo "Note: ccache or sccache are not found. Install either of them for faster rebuilds."
|
|
fi
|
|
|
|
if [[ -n "${BUILD_DEPS}" ]] ; then
|
|
echo "Configuring dependencies..."
|
|
read -r -a BUILD_ARGS <<< "${DEPS_EXTRA_BUILD_ARGS}"
|
|
if [[ -n "${CLEAN_BUILD}" ]]
|
|
then
|
|
print_and_run rm -fr deps/$BUILD_DIR
|
|
fi
|
|
mkdir -p deps/$BUILD_DIR
|
|
if [[ $BUILD_CONFIG != Release ]] ; then
|
|
BUILD_ARGS+=(-DCMAKE_BUILD_TYPE="${BUILD_CONFIG}")
|
|
fi
|
|
|
|
print_and_run cmake -S deps -B deps/$BUILD_DIR "${CMAKE_C_CXX_COMPILER_CLANG[@]}" "${CMAKE_LLD_LINKER_ARGS[@]}" "${CMAKE_CCACHE_ARGS[@]}" -G Ninja "${COLORED_OUTPUT}" "${BUILD_ARGS[@]}" "${EXTRA_CMAKE_ARGS[@]}"
|
|
# The top-level build runs one dependency at a time by default, which keeps the console
|
|
# output readable and lets that dependency's own build use all of CMAKE_BUILD_PARALLEL_LEVEL.
|
|
# -J raises the top level instead, and -j still applies in full to every dependency, so the
|
|
# worst case is -J times -j compile jobs at once. Ninja has no job server to share a pool
|
|
# across the nested builds, so that ceiling is not enforced anywhere: pick -J to suit the RAM.
|
|
DEPS_JOBS=1
|
|
if [[ -n "${DEPS_PARALLEL}" ]] ; then
|
|
DEPS_JOBS=${DEPS_PARALLEL}
|
|
SAVED_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL-}
|
|
export CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL:-$(nproc)}
|
|
echo "Building up to ${DEPS_JOBS} dependencies at a time, ${CMAKE_BUILD_PARALLEL_LEVEL} jobs each: up to $(( DEPS_JOBS * CMAKE_BUILD_PARALLEL_LEVEL )) compile jobs at once."
|
|
fi
|
|
|
|
print_and_run cmake --build deps/$BUILD_DIR -j"${DEPS_JOBS}"
|
|
|
|
if [[ -n "${DEPS_PARALLEL}" ]] ; then
|
|
# Give the whole -j back to the OrcaSlicer build below.
|
|
if [[ -n "${SAVED_PARALLEL_LEVEL}" ]] ; then
|
|
export CMAKE_BUILD_PARALLEL_LEVEL=${SAVED_PARALLEL_LEVEL}
|
|
else
|
|
unset CMAKE_BUILD_PARALLEL_LEVEL
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [[ -n "${BUILD_ORCA}" ]] || [[ -n "${BUILD_TESTS}" ]] ; then
|
|
echo "Configuring OrcaSlicer..."
|
|
if [[ -n "${CLEAN_BUILD}" ]] ; then
|
|
print_and_run rm -fr $BUILD_DIR
|
|
fi
|
|
read -r -a BUILD_ARGS <<< "${ORCA_EXTRA_BUILD_ARGS}"
|
|
if [[ $BUILD_CONFIG != Release ]] ; then
|
|
BUILD_ARGS+=(-DCMAKE_BUILD_TYPE="${BUILD_CONFIG}")
|
|
fi
|
|
if [[ -n "${BUILD_TESTS}" ]] ; then
|
|
BUILD_ARGS+=(-DBUILD_TESTS=ON)
|
|
fi
|
|
if [[ -n "${ORCA_UPDATER_SIG_KEY}" ]] ; then
|
|
BUILD_ARGS+=(-DORCA_UPDATER_SIG_KEY="${ORCA_UPDATER_SIG_KEY}")
|
|
fi
|
|
|
|
print_and_run cmake -S . -B $BUILD_DIR "${CMAKE_C_CXX_COMPILER_CLANG[@]}" "${CMAKE_LLD_LINKER_ARGS[@]}" "${CMAKE_CCACHE_ARGS[@]}" -G "Ninja Multi-Config" \
|
|
-DSLIC3R_PCH=${SLIC3R_PRECOMPILED_HEADERS} \
|
|
-DORCA_TOOLS=ON \
|
|
"${COLORED_OUTPUT}" \
|
|
"${BUILD_ARGS[@]}" \
|
|
"${EXTRA_CMAKE_ARGS[@]}"
|
|
echo "done"
|
|
if [[ -n "${BUILD_ORCA}" ]]; then
|
|
echo "Building OrcaSlicer ..."
|
|
print_and_run cmake --build $BUILD_DIR --config "${BUILD_CONFIG}" --target OrcaSlicer
|
|
echo "Building OrcaSlicer_profile_validator .."
|
|
print_and_run cmake --build $BUILD_DIR --config "${BUILD_CONFIG}" --target OrcaSlicer_profile_validator
|
|
echo "Building generate_system_cache ..."
|
|
print_and_run cmake --build $BUILD_DIR --config "${BUILD_CONFIG}" --target generate_system_cache
|
|
./scripts/run_gettext.sh
|
|
fi
|
|
if [[ -n "${BUILD_TESTS}" ]] ; then
|
|
echo "Building tests ..."
|
|
print_and_run cmake --build ${BUILD_DIR} --config "${BUILD_CONFIG}" --target tests/all
|
|
fi
|
|
echo "done"
|
|
fi
|
|
|
|
if [[ -n "${BUILD_IMAGE}" || -n "${BUILD_ORCA}" ]] ; then
|
|
pushd $BUILD_DIR > /dev/null
|
|
build_linux_image="./src/build_linux_image.sh"
|
|
if [[ -e ${build_linux_image} ]] ; then
|
|
extra_script_args=""
|
|
if [[ -n "${BUILD_IMAGE}" ]] ; then
|
|
extra_script_args="-i"
|
|
fi
|
|
print_and_run ${build_linux_image} ${extra_script_args} -R "${BUILD_CONFIG}"
|
|
|
|
echo "done"
|
|
fi
|
|
popd > /dev/null # build
|
|
fi
|
|
|
|
elapsed=$SECONDS
|
|
printf "\nBuild completed in %dh %dm %ds\n" $((elapsed/3600)) $((elapsed%3600/60)) $((elapsed%60))
|
|
|
|
popd > /dev/null # ${SCRIPT_PATH}
|