Skip to content

Instantly share code, notes, and snippets.

@DUOLabs333
Last active July 14, 2023 09:53
Show Gist options
  • Save DUOLabs333/c68e5e4e726855b3baa3d6747f39a504 to your computer and use it in GitHub Desktop.
Save DUOLabs333/c68e5e4e726855b3baa3d6747f39a504 to your computer and use it in GitHub Desktop.
Building `filestash` for ARM64

Building libresize and libtranscode: This must be done on a Debian stretch system or chroot. First, clone https://github.com/mickael-kerjean/filestash. cd filestash/server/plugin/plg_image_light/deps/ Copy ./create_libresize.sh from this gist over and run it Copy ./create_libtranscode.sh from this gist over and run it cd back into the root of filestash and run

mkdir -p ./dist/data/state/config
cp config/config.json ./dist/data/state/config/
mkdir -p ./filestash/data/state/config
cp config/config.json ./filestash/data/state/config/

Backend:

Run make build_init
cd filestash/server/plugin/plg_image_light
Open lib_resize.go and add // #cgo LDFLAGS: -lm -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -ldl -L./deps -l:libresize.a at the top
Open lib_transcode.go and add // #cgo LDFLAGS: -lm -lpthread -L./deps -l:libtranscode.a at top
(If you want, edit server/plugin/plg_starter_http/index.go and change go ensureAppHasBooted(fmt.Sprintf(":%d/about", port), fmt.Sprintf("[http] listening on :%d", port)) to go ensureAppHasBooted(fmt.Sprintf("http://127.0.0.1:%d/about", port), fmt.Sprintf("[http] listening on 127.0.0.1:%d", port)) if you only want it to listen on localhost)
Run make build_backend
Run cp dist/filestash filestash/

Frontend:

Install npm < 7 (on Arch, you can use npm6)
npm install
make build_frontend
cp -R ./dist/data/public ./filestash/data/public

Run:

Go to filestash in the root, and run ./filestash

