Skip to content

Commit

Permalink
prebuild with gha
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed Apr 26, 2020
1 parent 2e9ea73 commit 4780ec7
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 1 deletion.
161 changes: 161 additions & 0 deletions .github/workflows/prebuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Make Prebuilds
on: [push]
# TODO:
# on:
# release:
# types:
# - created

# When a new Node.js version is released, publish a new node-canvas release that
# adds that version to CI and the build? Could do on.push.branches: "master"
# with paths: ".github/workflows/prebuild.yaml", but how do we get the right
# $GITHUB_REF?

env:
CANVAS_VERSION_TO_BUILD: "2.6.1" # no "v" prefix. TODO switch to $GITHUB_REF if we switch to `on: release`
CANVAS_PREBUILT_VERSION: "0.0.1"

jobs:
Linux:
strategy:
matrix:
node: [10, 12, 14]
name: Node.js ${{ matrix.node }} on Linux
runs-on: ubuntu-latest
container:
image: chearon/canvas-prebuilt:7
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Build
env:
OS: ${{ runner.os }}
run: |
npm install -g node-gyp
npm install --ignore-scripts
. prebuild/$OS/preinstall.sh
cp prebuild/$OS/binding.gyp binding.gyp
node-gyp rebuild -j 2
. prebuild/$OS/bundle.sh
- name: Test binary
run: node -e "require('.')"

