Skip to content

Commit

Permalink
Build dependencies from sources
Browse files Browse the repository at this point in the history
The project has 3 build dependencies:
 - SDL
 - FFmpeg
 - libusb

For Windows, the release script downloaded pre-built build dependencies
(either from upstream, or from the scrcpy-deps repository).

Instead, download the source releases and build locally. This offers
more flexibility.

The official adb release is still downloaded and included as is in the
release archive (it is not a build dependency).
  • Loading branch information
rom1v committed Mar 1, 2024
1 parent 36189b9 commit 3f349c7
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 184 deletions.
2 changes: 2 additions & 0 deletions app/deps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/data
/install
25 changes: 25 additions & 0 deletions app/deps/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This directory (app/deps/) contains:

*.sh : shell scripts to download and build dependencies
patches/ : patches to fix dependencies (used by scripts)
data/sources/ : downloaded tarballs and extracted folders
ffmpeg-6.1.1.tar.xz
ffmpeg-6.1.1/
libusb-1.0.27.tar.gz
libusb-1.0.27/
...
data/work/ : build dirs for each dependency/version/architecture
ffmpeg-6.1.1/build-win32
ffmpeg-6.1.1/build-win64
libusb-1.0.27/build-win32
libusb-1.0.27/build-win64
...
install/ : install dirs for each architexture
win32/bin/
win32/include/
win32/lib/
win32/share/
win64/bin/
win64/include/
win64/lib/
win64/share/
32 changes: 32 additions & 0 deletions app/deps/adb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -ex
DEPS_DIR=$(dirname ${BASH_SOURCE[0]})
cd "$DEPS_DIR"
. common

VERSION=34.0.5
FILENAME=platform-tools_r$VERSION-windows.zip
PROJECT_DIR=platform-tools-$VERSION
SHA256SUM=3f8320152704377de150418a3c4c9d07d16d80a6c0d0d8f7289c22c499e33571

cd "$SOURCES_DIR"

