diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml new file mode 100644 index 00000000000..58b4f3fa7ea --- /dev/null +++ b/.github/workflows/build_all.yml @@ -0,0 +1,56 @@ +name: Build all + +on: + push: + branches: + - boss + - release/* + paths: + - 'deps/**' + - 'src/**' + - '**/CMakeLists.txt' + - 'version.inc' + - 'resources/**' + - ".github/workflows/build_*.yml" + + pull_request: + branches: + - boss + - release/* + paths: + - 'deps/**' + - 'src/**' + - '**/CMakeLists.txt' + - 'version.inc' + - ".github/workflows/build_*.yml" + + workflow_dispatch: # allows for manual dispatch + inputs: + build-deps-only: + description: 'Only build dependencies (bypasses caching)' + type: boolean + default: false + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + + +jobs: + build_all: + name: Build All + strategy: + fail-fast: false + matrix: + include: + # - os: windows-latest + # - os: macos-12 + # arch: x86_64 + - os: macos-12 + arch: arm64 + uses: ./.github/workflows/build_check_cache.yml + with: + os: ${{ matrix.os }} + arch: ${{ matrix.arch }} + build-deps-only: ${{ inputs.build-deps-only || false }} + secrets: inherit diff --git a/.github/workflows/build_check_cache.yml b/.github/workflows/build_check_cache.yml new file mode 100644 index 00000000000..5b91a0d6c76 --- /dev/null +++ b/.github/workflows/build_check_cache.yml @@ -0,0 +1,58 @@ +name: Check Cache + +on: + workflow_call: + inputs: + os: + required: true + type: string + arch: + required: false + type: string + build-deps-only: + required: false + type: boolean + +jobs: + check_cache: # determines if there is a cache and outputs variables used in caching process + name: Check Cache + runs-on: ${{ inputs.os }} + outputs: + cache-key: ${{ steps.set_outputs.outputs.cache-key }} + cache-path: ${{ steps.set_outputs.outputs.cache-path }} + valid-cache: ${{ steps.cache_deps.outputs.cache-hit }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: set outputs + id: set_outputs + env: + underscore-arch: ${{ inputs.os == 'macos-12' && '_' || ''}}${{ inputs.os == 'macos-12' && inputs.arch || '' }} # if is macos, make a string that does "_{arch}", else output nothing + dash-arch: ${{ inputs.os == 'macos-12' && '-' || ''}}${{ inputs.os == 'macos-12' && inputs.arch || '' }} # if is macos, make a string that does "-{arch}", else output nothing + dep-folder-name: ${{ (inputs.os == 'windows-latest' || inputs.os == 'macos-12') && 'PrusaSlicer_dep' || 'destdir' }} + output-cmd: ${{ inputs.os == 'windows-latest' && '$env:GITHUB_OUTPUT' || '"$GITHUB_OUTPUT"'}} + run: | + echo cache-key=${{ runner.os }}${{ env.dash-arch }}-cache-Prusaslicer_deps-build-${{ hashFiles('deps/**') }} >> ${{ env.output-cmd }} + echo cache-path=${{ github.workspace }}/deps/build${{ env.underscore-arch }}/${{ env.dep-folder-name }}${{ env.underscore-arch }} >> ${{ env.output-cmd }} + + - name: load cache + id: cache_deps + uses: actions/cache@v3 + with: + path: ${{ steps.set_outputs.outputs.cache-path }} + key: ${{ steps.set_outputs.outputs.cache-key }} + lookup-only: true + + build_deps: # call next step + name: Build Deps + needs: [check_cache] + uses: ./.github/workflows/build_deps.yml + with: + cache-key: ${{ needs.check_cache.outputs.cache-key }} + cache-path: ${{ needs.check_cache.outputs.cache-path }} + valid-cache: ${{ needs.check_cache.outputs.valid-cache == 'true' }} + os: ${{ inputs.os }} + arch: ${{ inputs.arch }} + build-deps-only: ${{ inputs.build-deps-only }} + secrets: inherit diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml new file mode 100644 index 00000000000..b6c3cc11c7a --- /dev/null +++ b/.github/workflows/build_deps.yml @@ -0,0 +1,106 @@ +on: + workflow_call: + inputs: + cache-key: + required: true + type: string + cache-path: + required: true + type: string + valid-cache: + required: true + type: boolean + os: + required: true + type: string + arch: + required: false + type: string + build-deps-only: + required: false + type: boolean + +jobs: + build_deps: + name: Build Deps + if: inputs.build-deps-only || inputs.valid-cache != true + runs-on: ${{ inputs.os }} + env: + date: + steps: + + # Setup the environment + - name: Checkout + uses: actions/checkout@v3 + + - name: load cached deps + uses: actions/cache@v3 + with: + path: ${{ inputs.cache-path }} + key: ${{ inputs.cache-key }} + + - name: setup dev on Windows + if: inputs.os == 'windows-latest' + uses: microsoft/setup-msbuild@v1.1 + + - name: Get the date on Ubuntu and macOS + if: inputs.os != 'windows-latest' + run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV + shell: bash + + - name: Get the date on Windows + if: inputs.os == 'windows-latest' + run: echo "date=$(Get-Date -Format 'yyyyMMdd')" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + shell: pwsh + + + # Build Dependencies + - name: Build on Windows + if: inputs.os == 'windows-latest' + working-directory: ${{ github.workspace }} + run: | + choco install strawberryperl + mkdir ${{ github.workspace }}/deps/build + mkdir ${{ github.workspace }}/deps/build/PrusaSlicer_dep + .\build_release_vs2022.bat deps + .\build_release_vs2022.bat pack + cd ${{ github.workspace }}/deps/build + + - name: Build on Mac ${{ inputs.arch }} + if: inputs.os == 'macos-12' + working-directory: ${{ github.workspace }} + run: | + brew install cmake git gettext automake texinfo + brew list + mkdir -p ${{ github.workspace }}/deps/build_${{ inputs.arch }} + mkdir -p ${{ github.workspace }}/deps/build_${{ inputs.arch }}/PrusaSlicer_dep_${{ inputs.arch }} + brew uninstall --ignore-dependencies zstd + ./build_release_macos.sh -dp -a ${{ inputs.arch }} -t 10.15 + brew install zstd + + # Upload Artifacts + - name: Upload Mac ${{ inputs.arch }} artifacts + if: inputs.os == 'macos-12' + uses: actions/upload-artifact@v3 + with: + name: PrusaSlicer_dep_mac_${{ inputs.arch }}_${{ env.date }} + path: ${{ github.workspace }}/deps/build_${{ inputs.arch }}/PrusaSlicer_dep*.tar.gz + + - name: Upload Windows artifacts + if: inputs.os == 'windows-latest' + uses: actions/upload-artifact@v3 + with: + name: PrusaSlicer_dep_win64_${{ env.date }} + path: ${{ github.workspace }}/deps/build/PrusaSlicer_dep*.zip + + build_prusa: + name: Build PrusaSlicer + needs: [build_deps] + if: ${{ !cancelled() && !inputs.build-deps-only && (inputs.valid-cache == true && needs.build_deps.result == 'skipped') || (inputs.valid-cache != true && success()) }} + uses: ./.github/workflows/build_prusa.yml + with: + cache-key: ${{ inputs.cache-key }} + cache-path: ${{ inputs.cache-path }} + os: ${{ inputs.os }} + arch: ${{ inputs.arch }} + secrets: inherit diff --git a/.github/workflows/build_prusa.yml b/.github/workflows/build_prusa.yml new file mode 100644 index 00000000000..0ed813656d2 --- /dev/null +++ b/.github/workflows/build_prusa.yml @@ -0,0 +1,146 @@ +on: + workflow_call: + inputs: + cache-key: + required: true + type: string + cache-path: + required: true + type: string + os: + required: true + type: string + arch: + required: false + type: string + +jobs: + build_prusa: + name: Build PrusaSlicer + runs-on: ${{ inputs.os }} + env: + date: + ver: + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: load cached deps + uses: actions/cache@v3 + with: + path: ${{ inputs.cache-path }} + key: ${{ inputs.cache-key }} + fail-on-cache-miss: true + + - name: Get the version and date on Ubuntu and macOS + if: inputs.os != 'windows-latest' + run: | + if [ "${{ github.ref }}" == "refs/heads/boss" ]; then + ver="nightly$(date +'%y%m%d')" + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then + ver="PR${{ github.event.number }}" + else + ver=$(grep 'set(SoftFever_VERSION' version.inc | cut -d '"' -f2) + ver=V$ver + fi + echo "ver=$ver" >> $GITHUB_ENV + echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV + shell: bash + + - name: Get the version and date on Windows + if: inputs.os == 'windows-latest' + run: | + $date = Get-Date -Format 'yyyyMMdd' + $ref = "${{ github.ref }}" + $eventName = "${{ github.event_name }}" + $prNumber = "${{ github.event.number }}" + + if ($ref -eq 'refs/heads/boss') { + $ver = "nightly" + $date.Substring(2) + } elseif ($eventName -eq 'pull_request') { + $ver = "PR" + $prNumber + } else { + $versionContent = Get-Content version.inc -Raw + if ($versionContent -match 'set\(SoftFever_VERSION "(.*?)"\)') { + $ver = $matches[1] + } + $ver = "V$ver" + } + + echo "ver=$ver" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "date=$date" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + echo "date: ${{ env.date }} version: ${{ env.ver }}" + shell: pwsh + +# Mac + - name: Install tools mac + if: inputs.os == 'macos-12' + run: | + brew install cmake git gettext tree + brew list + mkdir -p ${{ github.workspace }}/deps/build_${{inputs.arch}} + mkdir -p ${{ github.workspace }}/deps/build_${{inputs.arch}}/PrusaSlicer_dep_${{inputs.arch}} + tree ${{ github.workspace }}/deps/build_${{inputs.arch}}/PrusaSlicer_dep_${{inputs.arch}} + + - name: Build slicer mac + if: inputs.os == 'macos-12' + working-directory: ${{ github.workspace }} + run: | + ./build_release_macos.sh -s -n -a ${{inputs.arch}} -t 10.15 + + - name: Create DMG without notary + if: github.ref != 'refs/heads/boss' && inputs.os == 'macos-12' + working-directory: ${{ github.workspace }} + run: | + ln -s /Applications ${{ github.workspace }}/build_${{inputs.arch}}/PrusaSlicer/Applications + hdiutil create -volname "PrusaSlicer" -srcfolder ${{ github.workspace }}/build_${{inputs.arch}}/PrusaSlicer -ov -format UDZO PrusaSlicer_Mac_${{inputs.arch}}_${{ env.ver }}.dmg + + - name: Upload artifacts mac + if: inputs.os == 'macos-12' + uses: actions/upload-artifact@v3 + with: + name: PrusaSlicer_Mac_${{inputs.arch}}_${{ env.ver }} + path: ${{ github.workspace }}/PrusaSlicer_Mac_${{inputs.arch}}_${{ env.ver }}.dmg + +# Windows + - name: setup MSVC + if: inputs.os == 'windows-latest' + uses: microsoft/setup-msbuild@v1.1 + + - name: Install nsis + if: inputs.os == 'windows-latest' + run: | + dir "C:/Program Files (x86)/Windows Kits/10/Include" + choco install nsis + + - name: Build slicer Win + if: inputs.os == 'windows-latest' + working-directory: ${{ github.workspace }} + run: .\build_release_vs2022.bat slicer + + - name: Create installer Win + if: inputs.os == 'windows-latest' + working-directory: ${{ github.workspace }}/build + run: | + cpack -G NSIS + + - name: Pack app + if: inputs.os == 'windows-latest' + working-directory: ${{ github.workspace }}/build + shell: cmd + run: '"C:/Program Files/7-Zip/7z.exe" a -tzip PrusaSlicer_Windows_${{ env.ver }}_portable.zip ${{ github.workspace }}/build/PrusaSlicer' + + - name: Upload artifacts Win zip + if: inputs.os == 'windows-latest' + uses: actions/upload-artifact@v3 + with: + name: PrusaSlicer_Windows_${{ env.ver }}_portable + path: ${{ github.workspace }}/build/PrusaSlicer_Windows_${{ env.ver }}_portable.zip + + - name: Upload artifacts Win installer + if: inputs.os == 'windows-latest' + uses: actions/upload-artifact@v3 + with: + name: PrusaSlicer_Windows_${{ env.ver }} + path: ${{ github.workspace }}/build/PrusaSlicer*.exe diff --git a/build_release_macos.sh b/build_release_macos.sh new file mode 100755 index 00000000000..01ddefd833b --- /dev/null +++ b/build_release_macos.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +while getopts ":a:sdpt:hn" opt; do + case ${opt} in + d ) + export BUILD_TARGET="deps" + ;; + p ) + export PACK_DEPS="1" + ;; + a ) + export ARCH="$OPTARG" + ;; + s ) + export BUILD_TARGET="slicer" + ;; + n ) + export NIGHTLY_BUILD="1" + ;; + t ) + export OSX_DEPLOYMENT_TARGET="$OPTARG" + ;; + h ) echo "Usage: ./build_release_macos.sh [-d]" + echo " -d: Build deps only" + echo " -a: Set ARCHITECTURE (arm64 or x86_64)" + echo " -s: Build slicer only" + echo " -n: Nightly build" + echo " -t: Specify minimum version of the target platform, default is 11.3" + exit 0 + ;; + esac +done + +if [ -z "$ARCH" ] +then + export ARCH=$(uname -m) +fi + +echo "Arch: $ARCH" +echo "BUILD_TARGET: $BUILD_TARGET" +echo "OSX_DEPLOYMENT_TARGET: $OSX_DEPLOYMENT_TARGET" +# if which -s brew; then +# brew --prefix libiconv +# brew --prefix zstd +# export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/ +# elif which -s port; then +# port install libiconv +# port install zstd +# export LIBRARY_PATH=$LIBRARY_PATH:/opt/local/lib +# else +# echo "Need either brew or macports to successfully build deps" +# exit 1 +# fi + + +WD="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd $WD/deps +mkdir -p build_$ARCH +cd build_$ARCH +DEPS=$PWD/OrcaSlicer_dep_$ARCH +mkdir -p $DEPS +if [ "slicer." != $BUILD_TARGET. ]; +then + echo "building deps..." + echo "cmake ../ -DDESTDIR=$DEPS -DOPENSSL_ARCH=darwin64-${ARCH}-cc -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES:STRING=${ARCH} -DCMAKE_OSX_DEPLOYMENT_TARGET=${OSX_DEPLOYMENT_TARGET}" + cmake ../ -DDESTDIR="$DEPS" -DOPENSSL_ARCH="darwin64-${ARCH}-cc" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES:STRING=${ARCH} -DCMAKE_OSX_DEPLOYMENT_TARGET=${OSX_DEPLOYMENT_TARGET} + cmake --build . --config Release --target deps + if [ "1." == "$PACK_DEPS". ]; + then + tar -zcvf OrcaSlicer_dep_mac_${ARCH}_$(date +"%Y%m%d").tar.gz OrcaSlicer_dep_$ARCH + fi +fi + + +if [ "deps." == "$BUILD_TARGET". ]; +then + exit 0 +fi + +cd $WD +mkdir -p build_$ARCH +cd build_$ARCH +echo "building slicer..." +cmake .. -GXcode -DBBL_RELEASE_TO_PUBLIC=1 -DCMAKE_PREFIX_PATH="$DEPS/usr/local" -DCMAKE_INSTALL_PREFIX="$PWD/OrcaSlicer" -DCMAKE_BUILD_TYPE=Release -DCMAKE_MACOSX_RPATH=ON -DCMAKE_INSTALL_RPATH="$DEPS/usr/local" -DCMAKE_MACOSX_BUNDLE=ON -DCMAKE_OSX_ARCHITECTURES=${ARCH} -DCMAKE_OSX_DEPLOYMENT_TARGET=${OSX_DEPLOYMENT_TARGET} +cmake --build . --config Release --target ALL_BUILD +cd .. +./run_gettext.sh +cd build_$ARCH +mkdir -p OrcaSlicer +cd OrcaSlicer +rm -r ./OrcaSlicer.app +cp -pR ../src/Release/OrcaSlicer.app ./OrcaSlicer.app +resources_path=$(readlink ./OrcaSlicer.app/Contents/Resources) +rm ./OrcaSlicer.app/Contents/Resources +cp -R $resources_path ./OrcaSlicer.app/Contents/Resources +# delete .DS_Store file +find ./OrcaSlicer.app/ -name '.DS_Store' -delete +# extract version +# export ver=$(grep '^#define SoftFever_VERSION' ../src/libslic3r/libslic3r_version.h | cut -d ' ' -f3) +# ver="_V${ver//\"}" +# echo $PWD +# if [ "1." != "$NIGHTLY_BUILD". ]; +# then +# ver=${ver}_dev +# fi + + +# zip -FSr OrcaSlicer${ver}_Mac_${ARCH}.zip OrcaSlicer.app