- name: Make bundle
id: make_bundle
run: |
ASSET_NAME=$(. prebuild/tarball.sh $CANVAS_PREBUILT_VERSION)
echo "::set-output name=asset_name::${ASSET_NAME}"
ls -l
- name: Upload
uses: actions/[email protected]
with:
script: |
const fs = require("fs");
const assetName = "${{ steps.make_bundle.outputs.asset_name }}";
const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`;
const releases = await github.repos.listReleases({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1]
});
const release = releases.data.find(r => r.tag_name === tagName);
for (const asset of release.assets) {
if (asset.name === assetName) {
await github.repos.deleteReleaseAsset({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
asset_id: asset.id
});
break;
}
}
// (This is equivalent to actions/upload-release-asset. We're
// already in a script, so might as well do it here.)
const r = await github.repos.uploadReleaseAsset({
url: release.upload_url,
headers: {
"content-type": "application/x-gzip",
"content-length": `${fs.statSync(assetName).size}`
},
name: assetName,
data: fs.readFileSync(assetName)
});
macOS:
strategy:
matrix:
node: [10, 12, 14]
name: Node.js ${{ matrix.node }} on macOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Build
env:
OS: ${{ runner.os }}
run: |
npm install -g node-gyp
npm install --ignore-scripts
. prebuild/$OS/preinstall.sh
cp prebuild/$OS/binding.gyp binding.gyp
node-gyp rebuild -j 2
. prebuild/$OS/bundle.sh
- name: Test binary
run: node -e "require('.')"

- name: Make bundle
id: make_bundle
run: |
ASSET_NAME=$(. prebuild/tarball.sh $CANVAS_PREBUILT_VERSION)
echo "::set-output name=asset_name::${ASSET_NAME}"
ls -l
- name: Upload
uses: actions/[email protected]
with:
script: |
const fs = require("fs");
const assetName = "${{ steps.make_bundle.outputs.asset_name }}";
const tagName = `v${process.env.CANVAS_PREBUILT_VERSION}`;
const releases = await github.repos.listReleases({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1]
});
const release = releases.data.find(r => r.tag_name === tagName);
for (const asset of release.assets) {
if (asset.name === assetName) {
await github.repos.deleteReleaseAsset({
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
asset_id: asset.id
});
break;
}
}
// (This is equivalent to actions/upload-release-asset. We're
// already in a script, so might as well do it here.)
const r = await github.repos.uploadReleaseAsset({
url: release.upload_url,
headers: {
"content-type": "application/x-gzip",
"content-length": `${fs.statSync(assetName).size}`
},
name: assetName,
data: fs.readFileSync(assetName)
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"binary": {
"module_name": "canvas",
"module_path": "build/Release",
"host": "https://github.com/node-gfx/node-canvas-prebuilt/releases/download/",
"host": "https://github.com/Automattic/node-canvas/releases/download/",
"remote_path": "v{version}",
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{libc}-{arch}.tar.gz"
},
Expand Down
53 changes: 53 additions & 0 deletions prebuild/Linux/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
'targets': [
{
'target_name': 'canvas',
'sources': [
'src/backend/Backend.cc',
'src/backend/ImageBackend.cc',
'src/backend/PdfBackend.cc',
'src/backend/SvgBackend.cc',
'src/bmp/BMPParser.cc',
'src/Backends.cc',
'src/Canvas.cc',
'src/CanvasGradient.cc',
'src/CanvasPattern.cc',
'src/CanvasRenderingContext2d.cc',
'src/closure.cc',
'src/color.cc',
'src/Image.cc',
'src/ImageData.cc',
'src/init.cc',
'src/register_font.cc'
],
'defines': [
'HAVE_GIF',
'HAVE_JPEG',
'HAVE_RSVG'
],
'libraries': [
'<!@(pkg-config pixman-1 --libs)',
'<!@(pkg-config cairo --libs)',
'<!@(pkg-config libpng --libs)',
'<!@(pkg-config pangocairo --libs)',
'<!@(pkg-config freetype2 --libs)',
'<!@(pkg-config librsvg-2.0 --libs)',
'-ljpeg',
'-lgif'
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
'<!@(pkg-config cairo --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config libpng --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config pangocairo --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config freetype2 --cflags-only-I | sed s/-I//g)',
'<!@(pkg-config librsvg-2.0 --cflags-only-I | sed s/-I//g)'
],
'ldflags': [
'-Wl,-rpath \'-Wl,$$ORIGIN\''
],
'cflags!': ['-fno-exceptions'],
'cflags_cc!': ['-fno-exceptions']
}
]
}
5 changes: 5 additions & 0 deletions prebuild/Linux/bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
copies=$(lddtree.sh -l node-canvas/build/Release/canvas.node | sed -r -e '/^\/lib/d' -e '/canvas.node$/d');

for so in $copies; do
cp $so node-canvas/build/Release
done;
8 changes: 8 additions & 0 deletions prebuild/Linux/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# apt-get-style dependencies aren't done here since the
# linux build is done on a docker image that has them

git clone git://anongit.gentoo.org/proj/pax-utils.git
cd pax-utils
PATH=$PATH:$PWD
make
cd ..
79 changes: 79 additions & 0 deletions prebuild/Windows/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
'targets': [
{
'target_name': 'canvas',
'sources': [
'src/backend/Backend.cc',
'src/backend/ImageBackend.cc',
'src/backend/PdfBackend.cc',
'src/backend/SvgBackend.cc',
'src/bmp/BMPParser.cc',
'src/Backends.cc',
'src/Canvas.cc',
'src/CanvasGradient.cc',
'src/CanvasPattern.cc',
'src/CanvasRenderingContext2d.cc',
'src/closure.cc',
'src/color.cc',
'src/Image.cc',
'src/ImageData.cc',
'src/init.cc',
'src/register_font.cc'
],
'defines': [
'HAVE_GIF',
'HAVE_JPEG',
'HAVE_RSVG',
'HAVE_BOOLEAN', # or jmorecfg.h tries to define it
'_USE_MATH_DEFINES' # for M_PI
],
'libraries': [
'C:/msys64/mingw64/lib/libcairo-2.lib',
'C:/msys64/mingw64/lib/libpng16-16.lib',
'C:/msys64/mingw64/lib/libjpeg-8.lib',
'C:/msys64/mingw64/lib/libpango-1.0-0.lib',
'C:/msys64/mingw64/lib/libpangocairo-1.0-0.lib',
'C:/msys64/mingw64/lib/libgobject-2.0-0.lib',
'C:/msys64/mingw64/lib/libglib-2.0-0.lib',
'C:/msys64/mingw64/lib/libturbojpeg.lib',
'C:/msys64/mingw64/lib/libgif-7.lib',
'C:/msys64/mingw64/lib/libfreetype-6.lib',
'C:/msys64/mingw64/lib/librsvg-2-2.lib'
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
'C:/msys64/mingw64/include',
'C:/msys64/mingw64/include/pango-1.0',
'C:/msys64/mingw64/include/cairo',
'C:/msys64/mingw64/include/libpng16',
'C:/msys64/mingw64/include/glib-2.0',
'C:/msys64/mingw64/lib/glib-2.0/include',
'C:/msys64/mingw64/include/pixman-1',
'C:/msys64/mingw64/include/freetype2',
'C:/msys64/mingw64/include/fontconfig',
'C:/msys64/mingw64/include/librsvg-2.0',
'C:/msys64/mingw64/include/gdk-pixbuf-2.0'
],
'configurations': {
'Debug': {
'msvs_settings': {
'VCCLCompilerTool': {
'WarningLevel': 4,
'ExceptionHandling': 1,
'DisableSpecificWarnings': [4100, 4127, 4201, 4244, 4267, 4506, 4611, 4714, 4512]
}
}
},
'Release': {
'msvs_settings': {
'VCCLCompilerTool': {
'WarningLevel': 4,
'ExceptionHandling': 1,
'DisableSpecificWarnings': [4100, 4127, 4201, 4244, 4267, 4506, 4611, 4714, 4512]
}
}
}
}
}
]
}
19 changes: 19 additions & 0 deletions prebuild/Windows/bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# write recurisve dependencies of canvas.node into depends.csv
./depends -c -oc:depends.csv node-canvas/build/Release/canvas.node;

[ -f depends.csv ] || {
echo "error invoking depends.exe";
exit 1;
}

# case-insensitive intersection of 3rd column of depends.csv
# and all files ending in .dll in the mingw64 directory
copies=$(comm -12 \
<(cat depends.csv | cut -d ',' -f2 | sed 's/"//g' | tr '[:upper:]' '[:lower:]' | sort) \
<(find /mingw64/bin -name '*.dll' -printf "%f\n" | tr '[:upper:]' '[:lower:]' | sort) \
);

for dll in $copies; do
cp /mingw64/bin/$dll node-canvas/build/Release
done;

8 changes: 8 additions & 0 deletions prebuild/Windows/exec_with_msys.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@echo off

rem sets up MSYS environment and invokes the script argument in bash

set WD=C:\msys64\usr\bin\
set MSYSTEM=MINGW64
%WD%bash --login -c "cd $(cygpath '%cd%'); ""%~1"" ""%~2"" ""%~3"" ""%~4"" ""%~5"" ""%~6"" ""%~7"" ""%~8"" ""%~9"""

2 changes: 2 additions & 0 deletions prebuild/Windows/node_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VER=$1
powershell -Command "Install-Product node $VER x64"
44 changes: 44 additions & 0 deletions prebuild/Windows/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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";

# install cairo and tools to create .lib

pacman --noconfirm -S \
wget \
unzip \
mingw64/mingw-w64-x86_64-binutils \
mingw64/mingw-w64-x86_64-tools \
mingw64/mingw-w64-x86_64-libjpeg-turbo \
mingw64/mingw-w64-x86_64-pango \
mingw64/mingw-w64-x86_64-cairo \
mingw64/mingw-w64-x86_64-giflib \
mingw64/mingw-w64-x86_64-freetype \
mingw64/mingw-w64-x86_64-fontconfig \
mingw64/mingw-w64-x86_64-librsvg

# create .lib files for vc++

echo "generating lib files for the MSYS2 dlls"
for lib in $deps; do
gendef /mingw64/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 /mingw64/lib/lib$lib.lib > /dev/null 2>&1 || {
echo "could not create dll for lib$lib.dll";
continue;
}

echo "created lib$lib.lib from lib$lib.dll";

rm lib$lib.def
done

# dependency walker will help us figure out which DLLs
# canvas.node directly and indirectly uses

wget -nc http://www.dependencywalker.com/depends22_x64.zip
unzip -u depends22_x64.zip

Loading

0 comments on commit 4780ec7

Please sign in to comment.