if [[ -d "$PROJECT_DIR" ]]
then
echo "$PWD/$PROJECT_DIR" found
else
get_file "https://dl.google.com/android/repository/$FILENAME" "$FILENAME" "$SHA256SUM"
mkdir -p "$PROJECT_DIR"
cd "$PROJECT_DIR"
ZIP_PREFIX=platform-tools
unzip "../$FILENAME" \
"$ZIP_PREFIX"/AdbWinApi.dll \
"$ZIP_PREFIX"/AdbWinUsbApi.dll \
"$ZIP_PREFIX"/adb.exe
mv "$ZIP_PREFIX"/* .
rmdir "$ZIP_PREFIX"
fi

mkdir -p "$INSTALL_DIR/bin"
cd "$INSTALL_DIR/bin"
cp -r "$SOURCES_DIR/$PROJECT_DIR"/. "$INSTALL_DIR/bin/"
61 changes: 61 additions & 0 deletions app/deps/common
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# This file is intended to be sourced by other scripts, not executed

if [[ $# != 1 ]]
then
# <host>: win32 or win64
echo "Syntax: $0 <host>" >&2
exit 1
fi

HOST="$1"

if [[ "$HOST" = win32 ]]
then
HOST_TRIPLET=i686-w64-mingw32
elif [[ "$HOST" = win64 ]]
then
HOST_TRIPLET=x86_64-w64-mingw32
else
echo "Unsupported host: $HOST" >&2
exit 1
fi

DEPS_DIR=$(dirname ${BASH_SOURCE[0]})
cd "$DEPS_DIR"

PATCHES_DIR="$PWD/patches"

INSTALL_DIR="$PWD/install/$HOST"

# Contains $SOURCE_DIR and $WORK_DIR
DATA_DIR="$PWD/data"

# Contains downloaded tarballs and extracted folders
SOURCES_DIR="$DATA_DIR/sources"

# Contains build dirs
WORK_DIR="$DATA_DIR/work"

mkdir -p "$INSTALL_DIR" "$SOURCES_DIR" "$WORK_DIR"

checksum() {
local file="$1"
local sum="$2"
echo "$file: verifying checksum..."
echo "$sum $file" | sha256sum -c
}

get_file() {
local url="$1"
local file="$2"
local sum="$3"
if [[ -f "$file" ]]
then
echo "$file: found"
else
echo "$file: not found, downloading..."
wget "$url" -O "$file"
fi
checksum "$file" "$sum"
}
91 changes: 91 additions & 0 deletions app/deps/ffmpeg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env bash
set -ex
DEPS_DIR=$(dirname ${BASH_SOURCE[0]})
cd "$DEPS_DIR"
. common

VERSION=6.1.1
FILENAME=ffmpeg-$VERSION.tar.xz
PROJECT_DIR=ffmpeg-$VERSION
SHA256SUM=8684f4b00f94b85461884c3719382f1261f0d9eb3d59640a1f4ac0873616f968

cd "$SOURCES_DIR"

if [[ -d "$PROJECT_DIR" ]]
then
echo "$PWD/$PROJECT_DIR" found
else
get_file "https://ffmpeg.org/releases/$FILENAME" "$FILENAME" "$SHA256SUM"
tar xf "$FILENAME" # First level directory is "$PROJECT_DIR"
patch -d "$PROJECT_DIR" -p1 < "$PATCHES_DIR"/ffmpeg-6.1-fix-build.patch
fi

mkdir -p "$WORK_DIR/$PROJECT_DIR"
cd "$WORK_DIR/$PROJECT_DIR"

if [[ "$HOST" = win32 ]]
then
ARCH=x86
elif [[ "$HOST" = win64 ]]
then
ARCH=x86_64
else
echo "Unsupported host: $HOST" >&2
exit 1
fi

# -static-libgcc to avoid missing libgcc_s_dw2-1.dll
# -static to avoid dynamic dependency to zlib
export CFLAGS='-static-libgcc -static'
export CXXFLAGS="$CFLAGS"
export LDFLAGS='-static-libgcc -static'

if [[ -d "build-$HOST" ]]
then
echo "'$PWD/build-$HOST' already exists, not reconfigured"
cd "build-$HOST"
else
mkdir "build-$HOST"
cd "build-$HOST"

"$SOURCES_DIR/$PROJECT_DIR"/configure \
--prefix="$INSTALL_DIR" \
--enable-cross-compile \
--target-os=mingw32 \
--arch="$ARCH" \
--cross-prefix="${HOST_TRIPLET}-" \
--cc="${HOST_TRIPLET}-gcc" \
--extra-cflags="-O2 -fPIC" \
--enable-shared \
--disable-static \
--disable-programs \
--disable-doc \
--disable-swscale \
--disable-postproc \
--disable-avfilter \
--disable-avdevice \
--disable-network \
--disable-everything \
--enable-swresample \
--enable-decoder=h264 \
--enable-decoder=hevc \
--enable-decoder=av1 \
--enable-decoder=pcm_s16le \
--enable-decoder=opus \
--enable-decoder=aac \
--enable-decoder=flac \
--enable-decoder=png \
--enable-protocol=file \
--enable-demuxer=image2 \
--enable-parser=png \
--enable-zlib \
--enable-muxer=matroska \
--enable-muxer=mp4 \
--enable-muxer=opus \
--enable-muxer=flac \
--enable-muxer=wav \
--disable-vulkan
fi

make -j
make install
45 changes: 45 additions & 0 deletions app/deps/libusb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -ex
DEPS_DIR=$(dirname ${BASH_SOURCE[0]})
cd "$DEPS_DIR"
. common

VERSION=1.0.27
FILENAME=libusb-$VERSION.tar.gz
PROJECT_DIR=libusb-$VERSION
SHA256SUM=e8f18a7a36ecbb11fb820bd71540350d8f61bcd9db0d2e8c18a6fb80b214a3de

cd "$SOURCES_DIR"

if [[ -d "$PROJECT_DIR" ]]
then
echo "$PWD/$PROJECT_DIR" found
else
get_file "https://github.com/libusb/libusb/archive/refs/tags/v$VERSION.tar.gz" "$FILENAME" "$SHA256SUM"
tar xf "$FILENAME" # First level directory is "$PROJECT_DIR"
fi

mkdir -p "$WORK_DIR/$PROJECT_DIR"
cd "$WORK_DIR/$PROJECT_DIR"

export CFLAGS='-O2'
export CXXFLAGS="$CFLAGS"

if [[ -d "build-$HOST" ]]
then
echo "'$PWD/build-$HOST' already exists, not reconfigured"
cd "build-$HOST"
else
mkdir "build-$HOST"
cd "build-$HOST"

"$SOURCES_DIR/$PROJECT_DIR"/bootstrap.sh
"$SOURCES_DIR/$PROJECT_DIR"/configure \
--prefix="$INSTALL_DIR" \
--host="$HOST_TRIPLET" \
--enable-shared \
--disable-static
fi

make -j
make install-strip
27 changes: 27 additions & 0 deletions app/deps/patches/ffmpeg-6.1-fix-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 03c80197afb324da38c9b70254231e3fdcfa68fc Mon Sep 17 00:00:00 2001
From: Romain Vimont <rom@rom1v.com>
Date: Sun, 12 Nov 2023 17:58:50 +0100
Subject: [PATCH] Fix FFmpeg 6.1 build

Build failed on tag n6.1 With --enable-decoder=av1 but without
--enable-muxer=av1.
---
libavcodec/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 580a8d6b54..aff19b670c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -249,7 +249,7 @@ OBJS-$(CONFIG_ATRAC3PAL_DECODER) += atrac3plusdec.o atrac3plus.o \
OBJS-$(CONFIG_ATRAC9_DECODER) += atrac9dec.o
OBJS-$(CONFIG_AURA_DECODER) += cyuv.o
OBJS-$(CONFIG_AURA2_DECODER) += aura.o
-OBJS-$(CONFIG_AV1_DECODER) += av1dec.o
+OBJS-$(CONFIG_AV1_DECODER) += av1dec.o av1_parse.o
OBJS-$(CONFIG_AV1_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER) += mediacodecenc.o
--
2.42.0

47 changes: 47 additions & 0 deletions app/deps/sdl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -ex
DEPS_DIR=$(dirname ${BASH_SOURCE[0]})
cd "$DEPS_DIR"
. common

VERSION=2.28.5
FILENAME=SDL-$VERSION.tar.gz
PROJECT_DIR=SDL-release-$VERSION
SHA256SUM=9f0556e4a24ef5b267010038ad9e9948b62f236d5bcc4b22179f95ef62d84023

cd "$SOURCES_DIR"

if [[ -d "$PROJECT_DIR" ]]
then
echo "$PWD/$PROJECT_DIR" found
else
get_file "https://github.com/libsdl-org/SDL/archive/refs/tags/release-$VERSION.tar.gz" "$FILENAME" "$SHA256SUM"
tar xf "$FILENAME" # First level directory is "$PROJECT_DIR"
fi

mkdir -p "$WORK_DIR/$PROJECT_DIR"
cd "$WORK_DIR/$PROJECT_DIR"

export CFLAGS='-O2'
export CXXFLAGS="$CFLAGS"

if [[ -d "build-$HOST" ]]
then
echo "'$PWD/build-$HOST' already exists, not reconfigured"
cd "build-$HOST"
else
mkdir "build-$HOST"
cd "build-$HOST"

"$SOURCES_DIR/$PROJECT_DIR"/configure \
--prefix="$INSTALL_DIR" \
--host="$HOST_TRIPLET" \
--enable-shared \
--disable-static
fi

make -j
# There is no "make install-strip"
make install
# Strip manually
${HOST_TRIPLET}-strip "$INSTALL_DIR/bin/SDL2.dll"
1 change: 0 additions & 1 deletion app/prebuilt-deps/.gitignore

This file was deleted.

22 changes: 0 additions & 22 deletions app/prebuilt-deps/common

This file was deleted.

32 changes: 0 additions & 32 deletions app/prebuilt-deps/prepare-adb.sh

This file was deleted.

Loading

0 comments on commit 3f349c7

Please sign in to comment.