Automated prebuilds of native modules
Using prebuild and prebuild-ci (with travis-ci and appveyor) you can automate the building of native dependencies for almost all platforms!
prebuild
creates .tar.gz
bundles for each platform and uploads them to github. You can then add prebuild-install to your npm install
and it will try to download the prebuilds from github before fallback to actually building locally.
I've recently been experimenting creating a fork of electron-spellchecker that builds prebuilds this so that I will be able to build patchwork for all platforms from my one machine!
Thought I'd share my process for anyone else that wants to give this a go!
Adding prebuild-ci to your project
In the module that you want to add automated prebuilds:
npm install prebuild --save-dev
npm install prebuild-ci --save-dev
npm install prebuild-install --save
Then add prebuild-ci
to test
and prebuild-install
to install
under scripts in package.json
(and for local prebuilds you can add the prebuild script)
{
"scripts": {
"test": "tape && prebuild-ci",
"install": "prebuild-install || node-gyp rebuild",
"prebuild": "prebuild --all --strip --verbose"
}
}
Add .travis.yml
and appveyor.yml
files:
# .travis.yml
sudo: false
language: node_js
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-4.8; fi
- export JOBS=max
os:
- osx
- linux
node_js:
- "8"
# appveyor.yml
version: "{build}"
build: off
skip_tags: true
environment:
matrix:
- nodejs_version: "8"
platform:
- x86
- x64
install:
- ps: Install-Product node $env:nodejs_version $env:platform
- ps: if ($env:nodejs_version -eq "5") { npm i npm@latest -g }
- set PATH=%APPDATA%\npm;%APPVEYOR_BUILD_FOLDER%\node_modules\.bin;%PATH%
- npm i
test_script:
- npm test
Setup the travis build env (for mac and linux builds)
Add the github repo to travis on your profile: https://travis-ci.org/profile
Generate a token for uploading the prebuilds to github: https://github.com/settings/tokens/new (try adding repodeployment, repo:status, public_repo) _not sure if all these are needed, but it worked with just those selected
Then edit the settings on that repo in travis CI and then add the generated github token as an encrypted environment variable PREBUILD_TOKEN
.
You can probably turn off "Build branch updates" and "Build pull request updates".
Setup appveyor build env (for windows builds)
Add the repo as a "Project" using "New Project" on https://ci.appveyor.com/projects
Go into the project settings and add the same PREBUILD_TOKEN
as above (make sure you select the padlock to encrypt!)
Now whenever you push a new version, prebuilds will magically be added!
You should probably wait for the prebuilds to finish uploading before running npm publish
just to make sure people get the automated builds.