Skip to content

Commit

Permalink
ENH: Refactor BuildLinux.sh to support fedora
Browse files Browse the repository at this point in the history
JIRA: STUDIO-4377 STUDIO-7461
GITHUB: #2429
Change-Id: Ib4f14a88d04e789a58b1f83425a1708ce4934b0e
(cherry picked from commit a7c9e9e288694fe72665e45977f0676d827c767f)
  • Loading branch information
MackBambu authored and lanewei120 committed Jul 17, 2024
1 parent 61fbef4 commit b6715f3
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 191 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/build_bambu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,6 @@ jobs:
# max_releases: 1

# Ubuntu
- name: Install dependencies
if: inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04'
run: |
sudo apt-get update
sudo apt-get install -y autoconf build-essential cmake curl wget file git \
libgl1-mesa-dev libgtk-3-dev libxkbcommon-dev libunwind-dev libfuse2
- name: Install dependencies from BuildLinux.sh
if: inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04'
shell: bash
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/build_deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ jobs:
if: inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04'
working-directory: ${{ github.workspace }}
run: |
sudo apt-get update
sudo apt-get install libgl1-mesa-dev libgtk-3-dev libxkbcommon-dev libunwind-dev libfuse2 -y
mkdir -p ${{ github.workspace }}/deps/build
mkdir -p ${{ github.workspace }}/deps/build/destdir
sudo ./BuildLinux.sh -ur
sudo chown $USER -R ./
./BuildLinux.sh -dr
Expand Down
270 changes: 90 additions & 180 deletions BuildLinux.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/bash
set -e # exit on first error

export ROOT=`pwd`
export NCORES=`nproc --all`
export CMAKE_BUILD_PARALLEL_LEVEL=${NCORES}
FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
export ROOT=$(dirname $(readlink -f ${0}))

set -e # exit on first error

function check_available_memory_and_disk() {
FREE_MEM_GB=$(free -g -t | grep 'Mem' | rev | cut -d" " -f1 | rev)
Expand All @@ -27,246 +24,159 @@ function check_available_memory_and_disk() {
fi
}

function usage() {
echo "Usage: ./BuildLinux.sh [-1][-b][-c][-d][-i][-r][-s][-u]"
echo " -1: limit builds to 1 core (where possible)"
echo " -b: build in debug mode"
echo " -c: force a clean build"
echo " -d: build deps (optional)"
echo " -h: this help output"
echo " -i: Generate appimage (optional)"
echo " -r: skip ram and disk checks (low ram compiling)"
echo " -s: build bambu-studio (optional)"
echo " -u: update and build dependencies (optional and need sudo)"
echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo " and then './BuildLinux.sh -dsi'"
}

unset name
while getopts ":dsiuhgbr" opt; do
while getopts ":1bcdghirsu" opt; do
case ${opt} in
u )
UPDATE_LIB="1"
1 )
export CMAKE_BUILD_PARALLEL_LEVEL=1
;;
i )
BUILD_IMAGE="1"
b )
BUILD_DEBUG="1"
;;
c )
CLEAN_BUILD=1
;;
d )
BUILD_DEPS="1"
;;
s )
BUILD_BAMBU_STUDIO="1"
;;
b )
BUILD_DEBUG="1"
h ) usage
exit 0
;;
g )
FOUND_GTK3=""
i )
BUILD_IMAGE="1"
;;
r )
SKIP_RAM_CHECK="1"
SKIP_RAM_CHECK="1"
;;
h ) echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
echo " -i: Generate appimage (optional)"
echo " -g: force gtk2 build"
echo " -b: build in debug mode"
echo " -d: build deps (optional)"
echo " -s: build bambu-studio (optional)"
echo " -u: only update clock & dependency packets (optional and need sudo)"
echo " -r: skip free ram check (low ram compiling)"
echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo " and then './BuildLinux.sh -dsi'"
exit 0
s )
BUILD_BAMBU_STUDIO="1"
;;
u )
UPDATE_LIB="1"
;;
esac
done

if [ $OPTIND -eq 1 ]
if [ ${OPTIND} -eq 1 ]
then
echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
echo " -i: Generate appimage (optional)"
echo " -g: force gtk2 build"
echo " -b: build in debug mode"
echo " -d: build deps (optional)"
echo " -s: build bambu-studio (optional)"
echo " -u: only update clock & dependency packets (optional and need sudo)"
echo " -r: skip free ram check (low ram compiling)"
echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
echo " and then './BuildLinux.sh -dsi'"
usage
exit 0
fi

