Files
spacedrive/.github/scripts/setup-system.sh
T
Vítor Vasconcellos cf482f5621 [ENG-270, ENG-213] Stabilize release pipeline (#768)
* Attempt at building our own ffmpeg dylibs for macOS
 - Create dockerfile to setup osxcross and required host dependencies for cross-compiling ffmpeg for macOS
 - Create script to setup required macOS dependencies and build ffmpeg for both x86_64 and aarch64

* Improve dockerfile to better use docker's cache
 - Attempt at fixing arm64 build (still not there yet)

* ARM64 sucessfully compiles \o/
 - Use clang for everything (e.g. linker, assembler, ...)
 - Remove -lc++ because it is now handled internally thanks to a patch
 - Apply 3 open PRs to osxcross as external patches to solve some of our problems
 - PR 180 reduces the macports dependencies size by prefering non universal libs for x88
 - PR 314 adds the -lc++ flag for macOS SDKs >= 11.1
 - PR 379 fix macports pulling incorrects deps for SDK11 and adds support for SDK13 (future proofing, as it does nothing for us rigth now)

* Fix relink and copy logic in ffmpeg build script
 - Ensure ffmpeg and dependencies dylibs are correctly relinked and copied over to the output directory
 - Copy includes from ffmpeg and dependencies to allow for dev building against these dylibs
 - Set up symlinks for all dylibs to the common `lib` directory
 - Remove superfluous linker and compiler options
 - Add `-headerpad_max_install_names` linker option to accommodate the required relink changes
 - Remove `--disable-fft` for the arm64 build, as it doesn't seem to be required nowadays
 - Allow `swresample` and `avdevices` to be compiled as they seem to be expected to exist by `ffmpeg-sys-next`
 - Disable ffmpeg program compilation
 - Fix dylibs id to match their new expected location
 - Fix ffmpeg dylibs inter-linkage not being updated
 - Add custom patch for osxcross macports to load already downloaded files from cache
 - Remove the requirement for specifying the darwin version in the Dockerfile
 - Enable docker cache for macports
 - Move arm min macOS version ARG to the top

* Attempt at building ffmpeg with github actions
 - Split osxcross setup into it's own Dockerfile to allow exporting it as a image to Dockerhub
 - Create a github action to build ffmpeg
 - Add osxcross patch for PR 372 for future proofing (Add support for macOS SDK 13.1)

* Remove incompatible step name

* Change FFMPEG_VERSION to string to avoid yaml weird type casting

* Start to use our ffmpeg build in the macOS
 - Adjust the macOS setup script to download our ffmpeg build, also replace installing protobuf compiler from brew with grabbing it from it's own repository
 - Some misc improvement to the *nix setup script
 - Fix ffmpeg build script not copying static libs (for when we may want to statically link ffmpeg)
 - Fix ffmpeg build script not taking into acount possible libraries that are multiple paths deep in /lib
 - Update CI to actions/checkout@v3, v2 is deprecated
 - Update ffmpeg build CI to not xz the artifacts, as github already zips it anyway

* Fix macOS setup not finding the ffmpeg artifact due to a jq script mistake
 - Comment out embeeding static libs in ffmpeg artifact for now, as they take too much space
 - Remove incorrect dockerfile settings from editorconfig

* Fix protobuf download in macOS
 - Fix Framework directory creation not following script's dir but cwd
 - Improve download logic to avoid being rate limited on failures
 - Return to using xz for ffmpeg build, as it saves quite a bit of space

* Replace `OSTYPE` with `$(uname)` for a more standardized way to check which os is running
 - Fix mobile check using `==` instead of `=` in test command

* Fix syntax error in bash 3.x (which is the default in macOS)
 - Fix jq not downloading all deps and being placed in the incorrect directory

* Fix incorrect install_name_tool arguments
 - Remove leading './' when referencing ffmpeg libs during build

* Fix protoc not being executable
 - Fix some error messages

* jq throw input when it is invalid
 - Enable debug log in setup script when running in CI

* Add a dev.js build script for desktop app
 - Remove dll copy from setup-system.ps1, now done by dev.js
 - Minor rework to build.js to improve signals and stdio handling

* Configure cargo to use FFMPEG_DIR and PROTOC envvars on macOS

* Pass GITHUB_TOKEN to macOS setup script in CI

* Replace simple curl with gh_curl in github request

* Fix some ctrl+c/ctrl+v typos

* Add missing ffmpeg deps
 - Fix missing symlinks for ffmpeg libs in the output_dir/libs
 - Change arm64 minimum macOS target to 11.2 due to libbrotli only being available precompiled to this version
 - Add more options to ffmpeg configure in an attempt to reduce its size + improve performance

* Rework ffmpeg build script to create a FFMpeg.framework instead of loose dylibs
 - Disable unused postproc and enabled missing required protocols in ffmpeg configuration
 - Adjust Dockerfile and setup-script to handle the new FFMpeg.framework

* Fix setup script incorrect linking logic for FFMpeg.framework

* Forgot to remote the leading path in the lib/header linking logic for FFMpeg.framework

* Enable size optimization for ffmpeg
 - Remove Frameworks directory before setting it up in setup-system.sh

* Revert lib id to use `@executable_path/../Frameworks/` instead of `@rpath`
 - `@rpath` breaks dev builds
 - Add logic to create less versioned versions of dylibs in setup-system script, due to it being required for compiling ffmpeg-sys-next (not required during runtime, just for compilation)
 - Add scripts/deps to gitignore

* Fix ffmpeg build script not copying unversioned symlinks to FFMpeg.framework
 - Remove unecessary unversioned symlink logic from setup-system
 - Add new build scripts for dev and prod that setup the environment and tauri to correctly point to FFMpeg.framework
 - Rework windows setup-system script to follow the same logic as in macOS setup-system

* Attempt at fixing windows setup script
 - Add powershell editorconfig

* Attempt to fix Windows CI

* Fix some mistakes in the build scripts
 - Replace toml lib with something more used and maybe better?
 - Attempt to fix Windows CI

* Fix some more problems with the build script

* Another attempt at fixing windows CI

* Some more fixes for the windows setup script

* Add build.js step to release CI
 - Implement patch only mode for build.js when running under CI
 - Implement appeding extra env in cargo config in env.js
 - Only run windows dlls copy in dev in env.js
 - Another attempt at fixing windows CI

* Maybe this will make the windows CI happy?

* Windows CI why dont you work, whyyy?

* Try to apease the Windows CI Gods
 - Disable updater build in macOS, due to tauri-apps/tauri#3933

* Fix build.js extra env vars
 - Uncomment parts of setup-system.ps1 to check if it keeps working

* Uncomment another section and see if windows CI will complain

* uncomment some more of setup-system.ps1

* Use Start-Process for robocopy instead of executing it directly
 - Only raise an error if robocopy exists with a status code >=8
 - Revert build.js macOS specific bundles change
 - Disable updater for now

* Remove updater from cargo.toml

* Add -PassThru to Start-Process to ensure we get and Process obj back

* Comment out more of updater

* Improve documentation for both of the docker containers
 - Fix a harcoded install_name_tool call in the ffmpeg-build-macos.sh script

* Configure tauri to copy ffmpeg dlls to windows prod version
 - Fix windows dlls copy on dev
 - Stop replacing tauri.conf.json, except on CI, for prod builds and use a tauri.conf.patch.json for any required changes
 - Don't unset macOSPrivateApi on prod build, we need it for the transparent background
 - Fix dev.js not exiting when the spawned command was over

* Fix windows not find protoc
 - Fix missing import in env.js

* Fix Windows Dlls copy logic for prod build
 - Fix dev script failing due to missing env
 - Implement error handler to spawned process

* Format + Fix pnpm-lock

* Fix video thumb generation failing on Windows due to bad path to CString conversion logic

* Fix mobile build
 - Greatly improve windows setup-script error handling
 - Install LLVM with winget instead of downloading exe from github

* Improve CI a bit
 - Fix mobile CI not using github token to avoid being rate limited

* Fix pnpm not accesible to actions/setup-node

* Skip pnpm check on CI

* Fix pnpm skip not working
 - Fix pnpm cache check missing a step

* Only lock action to major versions

* CI really doesn't like running robocopy directly

* Attempt to build our own patched tauri bundler

* Trigger new workflow

* Fix attempt for patched tauri action tests
 - Disable cache for patched tauri action
 - Enable package publishing for patched tauri action

* Attempt fix patched tauri publish

* Remove commented code from patched tauri workflow
 - Replace deprecated `actions-rs/toolchain` with `dtolnay/rust-toolchain`

* Fix url patching logic for publishing step of patched tauri package

* Fix prepublishOnly command for patched tauri package

* Adjust patched tauri package package.json

* Also patch the specific os/arch sub packages

* Instruct napi to stop doing github releases

* Patch package.json befor build

* Re-enable updater
 - Patch tauri cli to workaround a tauri bug that prevented use from bundling frameworks in the updater
 - Update tauri/api to 1.3 and tauri/cli 1.3.1
 - Add target triple in the release artifacts name
 - Use ubuntu-20.04 instead of ubuntu-latest
 - Configure release workflow to build to all supported platforms
 - Replace `tauri-apps/tauri-action` with simply calling `pnpm desktop build`
 - Simplify tauri-patched-cli-js to only build the required macOS binaries
 - Unify build.js and dev.js in a tauri.js build script, which now acts as an all around wrapper for the tauri/cli

* Restore incorrectly removed step from `tauri-patched-cli-js`

* Disable auto-run of tauri-patched-cli-js
 - Update setup-system.sh with the latest tauri-patched-cli-js artifacts

* Forgot to mkdir bin

* Fix pnpm-lock.yaml not being up to date
 - Remove pnpm deps caching

* Fix variable name conflict

* Enable the updater build conditionally
 - Enable release workflow to test it

* Fix artifacts not being published
 - Change macOS on arm64 minimumSystemVersion to 11.2
 - Commented out rust cache to check if this is the culprit to the low memory problem on windows runner
 - Add some debug log to tauri.js

* Fix release workflow artifact uploading

* Specify which bundles to build on each platform
 - Attempt fix apple arm build
 - Don't include internal deb archives in linux updater artifact

* Attempt to fix apple arm build
 - Fix dmg background not applying

* Fix incorrect semver usage

* Patch swift-rs to see if that fix apple arm64 release build

* Update swift-rs submodule
 - Remove unused deps lodash.merge

* Configure so only release workflow runs without cache
 - Improve tauri.js logs

* Ignore `crates/swift-rs`

* Revert "Ignore `crates/swift-rs`"
- Remove `crates/swift-rs` before running `cargo fmt`

This reverts commit 851bd84373.

* Github CI input/output are always string
 - Attempt to fix Windows Clippy

* Fix CI syntax error

* Fix mobile CI
 - Disable pnpm deps caching
 - Disable rust targets caching on Windows
 - Configure cache factory to run for all targets

* Remove `crates/swift-rs`

* Attempt fix Mobile CI
 - Enable cache factory run in pull_request to test it
 - Specific more path for the CI run to ignore
 - Specify path that will trigger the cache factory run
 - Some cleanup in the setup-pnpm action

* Remove restore-cache options
 - Add prefix key to cache-factory
 - Fix LLVM cache-hit check
 - Add libheif to FFMpeg.framework

* Remove submodule clone from actions

* Add fake deps to ffmpeg build dockerfile
 - Fake install deps that aren't really necessary to build ffmpeg
 - Fail ffmpeg build script if it can't find a macports deps
 - Copy libheif headers to Framework

* Remove automatic trigger for relase and pull request trigger for cache-factory actions

* Remove pnpm setup from Cache factory
 - Cache factory is exclusivly for rust deps caching, no need to setup Node and pnpm with it

* Re-enabled fail-fast in Github CI
2023-05-15 18:02:56 +00:00

391 lines
14 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [ "${CI:-}" = "true" ]; then
set -x
fi
SYSNAME="$(uname)"
FFMPEG_VERSION='6.0'
err() {
for _line in "$@"; do
echo "$@" >&2
done
exit 1
}
has() {
if [ "$#" -ne 1 ]; then
err "Usage: has <command>"
fi
command -v "$1" >/dev/null 2>&1
}
_gh_url="https://api.github.com/repos"
_sd_gh_path='spacedriveapp/spacedrive'
gh_curl() {
if [ "$#" -ne 1 ]; then
err "Usage: gh_curl <api_route>"
fi
url="$1"
# Required headers for GitHub API
set -- -LSs -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
# Add authorization header if GITHUB_TOKEN is set, to avoid being rate limited
if [ -n "${GITHUB_TOKEN:-}" ]; then
set -- "$@" -H "Authorization: Bearer $GITHUB_TOKEN"
fi
curl "$@" "$url"
}
script_failure() {
if [ -n "${1:-}" ]; then
_line="on line $1"
else
_line="(unknown)"
fi
err "An error occurred $_line." "Setup failed."
}
trap 'script_failure ${LINENO:-}' ERR
echo "Setting up this system for Spacedrive development."
echo
# Change CWD to the directory of this script
CDPATH='' cd -- "$(dirname -- "$0")"
_script_path="$(pwd -P)"
_cargo_config="${_script_path}/../../.cargo"
rm -rf "$_cargo_config/config"
if ! has cargo; then
err 'Rust was not found.' \
"Ensure the 'rustc' and 'cargo' binaries are in your \$PATH." \
'https://rustup.rs'
fi
if [ "${CI:-}" != "true" ] && [ "${spacedrive_skip_pnpm_check:-}" != "true" ]; then
echo "checking for pnpm..."
if ! has pnpm; then
err 'pnpm was not found.' \
"Ensure the 'pnpm' command is in your \$PATH." \
'You must use pnpm for this project; yarn and npm are not allowed.' \
'https://pnpm.io/installation'
else
echo "found pnpm!"
fi
else
echo "Skipping pnpm check."
fi
if [ "${CI:-}" != "true" ]; then
echo "Installing Rust tools"
cargo install cargo-watch
fi
echo
if [ "${1:-}" = "mobile" ]; then
echo "Setting up for mobile development."
# iOS targets
if [ "$SYSNAME" = "Darwin" ]; then
echo "Checking for Xcode..."
if ! /usr/bin/xcodebuild -version >/dev/null; then
err "Xcode was not detected." \
"Please ensure Xcode is installed and try again."
fi
echo "Installing iOS targets for Rust..."
rustup target add aarch64-apple-ios
rustup target add aarch64-apple-ios-sim
rustup target add x86_64-apple-ios # for CI
fi
# Android requires python
if ! command -v python3 >/dev/null; then
err 'python3 was not found.' \
'This is required for Android mobile development.' \
"Ensure 'python3' is available in your \$PATH and try again."
fi
# Android targets
echo "Setting up Android targets for Rust..."
rustup target add armv7-linux-androideabi # for arm
rustup target add aarch64-linux-android # for arm64
rustup target add i686-linux-android # for x86
rustup target add x86_64-linux-android # for x86_64
rustup target add x86_64-unknown-linux-gnu # for linux-x86-64
rustup target add aarch64-apple-darwin # for darwin arm64 (if you have an M1 Mac)
rustup target add x86_64-apple-darwin # for darwin x86_64 (if you have an Intel Mac)
rustup target add x86_64-pc-windows-gnu # for win32-x86-64-gnu
rustup target add x86_64-pc-windows-msvc # for win32-x86-64-msvc
echo "Done setting up mobile targets."
echo
fi
if [ "$SYSNAME" = "Linux" ]; then
if has apt-get; then
echo "Detected apt!"
echo "Installing dependencies with apt..."
# Tauri dependencies
DEBIAN_TAURI_DEPS="libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev patchelf"
# FFmpeg dependencies
DEBIAN_FFMPEG_DEPS="libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev ffmpeg"
# Webkit2gtk requires gstreamer plugins for video playback to work
DEBIAN_VIDEO_DEPS="gstreamer1.0-libav gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly"
# Bindgen dependencies - it's used by a dependency of Spacedrive
DEBIAN_BINDGEN_DEPS="pkg-config clang"
# Protobuf compiler
DEBIAN_LIBP2P_DEPS="protobuf-compiler"
sudo apt-get -y update
sudo apt-get -y install ${SPACEDRIVE_CUSTOM_APT_FLAGS:-} $DEBIAN_TAURI_DEPS $DEBIAN_FFMPEG_DEPS $DEBIAN_BINDGEN_DEPS $DEBIAN_LIBP2P_DEPS $DEBIAN_VIDEO_DEPS
elif has pacman; then
echo "Detected pacman!"
echo "Installing dependencies with pacman..."
# Tauri deps https://tauri.studio/guides/getting-started/setup/linux#1-system-dependencies
ARCH_TAURI_DEPS="webkit2gtk base-devel curl wget openssl appmenu-gtk-module gtk3 libappindicator-gtk3 librsvg libvips patchelf"
# Webkit2gtk requires gstreamer plugins for video playback to work
ARCH_VIDEO_DEPS="gst-libav gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly"
# FFmpeg dependencies
ARCH_FFMPEG_DEPS="ffmpeg"
# Bindgen dependencies - it's used by a dependency of Spacedrive
ARCH_BINDGEN_DEPS="clang"
# Protobuf compiler - https://github.com/archlinux/svntogit-packages/blob/packages/protobuf/trunk/PKGBUILD provides `libprotoc`
ARCH_LIBP2P_DEPS="protobuf"
sudo pacman -Sy --needed $ARCH_TAURI_DEPS $ARCH_FFMPEG_DEPS $ARCH_BINDGEN_DEPS $ARCH_LIBP2P_DEPS $ARCH_VIDEO_DEPS
elif has dnf; then
echo "Detected dnf!"
echo "Installing dependencies with dnf..."
# `webkit2gtk4.0-devel` also provides `webkit2gtk3-devel`, it's just under a different package in fedora versions >= 37.
# https://koji.fedoraproject.org/koji/packageinfo?tagOrder=-blocked&packageID=26162#taglist
# https://packages.fedoraproject.org/pkgs/webkitgtk/webkit2gtk4.0-devel/fedora-38.html#provides
FEDORA_37_TAURI_WEBKIT="webkit2gtk4.0-devel"
FEDORA_36_TAURI_WEBKIT="webkit2gtk3-devel"
# Tauri dependencies
# openssl is manually declared here as i don't think openssl and openssl-devel are actually dependant on eachother
# openssl also has a habit of being missing from some of my fresh Fedora installs - i've had to install it at least twice
FEDORA_TAURI_DEPS="openssl-devel curl wget libappindicator-gtk3 librsvg2-devel patchelf"
# required for building the openssl-sys crate
FEDORA_OPENSSL_SYS_DEPS="perl-FindBin perl-File-Compare perl-IPC-Cmd perl-File-Copy"
# FFmpeg dependencies
FEDORA_FFMPEG_DEPS="ffmpeg ffmpeg-devel"
# Webkit2gtk requires gstreamer plugins for video playback to work
FEDORA_VIDEO_DEPS="gstreamer1-plugin-libav gstreamer1-plugins-base gstreamer1-plugins-good gstreamer1-plugins-good-extras gstreamer1-plugins-bad-free gstreamer1-plugins-bad-free-extras gstreamer1-plugins-ugly-free"
# Bindgen dependencies - it's used by a dependency of Spacedrive
FEDORA_BINDGEN_DEPS="clang"
# Protobuf compiler
FEDORA_LIBP2P_DEPS="protobuf-compiler"
if ! sudo dnf install $FEDORA_37_TAURI_WEBKIT && ! sudo dnf install $FEDORA_36_TAURI_WEBKIT; then
err 'We were unable to install the webkit2gtk4.0-devel/webkit2gtk3-devel package.' \
'Please open an issue if you feel that this is incorrect.' \
'https://github.com/spacedriveapp/spacedrive/issues'
fi
if ! sudo dnf install $FEDORA_FFMPEG_DEPS; then
err 'We were unable to install the FFmpeg and FFmpeg-devel packages.' \
'This is likely because the RPM Fusion free repository is not enabled.' \
'https://docs.fedoraproject.org/en-US/quick-docs/setup_rpmfusion'
fi
sudo dnf install $FEDORA_TAURI_DEPS $FEDORA_BINDGEN_DEPS $FEDORA_LIBP2P_DEPS $FEDORA_VIDEO_DEPS
sudo dnf group install "C Development Tools and Libraries"
else
err "Your Linux distro '$(lsb_release -s -d)' is not supported by this script." \
'We would welcome a PR or some help adding your OS to this script:' \
'https://github.com/spacedriveapp/spacedrive/issues'
fi
elif [ "$SYSNAME" = "Darwin" ]; then
# Location for installing script dependencies
_deps_dir="${_script_path}/deps"
mkdir -p "$_deps_dir"
PATH="$PATH:${_deps_dir}"
export PATH
_arch="$(uname -m)"
if ! has jq; then
echo "Download jq build..."
# Determine the machine's architecture
case "$_arch" in
x86_64)
_jq_url='https://packages.macports.org/jq/jq-1.6_4.darwin_19.x86_64.tbz2'
_oniguruma6_url='https://packages.macports.org/oniguruma6/oniguruma6-6.9.8_0.darwin_19.x86_64.tbz2'
;;
arm64)
_jq_url='https://packages.macports.org/jq/jq-1.6_4.darwin_20.arm64.tbz2'
_oniguruma6_url='https://packages.macports.org/oniguruma6/oniguruma6-6.9.8_0.darwin_20.arm64.tbz2'
;;
*)
err "Unsupported architecture: $_arch"
;;
esac
# Download the latest jq binary and deps from macports
curl -LSs "$_jq_url" | tar -xjOf - ./opt/local/bin/jq >"${_deps_dir}/jq"
curl -LSs "$_oniguruma6_url" | tar -xjOf - ./opt/local/lib/libonig.5.dylib >"${_deps_dir}/libonig.5.dylib"
# Make the binaries executable
chmod +x "$_deps_dir"/*
# Make jq look for deps in the same directory
install_name_tool -change '/opt/local/lib/libonig.5.dylib' '@executable_path/libonig.5.dylib' "${_deps_dir}/jq"
fi
# Create frameworks directory to put Spacedrive dependencies
_frameworks_dir="${_script_path}/../../target/Frameworks"
rm -rf "$_frameworks_dir"
mkdir -p "${_frameworks_dir}/"{bin,lib,include}
_frameworks_dir="$(CDPATH='' cd -- "$_frameworks_dir" && pwd -P)"
exec 3>&1 # Copy stdout to fd 3.
echo "Download ffmpeg build..."
_page=1
while [ $_page -gt 0 ]; do
# TODO: Filter only actions triggered by the main branch
_success=$(gh_curl "${_gh_url}/${_sd_gh_path}/actions/workflows/ffmpeg.yml/runs?page=${_page}&per_page=100&status=success" \
| jq -r '. as $raw | .workflow_runs | if length == 0 then error("Error: \($raw)") else .[] | .artifacts_url end' \
| while IFS= read -r _artifacts_url; do
if _artifact_path="$(
gh_curl "$_artifacts_url" \
| jq --arg version "$FFMPEG_VERSION" --arg arch "$(
if [ "${TARGET:-}" = 'aarch64-apple-darwin' ]; then
echo 'arm64'
else
echo "$_arch"
fi
)" -r \
'. as $raw | .artifacts | if length == 0 then error("Error: \($raw)") else .[] | select(.name == "ffmpeg-\($version)-\($arch)") | "suites/\(.workflow_run.id)/artifacts/\(.id)" end'
)"; then
# nightly.link is a workaround for the lack of a public GitHub API to download artifacts from a workflow run
# https://github.com/actions/upload-artifact/issues/51
# TODO: Use Github's private API when running on CI
if curl -LSs "https://nightly.link/${_sd_gh_path}/${_artifact_path}" | tar -xOf- | XZ_OPT='-T0' tar -xJf- -C "$_frameworks_dir"; then
printf 'yes'
exit
fi
echo "Failed to ffmpeg artifiact release, trying again in 1sec..." >&3
sleep 1
fi
done)
if [ "${_success:-}" = 'yes' ]; then
break
fi
_page=$((_page + 1))
echo "ffmpeg artifact not found, trying again in 1sec..."
sleep 1
done
# Symlink the FFMpeg.framework libs to the lib directory
for _lib in "${_frameworks_dir}/FFMpeg.framework/Libraries/"*; do
_lib="${_lib#"${_frameworks_dir}/FFMpeg.framework/Libraries/"}"
ln -s "../FFMpeg.framework/Libraries/${_lib}" "${_frameworks_dir}/lib/${_lib}"
done
# Symlink the FFMpeg.framework headers to the include directory
for _header in "${_frameworks_dir}/FFMpeg.framework/Headers/"*; do
_header="${_header#"${_frameworks_dir}/FFMpeg.framework/Headers/"}"
ln -s "../FFMpeg.framework/Headers/${_header}" "${_frameworks_dir}/include/${_header}"
done
# Workaround while https://github.com/tauri-apps/tauri/pull/3934 is not merged
echo "Download patched tauri cli.js build..."
case "$_arch" in
x86_64)
_artifact_url="https://nightly.link/${_sd_gh_path}/actions/artifacts/687573480.zip"
;;
arm64)
_artifact_url="https://nightly.link/${_sd_gh_path}/actions/artifacts/687573479.zip"
;;
*)
err "Unsupported architecture: $_arch"
;;
esac
curl -LSs "$_artifact_url" | tar -xf- -C "${_frameworks_dir}/bin"
echo "Download protobuf build"
_page=1
while [ $_page -gt 0 ]; do
_success=$(gh_curl "${_gh_url}/protocolbuffers/protobuf/releases?page=${_page}&per_page=100" \
| jq --arg arch "$(
if [ "$_arch" = 'arm64' ]; then
echo 'aarch_64'
else
echo 'x86_64'
fi
)" -r \
'. as $raw | if length == 0 then error("Error: \($raw)") else .[] | select(.prerelease | not) | .assets[] | select(.name | endswith("osx-\($arch).zip")) | .browser_download_url end' \
| while IFS= read -r _asset_url; do
if curl -LSs "${_asset_url}" | tar -xf - -C "$_frameworks_dir"; then
printf 'yes'
exit
fi
echo "Failed to download protobuf release, trying again in 1sec..." >&3
sleep 1
done)
if [ "${_success:-}" = 'yes' ]; then
break
fi
_page=$((_page + 1))
echo "protobuf release not found, trying again in 1sec..."
sleep 1
done
# Ensure all binaries are executable
chmod +x "$_frameworks_dir"/bin/*
cat <<EOF >"${_cargo_config}/config"
[env]
PROTOC = "${_frameworks_dir}/bin/protoc"
FFMPEG_DIR = "${_frameworks_dir}"
$(cat "${_cargo_config}/config.toml")
EOF
else
err "Your OS ($SYSNAME) is not supported by this script." \
'We would welcome a PR or some help adding your OS to this script.' \
'https://github.com/spacedriveapp/spacedrive/issues'
fi
echo "Your machine has been successfully set up for Spacedrive development."