How to npm install and compile on travis.ci for multiple environments (including 32 bit)

474 Views Asked by At

I have a project hosted on github that builds and publishes releases to GitHub using Travis.ci:

https://github.com/Roaders/rpi-garage-door/releases/tag/v1.1.0

currently this just adds one tgz file to the release. This includes the bundles dependencies needed to run (the thinking behind this is that npm install and npm run build are really slow on a raspberry pi so just unzipping a tar is a million times faster). As travis uses 64bit machines the resulting tar files can only be used on 64bit so as part of the upgrade process we need to run npm rebuild - which is still fairly slow on RPI 3.

Initially I would like to build a 32 bit version instead of a 64 bit version but I do not know how to configure this on travis. I think I need to change the npm config so I tried this in my .travis.yml:

language: node_js
node_js: 12
script: npm run build-release

before_install:
  npm set npm_config_arch ia32

but that doesn't work.

The second thing that I want to do is to build multiple versions of my project using different versions of node and then add all of those tgz files to the release.

this solution:

Cross-platform install of npm package sqlite3

is very close to what I want but does not work for me as the dependency I need to rebuild (epoll) does not build with node-pre-gyp

1

There are 1 best solutions below

0
On

It seems that the other referenced answer was almost there. The difference is that I have to use node-gyp to rebuild epoll. I also want to rename the generated tgz file to distinguish between the binaries. These scripts generate the required files for me:

"build-release": "npm run build",
"postbuild-release": "npm run build-node10-32 && npm run build-node12-32 && npm run build-node14-32",
"build-node10-32": "npx node-gyp rebuild -C node_modules/epoll/ --arch=arm --target=v10.21.0 && FILENAME=$(npm pack | tail -n 1) && mv $FILENAME \"node_10_32_$FILENAME\"",
"build-node12-32": "npx node-gyp rebuild -C node_modules/epoll/ --arch=arm --target=v12.18.2 && FILENAME=$(npm pack | tail -n 1) && mv $FILENAME \"node_12_32_$FILENAME\"",
"build-node14-32": "npx node-gyp rebuild -C node_modules/epoll/ --arch=arm --target=v14.5.0 && FILENAME=$(npm pack | tail -n 1) && mv $FILENAME \"node_14_32_$FILENAME\"",

Note: this doesn't actually solve my specific issue as this still generates 64bit binaries that do not work on my 32 bit raspberry pis. I think the advised fix for this is to use --arch=ia32 but this results in the error unrecognized command line option ‘-m32’; did you mean ‘-mbe32’? but I think fixing that is outside the scope of this question.