# mkdir build
if [ ! -d "build" ]
DISTRIBUTION=$(awk -F= '/^ID=/ {print $2}' /etc/os-release)
VERSION=$(awk -F= '/^VERSION_ID=/ {print $2}' /etc/os-release)
# treat ubuntu as debian
if [ "${DISTRIBUTION}" == "ubuntu" ]
then
mkdir build
DISTRIBUTION="debian"
fi

#FIXME: require root for -u option
if [[ -n "$UPDATE_LIB" ]]
if [ ! -f ./linux.d/${DISTRIBUTION} ]
then
echo -n -e "Updating linux ...\n"
# hwclock -s # DeftDawg: Why does SuperSlicer want to do this?
apt update
if [[ -z "$FOUND_GTK3" ]]
then
echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
apt install -y libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git
else
echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
apt install -y libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git
fi
# for ubuntu:
ubu_version="$(cat /etc/issue)"
if [[ $ubu_version == "Ubuntu 22.04"* ]]
then
apt install -y curl libssl-dev libcurl4-openssl-dev m4 libwebkit2gtk-4.0-dev
elif [[ $ubu_version == "Ubuntu 24.04"* ]]
then
# NEW_SOURCE="deb http://gb.archive.ubuntu.com/ubuntu jammy main"
# if grep -qF -- "$NEW_SOURCE" /etc/apt/sources.list; then
# echo "source exist: $NEW_SOURCE"
# else
# echo "$NEW_SOURCE" | sudo tee -a /etc/apt/sources.list > /dev/null
# fi
# apt update
apt install -y libwebkit2gtk-4.1-dev
else
apt install -y libwebkit2gtk-4.0-dev
fi
if [[ -n "$BUILD_DEBUG" ]]
then
echo -e "\nInstalling: libssl-dev libcurl4-openssl-dev\n"
apt install -y libssl-dev libcurl4-openssl-dev
fi

# Addtional Dev packages for BambuStudio
export REQUIRED_DEV_PACKAGES="libgstreamerd-3-dev libsecret-1-dev libosmesa6-dev libssl-dev libcurl4-openssl-dev eglexternalplatform-dev libudev-dev libdbus-1-dev extra-cmake-modules"
# libwebkit2gtk-4.1-dev ??
export DEV_PACKAGES_COUNT=$(echo ${REQUIRED_DEV_PACKAGES} | wc -w)
if [ $(dpkg --get-selections | grep -E "$(echo ${REQUIRED_DEV_PACKAGES} | tr ' ' '|')" | wc -l) -lt ${DEV_PACKAGES_COUNT} ]; then
sudo apt install -y ${REQUIRED_DEV_PACKAGES} git cmake wget file
fi
echo -e "done\n"
exit 0
echo "Your distribution does not appear to be currently supported by these build scripts"
exit 1
fi
source ./linux.d/${DISTRIBUTION}

FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev || echo '')
FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev || echo '')
echo "FOUND_GTK2=$FOUND_GTK2)"
if [[ -z "$FOUND_GTK2_DEV" ]]
then
if [[ -z "$FOUND_GTK3_DEV" ]]
echo "FOUND_GTK3=${FOUND_GTK3}"
if [[ -z "${FOUND_GTK3_DEV}" ]]
then
echo "Error, you must install the dependencies before."
echo "Use option -u with sudo"
exit 0
fi
exit 1
fi

echo "[1/9] Updating submodules..."
{
# update submodule profiles
pushd resources/profiles
git submodule update --init
popd
}

echo "[2/9] Changing date in version..."
echo "Changing date in version..."
{
# change date in version
sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
}
echo "done"

# mkdir in deps
if [ ! -d "deps/build" ]
then
mkdir deps/build
fi

if ! [[ -n "$SKIP_RAM_CHECK" ]]
if ! [[ -n "${SKIP_RAM_CHECK}" ]]
then
check_available_memory_and_disk
check_available_memory_and_disk
fi

if [[ -n "$BUILD_DEPS" ]]
if [[ -n "${BUILD_DEPS}" ]]
then
echo "[3/9] Configuring dependencies..."
BUILD_ARGS=""
if [[ -n "$FOUND_GTK3_DEV" ]]
echo "Configuring dependencies..."
BUILD_ARGS="-DDEP_WX_GTK3=ON"
if [[ -n "${CLEAN_BUILD}" ]]
then
rm -fr deps/build
fi
if [ ! -d "deps/build" ]
then
BUILD_ARGS="-DDEP_WX_GTK3=ON"
mkdir deps/build
fi
if [[ -n "$BUILD_DEBUG" ]]
if [[ -n "${BUILD_DEBUG}" ]]
then
# have to build deps with debug & release or the cmake won't find evrything it needs
# have to build deps with debug & release or the cmake won't find everything it needs
mkdir deps/build/release
pushd deps/build/release
cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
make -j$NCORES
popd
cmake -S deps -B deps/build/release -G Ninja -DDESTDIR="../destdir" ${BUILD_ARGS}
cmake --build deps/build/release
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
fi

# cmake deps
pushd deps/build
cmake .. $BUILD_ARGS
echo "done"

# make deps
echo "[4/9] Building dependencies..."
make -j$NCORES
echo "done"

# rename wxscintilla # TODO: DeftDawg: Does BambuStudio need this?
# echo "[5/9] Renaming wxscintilla library..."
# pushd destdir/usr/local/lib
# if [[ -z "$FOUND_GTK3_DEV" ]]
# then
# cp libwxscintilla-3.1.a libwx_gtk2u_scintilla-3.1.a
# else
# cp libwxscintilla-3.1.a libwx_gtk3u_scintilla-3.1.a
# fi
# popd
# echo "done"

# FIXME: only clean deps if compiling succeeds; otherwise reruns waste tonnes of time!
# clean deps
# echo "[6/9] Cleaning dependencies..."
# rm -rf dep_*
popd
echo "done"
echo "cmake -S deps -B deps/build -G Ninja ${BUILD_ARGS}"
cmake -S deps -B deps/build -G Ninja ${BUILD_ARGS}
cmake --build deps/build
fi

if [[ -n "$BUILD_BAMBU_STUDIO" ]]
if [[ -n "${BUILD_BAMBU_STUDIO}" ]]
then
echo "[7/9] Configuring Slic3r..."
echo "Configuring BambuStudio..."
if [[ -n "${CLEAN_BUILD}" ]]
then
rm -fr build
fi
BUILD_ARGS=""
if [[ -n "$FOUND_GTK3_DEV" ]]
if [[ -n "${FOUND_GTK3_DEV}" ]]
then
BUILD_ARGS="-DSLIC3R_GTK=3"
fi
if [[ -n "$BUILD_DEBUG" ]]
if [[ -n "${BUILD_DEBUG}" ]]
then
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug -DBBL_INTERNAL_TESTING=1"
else
BUILD_ARGS="${BUILD_ARGS} -DBBL_RELEASE_TO_PUBLIC=1 -DBBL_INTERNAL_TESTING=0"
fi

# cmake
pushd build
cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
echo "done"

# make Slic3r
echo "[8/9] Building Slic3r..."
make -j$NCORES BambuStudio # Slic3r

# make .mo
# make gettext_po_to_mo # FIXME: DeftDawg: complains about msgfmt not existing even in SuperSlicer, did this ever work?

popd
echo -e "cmake -S . -B build -G Ninja -DCMAKE_PREFIX_PATH="${PWD}/deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}"
cmake -S . -B build -G Ninja \
-DCMAKE_PREFIX_PATH="${PWD}/deps/build/destdir/usr/local" \
-DSLIC3R_STATIC=1 \
${BUILD_ARGS}
echo "done"
echo "Building BambuStudio ..."
cmake --build build --target BambuStudio
echo "done"
fi

if [[ -e $ROOT/build/src/BuildLinuxImage.sh ]]; then
if [[ -e ${ROOT}/build/src/BuildLinuxImage.sh ]]; then
# Give proper permissions to script
chmod 755 $ROOT/build/src/BuildLinuxImage.sh
chmod 755 ${ROOT}/build/src/BuildLinuxImage.sh

echo "[9/9] Generating Linux app..."
pushd build
if [[ -n "$BUILD_IMAGE" ]]
if [[ -n "${BUILD_IMAGE}" ]]
then
$ROOT/build/src/BuildLinuxImage.sh -i
else
$ROOT/build/src/BuildLinuxImage.sh
${ROOT}/build/src/BuildLinuxImage.sh -i
fi
popd
echo "done"
fi
fi
Loading

0 comments on commit b6715f3

Please sign in to comment.