Skip to content

Commit

Permalink
feat(prebuild): support of Alpine binaries
Browse files Browse the repository at this point in the history
- update dependencies
- rework binding.gyp
- rework msys bundle for Windows
- add bundle for MUSL (Alpine)
- rework bundle scripts and ci

moved to prebuild
  • Loading branch information
Delagen committed Mar 28, 2024
1 parent 379b7a1 commit d68fb7a
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 543 deletions.
416 changes: 185 additions & 231 deletions .github/workflows/prebuild.yaml

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
build
.DS_Store
.lock-wscript
test/images/*.png
examples/*.png
examples/*.jpg
testing
out.png
out.pdf
out.svg
.pomo

node_modules
package-lock.json

Expand Down
3 changes: 3 additions & 0 deletions prebuild/Alpine/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

apk --no-cache add build-base cairo-dev jpeg-dev pango-dev giflib-dev librsvg-dev pixman-dev patchelf lddtree
3 changes: 3 additions & 0 deletions prebuild/Alpine/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

apk --purge del build-base cairo* jpeg* pango* giflib* librsvg* pixman*
9 changes: 9 additions & 0 deletions prebuild/Debian/bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh

TARGET=./source/build/Release

for lib in $(lddtree -l ${TARGET}/canvas.node|sed -r -e '/canvas.node$/d'); do
echo "Copy ${lib}"
cp -L "${lib}" "${TARGET}"
patchelf --force-rpath --set-rpath '$ORIGIN' "${TARGET}/$(basename -- "${lib}")"
done
4 changes: 4 additions & 0 deletions prebuild/Debian/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

apt-get update
apt-get install -y build-essential libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev librsvg2-dev libpixman-1-dev patchelf pax-utils
2 changes: 2 additions & 0 deletions prebuild/Debian/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apt-get purge -y build-essential libcairo2* libjpeg* libpango1.0* libgif* librsvg2* libpixman-1*
#apt-get autoremove --purge -y
43 changes: 0 additions & 43 deletions prebuild/Linux/Dockerfile

This file was deleted.

55 changes: 0 additions & 55 deletions prebuild/Linux/binding.gyp

This file was deleted.

11 changes: 0 additions & 11 deletions prebuild/Linux/bundle.sh

This file was deleted.

10 changes: 0 additions & 10 deletions prebuild/Linux/preinstall.sh

This file was deleted.

84 changes: 0 additions & 84 deletions prebuild/Windows/binding.gyp

This file was deleted.

57 changes: 57 additions & 0 deletions prebuild/Windows/bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env sh

LIBS=()

WINDIR=$(cygpath -u -W)

shopt -s nocasematch
function addToLibs() {
local TARGET=${1} && shift
if [[ "$(which "${TARGET}")" == "${WINDIR}"* ]]; then
:
else
for lib in ${LIBS[@]}; do
if [[ "${lib}" == "${TARGET}" ]]; then
return
fi
done
echo $TARGET
fi
}

RECURSE_INDEX=0

function getLibsForBinary() {
local TARGET=$1 && shift

local -i count=0
for binLib in $(objdump -p "$(cygpath -u "${TARGET}")" | grep "DLL Name:"| sed -e 's/^\s*DLL\sName:\s*//'); do
if [[ ! -z "$(addToLibs ${binLib})" ]]; then
echo "added ${binLib}"
count=$count+1
LIBS+=("${binLib}")
fi
done

if [[ count -gt 0 ]]; then
local CURRENT_INDEX=${RECURSE_INDEX}
RECURSE_INDEX=${#LIBS[@]}
# recurse if any added from last checked
echo "recurse check after ${count} added"
for lib in ${LIBS[@]:${CURRENT_INDEX}}; do
getLibsForBinary "$(which "${lib}")"
done
fi
}

function copyLibs() {
local TARGET=$1 && shift
local TARGET_PATH=$(cygpath -u "${TARGET}")
for lib in ${LIBS[@]}; do
echo "copy ${lib} to destination"
cp "$(which "${lib}")" "${TARGET_PATH}"
done
}

getLibsForBinary "./source/build/Release/canvas.node"
copyLibs "./source/build/Release"
38 changes: 20 additions & 18 deletions prebuild/Windows/preinstall.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
#!/usr/bin/env sh
# expects node, VS, and MSYS environments to be set up already. does everything else.

deps="cairo-2 png16-16 jpeg-8 pango-1.0-0 pangocairo-1.0-0 gobject-2.0-0 glib-2.0-0 turbojpeg gif-7 freetype-6 rsvg-2-2 gsf-1-114";
deps="cairo-2 png16-16 jpeg-8 pango-1.0-0 pangocairo-1.0-0 gobject-2.0-0 glib-2.0-0 turbojpeg gif-7 freetype-6 rsvg-2-2";

# install cairo and tools to create .lib

pacman --noconfirm -S \
wget \
unzip \
ucrt64/mingw-w64-ucrt-x86_64-binutils \
ucrt64/mingw-w64-ucrt-x86_64-tools \
ucrt64/mingw-w64-ucrt-x86_64-libjpeg-turbo \
ucrt64/mingw-w64-ucrt-x86_64-pango \
ucrt64/mingw-w64-ucrt-x86_64-cairo \
ucrt64/mingw-w64-ucrt-x86_64-giflib \
ucrt64/mingw-w64-ucrt-x86_64-freetype \
ucrt64/mingw-w64-ucrt-x86_64-fontconfig \
ucrt64/mingw-w64-ucrt-x86_64-librsvg \
ucrt64/mingw-w64-ucrt-x86_64-libxml2 \
ucrt64/mingw-w64-ucrt-x86_64-libgsf
prefix=${MSYSTEM,,}
arch=${MSYSTEM_CARCH}

pacman --noconfirm --needed -S \
${prefix}/mingw-w64-ucrt-${arch}-binutils \
${prefix}/mingw-w64-ucrt-${arch}-tools \
${prefix}/mingw-w64-ucrt-${arch}-libjpeg-turbo \
${prefix}/mingw-w64-ucrt-${arch}-pango \
${prefix}/mingw-w64-ucrt-${arch}-cairo \
${prefix}/mingw-w64-ucrt-${arch}-giflib \
${prefix}/mingw-w64-ucrt-${arch}-harfbuzz \
${prefix}/mingw-w64-ucrt-${arch}-freetype \
${prefix}/mingw-w64-ucrt-${arch}-fontconfig \
${prefix}/mingw-w64-ucrt-${arch}-librsvg \
${prefix}/mingw-w64-ucrt-${arch}-libxml2

# create .lib files for vc++

echo "generating lib files for the MSYS2 UCRT64 dlls"
echo "generating lib files for the MSYS2 dlls"
for lib in $deps; do
gendef /ucrt64/bin/lib$lib.dll > /dev/null 2>&1 || {
gendef /${prefix}/bin/lib$lib.dll > /dev/null 2>&1 || {
echo "could not find lib$lib.dll, have to skip ";
continue;
}

dlltool -d lib$lib.def -l /ucrt64/lib/lib$lib.lib > /dev/null 2>&1 || {
dlltool -d lib$lib.def -l /${prefix}/lib/lib$lib.lib > /dev/null 2>&1 || {
echo "could not create dll for lib$lib.dll";
continue;
}
Expand Down

0 comments on commit d68fb7a

Please sign in to comment.