Skip to content

Commit

Permalink
[TASK] Build Linux (Ubuntu 22.04)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Mar 6, 2024
1 parent c8314e4 commit 9e8a60f
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
- 'version.inc'
- 'resources/**'
- ".github/workflows/build_*.yml"
- "build_release_linux.sh"
- "build_release_macos.sh"
- "build_release_vs2022.bat"
- "build_win.bat"

pull_request:
Expand Down Expand Up @@ -46,6 +46,7 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
- os: macos-14
arch: arm64
- os: macos-12
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/build_deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: setup dev on Windows
if: inputs.os == 'windows-latest'
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v2

- name: Get the date on Ubuntu and macOS
if: inputs.os != 'windows-latest'
Expand Down Expand Up @@ -80,6 +80,20 @@ jobs:
./build_release_macos.sh -dp -a ${{ inputs.arch }} -t 10.15
brew install zstd
- name: Build on Ubuntu
if: inputs.os == 'ubuntu-22.04'
working-directory: ${{ github.workspace }}
run: |
sudo apt-get update
sudo apt-get install -y cmake git build-essential autoconf cmake libglu1-mesa-dev libgtk-3-dev libdbus-1-dev libcurl4-openssl-dev libsecret-1-dev libssl-dev
mkdir -p ${{ github.workspace }}/deps/build
mkdir -p ${{ github.workspace }}/deps/build/destdir
sudo ./build_release_linux.sh -ur
sudo chown $USER -R ./
./build_release_linux.sh -dr
cd deps/build
tar -czvf PrusaSlicer_dep_ubuntu_$(date +"%Y%m%d").tar.gz destdir
# Upload Artifacts
- name: Upload Mac ${{ inputs.arch }} artifacts
if: inputs.os == 'macos-12' || inputs.os == 'macos-13' || inputs.os == 'macos-14'
Expand All @@ -95,6 +109,13 @@ jobs:
name: PrusaSlicer_dep_win64_${{ env.date }}
path: ${{ github.workspace }}/deps/build/PrusaSlicer_dep*.zip

- name: Upload Ubuntu artifacts
if: inputs.os == 'ubuntu-22.04'
uses: actions/upload-artifact@v4
with:
name: PrusaSlicer_dep_ubuntu_${{ env.date }}
path: ${{ github.workspace }}/deps/build/PrusaSlicer_dep_ubuntu_*.tar.gz

build_prusa:
name: Build PrusaSlicer
needs: [build_deps]
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/build_prusa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,43 @@ jobs:
with:
name: PrusaSlicer-${{ env.ver }}+win64-${{ env.date }}
path: ${{ github.workspace }}\build\PrusaSlicer-${{ env.ver }}+win64-${{ env.date }}.zip

# Ubuntu
- name: Install dependencies
if: inputs.os == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y cmake git build-essential autoconf cmake libglu1-mesa-dev libgtk-3-dev libdbus-1-dev libcurl4-openssl-dev libsecret-1-dev libssl-dev
- name: Install dependencies from build_linux.sh
if: inputs.os == 'ubuntu-22.04'
shell: bash
run: sudo ./build_release_linux.sh -ur

- name: Fix permissions
if: inputs.os == 'ubuntu-22.04'
shell: bash
run: sudo chown $USER -R ./

- name: Build slicer
if: inputs.os == 'ubuntu-22.04'
shell: bash
run: |
./build_release_linux.sh -isr
mv -n ./build/PrusaSlicer-${{ env.ver_pure }}+Linux.tar ./build/PrusaSlicer-${{ env.ver }}+Linux-${{ env.date }}.tar
mv -n ./build/PrusaSlicer-${{ env.ver_pure }}+Linux.AppImage ./build/PrusaSlicer-${{ env.ver }}+Linux-${{ env.date }}.AppImage
chmod +x ./build/PrusaSlicer-${{ env.ver }}+Linux-${{ env.date }}.AppImage
- name: Upload artifacts Ubuntu (Archive)
if: inputs.os == 'ubuntu-22.04'
uses: actions/upload-artifact@v4
with:
name: "PrusaSlicer-${{ env.ver }}+Linux-${{ env.date }} (Archive)"
path: './build/PrusaSlicer-${{ env.ver }}+Linux-${{ env.date }}.tar'