#!/bin/sh
# # This script handle the creation of the static library used by the plugin to
# # perform image resizing jobs. You can run it like this:
# docker run -ti --name debian_build_dep -v /home/:/home/ debian:9 bash
# apt-get -y update && apt-get -y install git
# git clone https://github.com/mickael-kerjean/filestash
# cd filestash/server/plugin/plg_image_light/deps/
# ./create_libresize.sh
set -e
arch=$(dpkg --print-architecture)
################################################
# Tooling
apt install -y --allow-unauthenticated curl make gcc g++ xz-utils pkg-config python3-pip autoconf libtool unzip python-setuptools cmake git
#pip3 install --user meson ninja
export PATH=~/.local/bin:$PATH
################################################
# Stage 1: Get libvips and its dependencies + recompile for less headaches
INITIAL_PATH=`pwd`
mkdir -p /tmp/filestash/libresize/tmp
cd /tmp/filestash/libresize
apt install -y --allow-unauthenticated libvips-dev
cd tmp
curl -L -X GET https://github.com/libvips/libvips/releases/download/v8.7.0/vips-8.7.0.tar.gz > libvips.tar.gz
tar -zxf libvips.tar.gz
cd vips-8.7.0/
./configure --enable-static --without-magick --without-lcms --without-OpenEXR --without-nifti --without-pdfium --without-rsvg --without-matio --without-libwebp --without-cfitsio --without-zlib --without-poppler --without-pangoft2 --enable-introspection=no --without-openslide
make -j 8
make install
cd $INITIAL_PATH
################################################
# Stage 2: Create our own library as a static build
gcc -Wall -c src/libresize.c `pkg-config --cflags glib-2.0`
ar rcs libresize.a libresize.o
################################################
# Stage 3: Gather and assemble all the bits and pieces together
libpath='aarch64-linux-gnu'
#ar x /tmp/libresize.a
ar x /usr/local/lib/libvips.a
ar x /usr/lib/$libpath/libz.a
ar x /usr/lib/$libpath/libbz2.a
ar x /usr/lib/$libpath/libjpeg.a
ar x /usr/lib/$libpath/libgif.a
ar x /usr/lib/$libpath/libdl.a
ar x /usr/lib/$libpath/libicui18n.a
ar x /usr/lib/$libpath/libgsf-1.a
ar x /usr/lib/$libpath/libicuuc.a
ar x /usr/lib/$libpath/libicudata.a
ar x /usr/lib/$libpath/liblzma.a
ar x /usr/lib/$libpath/libfreetype.a
ar x /usr/lib/$libpath/libfftw3.a
ar x /usr/lib/$libpath/libfontconfig.a
ar x /usr/lib/$libpath/libXext.a
ar x /usr/lib/$libpath/libSM.a
ar x /usr/lib/$libpath/libX11.a
ar x /usr/lib/$libpath/liborc-0.4.a
ar x /usr/lib/$libpath/libltdl.a
ar x /usr/lib/$libpath/librt.a
ar x /usr/lib/$libpath/libharfbuzz.a
ar x /usr/lib/$libpath/libexpat.a
ar x /usr/lib/$libpath/libgio-2.0.a
ar x /usr/lib/$libpath/libpng16.a
ar x /usr/lib/$libpath/libpixman-1.a
ar x /usr/lib/$libpath/libxcb.a
ar x /usr/lib/$libpath/libjbig.a
ar x /usr/lib/$libpath/libexif.a
ar x /usr/lib/$libpath/libpcre.a
ar x /usr/lib/$libpath/libtiff.a
ar x /usr/lib/$libpath/libpangoft2-1.0.a
ar x /usr/lib/$libpath/libpoppler.a
ar rcs libresize.a *.o
rm *.o *.ao
#scp libresize.a mickael@hal.kerjean.me:/home/app/pages/data/projects/filestash/downloads/upload/libresize_`uname -s`-`uname -m`.a
################################################
# Stage 4: Gather all the related headers
#cd /usr/include/
#tar zcf /tmp/libresize-headers.tar.gz .
#scp /tmp/libresize-headers.tar.gz mickael@hal.kerjean.me:/home/app/pages/data/projects/filestash/downloads/upload/libresize_`uname -s`-`uname -m`_headers.tar.gz
#!/bin/sh
# # This script handle the creation of the static library used by the plugin to
# # perform transcoding jobs. You can run it like this:
# docker run -ti --name debian_build_dep -v /home/:/home/ debian:9 bash
# apt-get -y update && apt-get -y install git
# git clone https://github.com/mickael-kerjean/filestash
# cd filestash/server/plugin/plg_image_light/deps/
# ./create_libtranscode.sh
set -e
arch=$(dpkg --print-architecture)
################################################
# Tooling
apt install -y --allow-unauthenticated curl make gcc g++ xz-utils pkg-config python3-pip autoconf libtool unzip python-setuptools cmake git
export PATH=~/.local/bin:$PATH
################################################
# Stage 1: Get libraw and its dependencies
INITIAL_PATH=`pwd`
apt install -y --allow-unauthenticated libraw-dev
cd /tmp/
# libgomp and libstdc++
apt-get install --allow-unauthenticated -y libgcc-6-dev
# libjpeg
apt-get install --allow-unauthenticated -y libjpeg-dev
# liblcms2
curl -L -O -k https://downloads.sourceforge.net/project/lcms/lcms/2.9/lcms2-2.9.tar.gz
tar zxf lcms2-2.9.tar.gz
cd lcms2-2.9
./configure --enable-static --without-zlib --without-threads
make -j 8
make install
cd $INITIAL_PATH
################################################
# Stage 2: Create our own library as a static build
gcc -Wall -c src/libtranscode.c
################################################
# Stage 3: Gather and assemble all the bits and pieces together
libpath='aarch64-linux-gnu'
ar x /usr/lib/$libpath/libraw.a
ar x /usr/lib/$libpath/libjpeg.a
ar x /usr/local/lib/liblcms2.a
ar x /usr/lib/gcc/$libpath/6/libstdc++.a
ar x /usr/lib/gcc/$libpath/6/libgomp.a
ar x /usr/lib/$libpath/libpthread.a
ar rcs libtranscode.a *.o
rm *.o
#scp libtranscode.a mickael@hal.kerjean.me:/home/app/pages/data/projects/filestash/downloads/upload/libtranscode_`uname -s`-`uname -m`.a
################################################
# Stage 4: Gather all the related headers
#cd /usr/include/
#tar zcf /tmp/libtranscode-headers.tar.gz .
#scp /tmp/libtranscode-headers.tar.gz mickael@hal.kerjean.me:/home/app/pages/data/projects/filestash/downloads/upload/libtranscode_`uname -s`-`uname -m`_headers.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment