Skip to content

Commit

Permalink
Fix Linux .so rpath
Browse files Browse the repository at this point in the history
 - Add lzo dependency
 - Publish source for the built libs
 - Add warning for missing nasm in tauri.mjs
 - Remove ffmpeg install from setup.sh
 - Add download logic for our linux ffmpeg bundle in preprep.mjs
  • Loading branch information
HeavenVolkoff committed Nov 1, 2023
1 parent c2f39de commit 097641d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 78 deletions.
2 changes: 0 additions & 2 deletions .cargo/config.toml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
{{#protoc}}
PROTOC = { force = true, value = "{{{protoc}}}" }
{{/protoc}}
{{^isLinux}}
FFMPEG_DIR = { force = true, value = "{{{nativeDeps}}}" }
{{/isLinux}}
OPENSSL_STATIC = { force = true, value = "1" }
OPENSSL_NO_VENDOR = { force = true, value = "0" }
OPENSSL_RUST_USE_NASM = { force = true, value = "1" }
Expand Down
19 changes: 19 additions & 0 deletions .github/scripts/ffmpeg/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ARG TARGET="x86_64-linux-gnu"
ARG ZIG_VERSION="0.11.0"
ARG MESON_VERSION="1.2.3"
ARG CMAKE_VERSION="3.27.0"
ARG PATCHELF_VERSION="0.18.0"

#--

Expand Down Expand Up @@ -87,6 +88,11 @@ RUN cd /srv/meson `
&& packaging/create_zipapp.py --outfile "${SYSROOT}/bin/meson" --compress `
&& rm -rf /srv/meson

# Download and install patchelf, used to do some light rpath ELF manipulation
ARG PATCHELF_VERSION
RUN --mount=type=cache,target=/root/.cache `
curl_tar "https://github.com/NixOS/patchelf/releases/download/${PATCHELF_VERSION:?}/patchelf-${PATCHELF_VERSION:?}-$(uname -m).tar.gz" "$SYSROOT" 1

# Download and install gas-preprocessor, used by our zig wrapper to handle GNU flavored assembly files
ADD --chmod=0750 'https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl' "${SYSROOT}/bin/gas-preprocessor.pl"

Expand Down Expand Up @@ -208,6 +214,12 @@ RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=scripts/20-bzip2.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-10 AS layer-20-lzo

RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=scripts/20-lzo.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-10 AS layer-20-zlib

RUN --mount=type=cache,target=/root/.cache `
Expand All @@ -218,6 +230,7 @@ FROM layer-10 AS layer-20

COPY --from=layer-20-brotli "${PREFIX}/." $PREFIX
COPY --from=layer-20-bzip2 "${PREFIX}/." $PREFIX
COPY --from=layer-20-lzo "${PREFIX}/." $PREFIX
COPY --from=layer-20-zlib "${PREFIX}/." $PREFIX

#--
Expand Down Expand Up @@ -442,6 +455,12 @@ RUN { cd "${OUT}/bin" || exit 0; } `

RUN find "$OUT" -type d -delete || true

RUN cd "${OUT}/srv" && env XZ_OPT='-T0 -7' bsdtar -cJf ../srv.tar.xz *

RUN rm -rf "${OUT}/srv"

# Ensure all .so libs have the correct rpaths
RUN find "$OUT" -type f \( -name '*.so' -o -name '*.so.*' \) -exec patchelf --set-rpath '$ORIGIN' {} \;
# Strip debug symbols and ensure any .so, .dll, .dylib has the execution flag set
RUN find "$OUT" -type f \( -name '*.so' -o -name '*.so.*' -o -name '*.dll' -o -name '*.dylib' \) -exec `
sh -euxc 'llvm-strip-17 -S "$@" && chmod +x "$@"' sh {} +
Expand Down
3 changes: 2 additions & 1 deletion .github/scripts/ffmpeg/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -o allexport
. /etc/environment
set +o allexport

# COnfigure cross compiler environment variables
# Configure cross compiler environment variables
export CC="zig-cc"
export AR="zig ar"
export RC="rc"
Expand Down Expand Up @@ -37,6 +37,7 @@ case "$TARGET" in
# https://github.com/ziglang/zig/issues/17430#issuecomment-1752592338
export CFLAGS="${CFLAGS} -fno-stack-protector -fno-stack-check"
export LDFLAGS="${LDFLAGS} -fno-stack-protector -fno-stack-check"
;;
esac

export CXXFLAGS="$CFLAGS"
Expand Down
28 changes: 28 additions & 0 deletions .github/scripts/ffmpeg/scripts/20-lzo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env -S bash -euo pipefail

echo "Download lzo..."
mkdir -p lzo

curl_tar 'https://www.oberhumer.com/opensource/lzo/download/lzo-2.10.tar.gz' lzo 1

sed -i "/^if(0)/d" lzo/CMakeLists.txt
sed -i "/^add_test/d" lzo/CMakeLists.txt
sed -i "/^include(CTest)/d" lzo/CMakeLists.txt
sed -ie 's/^if(1)/if(0)/' lzo/CMakeLists.txt
sed -ie 's/^# main test driver/if(0)/' lzo/CMakeLists.txt

# Remove unused components
rm -r lzo/{B,util,tests,minilzo,lzotest,examples,autoconf,lzo2.pc.in,Makefile.am,Makefile.in,aclocal.m4,configure,config.hin}

# Backup source
bak_src 'lzo'

mkdir -p lzo/build
cd lzo/build

echo "Build lzo..."
cmake ..

ninja -j"$(nproc)"

ninja install
10 changes: 9 additions & 1 deletion .github/workflows/ffmpeg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ jobs:
run: |
set -euxo pipefail
cd .github/scripts/ffmpeg
docker build --no-cache --build-arg TARGET=${{ matrix.settings.target }} -o . .
docker build --no-cache --jobs 2 --build-arg TARGET=${{ matrix.settings.target }} -o . .
mv out/srv.tar.xz ./
- name: Publish ffmpeg
uses: actions/upload-artifact@v3
with:
name: ffmpeg-6.0-${{ matrix.settings.target }}
path: .github/scripts/ffmpeg/out/*
if-no-files-found: error

- name: Publish built source
uses: actions/upload-artifact@v3
with:
name: ffmpeg-6.0-${{ matrix.settings.target }}-source
path: .github/scripts/ffmpeg/srv.tar.xz
if-no-files-found: warn
6 changes: 1 addition & 5 deletions scripts/preprep.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url'

import * as _mustache from 'mustache'

import { downloadFFMpeg, downloadLibHeif, downloadPDFium, downloadProtc } from './utils/deps.mjs'
import { downloadFFMpeg, downloadPDFium, downloadProtc } from './utils/deps.mjs'
import { getGitBranches } from './utils/git.mjs'
import { getMachineId } from './utils/machineId.mjs'
import {
Expand Down Expand Up @@ -86,10 +86,6 @@ await Promise.all([
console.error(`Failed to download ffmpeg. ${bugWarn}`)
throw e
}),
downloadLibHeif(machineId, nativeDeps, branches).catch(e => {
console.error(`Failed to download libheif. ${bugWarn}`)
throw e
}),
]).catch(e => {
if (__debug) console.error(e)
exit(1)
Expand Down
14 changes: 0 additions & 14 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ case "$(uname)" in
set -- build-essential curl wget file patchelf openssl libssl-dev libgtk-3-dev librsvg2-dev \
libwebkit2gtk-4.0-dev libayatana-appindicator3-dev

# FFmpeg dependencies
set -- "$@" ffmpeg libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev \
libavutil-dev libswscale-dev libswresample-dev

# Webkit2gtk requires gstreamer plugins for video playback to work
set -- "$@" gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-libav \
gstreamer1.0-pipewire gstreamer1.0-plugins-bad gstreamer1.0-plugins-base \
Expand All @@ -157,9 +153,6 @@ case "$(uname)" in
# Tauri dependencies
set -- base-devel curl wget file patchelf openssl gtk3 librsvg webkit2gtk libayatana-appindicator

# FFmpeg dependencies
set -- "$@" ffmpeg

# Webkit2gtk requires gstreamer plugins for video playback to work
set -- "$@" gst-libav gst-plugins-bad gst-plugins-base gst-plugins-good gst-plugins-ugly \
gst-plugin-pipewire gstreamer-vaapi
Expand Down Expand Up @@ -203,13 +196,6 @@ case "$(uname)" in
set -- "$@" clang clang-devel nasm

sudo dnf install "$@"

# FFmpeg dependencies
if ! sudo dnf install ffmpeg ffmpeg-devel; 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
else
if has lsb_release; then
_distro="'$(lsb_release -s -d)' "
Expand Down
5 changes: 4 additions & 1 deletion scripts/tauri.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ try {
)

console.warn(
`If you got an error related to FFMpeg or Protoc/Protobuf you may need to re-run \`pnpm prep\``
`If you got an error related to libav*/FFMpeg or Protoc/Protobuf you may need to re-run \`pnpm prep\``,
`If you got an error related to missing nasm you need to run ${
platform === 'win32' ? './scripts/setup.ps1' : './scripts/setup.sh'
}`
)

throw error
Expand Down
25 changes: 7 additions & 18 deletions scripts/utils/consts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,24 @@ export const PDFIUM_SUFFIX = {
}

export const FFMPEG_SUFFFIX = {
Linux: {
x86_64: 'x86_64',
aarch64: 'aarch64',
},
Darwin: {
x86_64: 'x86_64',
aarch64: 'arm64',
},
Windows_NT: {
x86_64: 'x86_64',
aarch64: 'aarch64',
},
}

export const FFMPEG_WORKFLOW = {
Linux: 'ffmpeg.yml',
Darwin: 'ffmpeg-macos.yml',
Windows_NT: 'ffmpeg-windows.yml',
}

export const LIBHEIF_SUFFIX = {
Linux: {
x86_64: {
musl: 'x86_64-linux-musl',
glibc: 'x86_64-linux-gnu',
},
aarch64: {
musl: 'aarch64-linux-musl',
glibc: 'aarch64-linux-gnu',
},
},
}

export const LIBHEIF_WORKFLOW = {
Linux: 'libheif-linux.yml',
Windows_NT: 'ffmpeg.yml',
}

/**
Expand Down
36 changes: 0 additions & 36 deletions scripts/utils/deps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,39 +160,3 @@ export async function downloadFFMpeg(machineId, nativeDeps, branches) {

if (!found) throw new Error('NO_FFMPEG')
}

/**
* Download and extract libheif libs for heif thumbnails
* @param {string[]} machineId
* @param {string} nativeDeps
* @param {string[]} branches
*/
export async function downloadLibHeif(machineId, nativeDeps, branches) {
const workflow = getConst(LIBHEIF_WORKFLOW, machineId)
if (workflow == null) return

console.log('Downloading LibHeif...')

const libHeifSuffix = getSuffix(LIBHEIF_SUFFIX, machineId)
if (libHeifSuffix == null) throw new Error('NO_LIBHEIF')

let found = false
for await (const artifact of getGhWorkflowRunArtifacts(SPACEDRIVE_REPO, workflow, branches)) {
if (!libHeifSuffix.test(artifact.name)) continue
try {
const data = await getGhArtifactContent(SPACEDRIVE_REPO, artifact.id)
await extractTo(data, nativeDeps, {
chmod: 0o600,
recursive: true,
overwrite: true,
})
found = true
break
} catch (error) {
console.warn('Failed to download LibHeif, re-trying...')
if (__debug) console.error(error)
}
}

if (!found) throw new Error('NO_LIBHEIF')
}

0 comments on commit 097641d

Please sign in to comment.