- name: Upload artifacts Ubuntu (AppImage)
if: inputs.os == 'ubuntu-22.04'
uses: actions/upload-artifact@v4
with:
name: "PrusaSlicer-${{ env.ver }}+Linux-${{ env.date }} (AppImage)"
path: './build/PrusaSlicer-${{ env.ver }}+Linux-${{ env.date }}.AppImage'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ xs/assertlib*
.vs/*
/src/TAGS
/.vscode/
build-default/*
build-linux/*
build_x86_64/*
build_arm64/*
Expand Down
19 changes: 12 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ endif()
function(slic3r_remap_configs targets from_Cfg to_Cfg)
if(MSVC)
string(TOUPPER ${from_Cfg} from_CFG)

foreach(tgt ${targets})
if(TARGET ${tgt})
set_target_properties(${tgt} PROPERTIES MAP_IMPORTED_CONFIG_${from_CFG} ${to_Cfg})
Expand Down Expand Up @@ -581,7 +581,7 @@ function(prusaslicer_copy_dlls target)
elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
set(_bits 32)
endif ()

get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
get_target_property(_alt_out_dir ${target} RUNTIME_OUTPUT_DIRECTORY)

Expand All @@ -592,14 +592,14 @@ function(prusaslicer_copy_dlls target)
else ()
set (_out_dir "$<TARGET_PROPERTY:${target},BINARY_DIR>")
endif ()
# This has to be a separate target due to the windows command line lenght limits
add_custom_command(TARGET ${target} POST_BUILD

# This has to be a separate target due to the windows command line lenght limits
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${TOP_LEVEL_PROJECT_DIR}/deps/+GMP/gmp/lib/win${_bits}/libgmp-10.dll ${_out_dir}
COMMENT "Copy gmp runtime to build tree"
VERBATIM)
add_custom_command(TARGET ${target} POST_BUILD

add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${TOP_LEVEL_PROJECT_DIR}/deps/+MPFR/mpfr/lib/win${_bits}/libmpfr-4.dll ${_out_dir}
COMMENT "Copy mpfr runtime to build tree"
VERBATIM)
Expand All @@ -621,6 +621,11 @@ if(SLIC3R_BUILD_TESTS)
add_subdirectory(tests)
endif()

if (NOT WIN32 AND NOT APPLE)
set(SLIC3R_APP_CMD "prusa-slicer")
set(SLIC3R_VIEWER_CMD "prusa-gcodeviewer")
configure_file(${LIBDIR}/platform/unix/build_appimage.sh.in ${CMAKE_CURRENT_BINARY_DIR}/build_appimage.sh @ONLY)
endif()

# Resources install target, configure fhs.hpp on UNIX
if (WIN32)
Expand Down
232 changes: 232 additions & 0 deletions build_release_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
#!/bin/bash

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)

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)
MIN_MEM_GB=10

FREE_DISK_KB=$(df -k . | tail -1 | awk '{print $4}')
MIN_DISK_KB=$((10 * 1024 * 1024))

if [ ${FREE_MEM_GB} -le ${MIN_MEM_GB} ]; then
echo -e "\nERROR: PrusaSlicer Builder requires at least ${MIN_MEM_GB}G of 'available' mem (systen has only ${FREE_MEM_GB}G available)"
echo && free -h && echo
exit 2
fi

if [[ ${FREE_DISK_KB} -le ${MIN_DISK_KB} ]]; then
echo -e "\nERROR: PrusaSlicer Builder requires at least $(echo $MIN_DISK_KB |awk '{ printf "%.1fG\n", $1/1024/1024; }') (systen has only $(echo ${FREE_DISK_KB} | awk '{ printf "%.1fG\n", $1/1024/1024; }') disk free)"
echo && df -h . && echo
exit 1
fi
}

function usage() {
echo "Usage: ./build_release_linux.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 prusa-slicer (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 ./build_release_linux.sh -u'"
echo " and then './build_release_linux.sh -dsi'"
}

unset name
while getopts ":dsiuhgbr" opt; do
case ${opt} in
u )
UPDATE_LIB="1"
;;
i )
BUILD_IMAGE="1"
;;
d )
BUILD_DEPS="1"
;;
s )
BUILD_SLIC3R="1"
;;
b )
BUILD_DEBUG="1"
;;
g )
FOUND_GTK3=""
;;
r )
SKIP_RAM_CHECK="1"
;;
h ) usage
exit 0
;;
esac
done

if [ $OPTIND -eq 1 ]
then
usage
exit 0
fi

# Addtional Dev packages for OrcaSlicer
export REQUIRED_DEV_PACKAGES="libmspack-dev libsecret-1-dev libwebkit2gtk-4.0-dev libosmesa6-dev libssl-dev libcurl4-openssl-dev eglexternalplatform-dev libudev-dev libdbus-1-dev extra-cmake-modules texinfo"
# 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 gettext
fi

#FIXME: require root for -u option
if [[ -n "$UPDATE_LIB" ]]
then
echo -n -e "Updating linux ...\n"
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 "\nFound 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 22+ and 23+:
ubu_major_version="$(grep VERSION_ID /etc/os-release | cut -d "=" -f 2 | cut -d "." -f 1 | tr -d /\"/)"
if [ $ubu_major_version == "22" ] || [ $ubu_major_version == "23" ]
then
apt install -y curl libfuse-dev libssl-dev libcurl4-openssl-dev m4
fi
if [[ -n "$BUILD_DEBUG" ]]
then
echo -e "\nInstalling: libssl-dev libcurl4-openssl-dev\n"
apt install -y libssl-dev libcurl4-openssl-dev
fi
echo -e "done\n"
exit 0
fi

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" ]]
then
echo "Error, you must install the dependencies before."
echo "Use option -u with sudo"
exit 0
fi
fi

echo "[1/9] Preparing build envirnoment for dependencies..."
{
# mkdir in deps
if [ ! -d "deps/build" ]
then
mkdir -p deps/build
fi
echo "done"
}

echo "[2/9] Checking system requirements..."
{
if ! [[ -n "$SKIP_RAM_CHECK" ]]
then
check_available_memory_and_disk
fi
echo "done"
}

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

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

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



if [[ -n "$BUILD_SLIC3R" ]]
then
# Create main "build" directory
echo "[5/9] Creating main build directory..."
if [ ! -d "build" ]
then
mkdir build
fi

echo "[6/9] Configuring Slic3r..."
BUILD_ARGS="-DSLIC3R_PCH=OFF"
if [[ -n "$FOUND_GTK3_DEV" ]]
then
BUILD_ARGS="-DSLIC3R_GTK=3"
fi
if [[ -n "$BUILD_DEBUG" ]]
then
BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
fi

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

# make Slic3r
echo "[7/9] Building Slic3r..."
make -j$NCORES
popd

echo "done"
fi

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

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

0 comments on commit 9e8a60f

Please sign in to comment.