Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Create prebuilt binaries using prebuild #47

Closed
wants to merge 7 commits into from

Conversation

Abrahamic-God
Copy link

@Abrahamic-God Abrahamic-God commented Nov 11, 2017

Closes #40.

This PR should provide almost everything needed to immediately start getting pre-built binaries automatically created and uploaded to GitHub for the following platforms:

  • Windows x86
  • Windows x64
  • Linux x86
  • Linux x64
  • macOS x64

Before merging, you'll want to set up this project on both AppVeyor and TravisCI. This should be just a few mouse clicks, all you're doing is telling these services that yes, you would like to build this project. You don't need to do any configuration at this time.

Once that's done, you'll need to replace my encrypted GitHub token (the prebuild_upload environment variable) with your own:

  1. Follow the steps outlined in the prebuild docs for creating a GitHub token with the appropriate scope permissions.

  2. Use the AppVeyor "Encrypt Data" page to encrypt your token. Then, paste it over my encrypted token in line 4 of appveyor.yml.

  3. Install the TravisCI CLI.

  4. From your local node-usb-detection directory, run the following command to get your encrypted prebuild_upload env var with your token:

    travis encrypt prebuild_upload=YOUR_GITHUB_TOKEN_HERE
  5. Copy the resulting output and paste it over mine in line 22 of .travis.yml.

  6. Commit/push your changes, then merge this PR! 馃帀 If I've done everything right, tagged commits will trigger a build, and automatically publish their artifacts to the GitHub release. The release will also be created if it does not already exist.

Caveats:

  • Travis' OSX build infrastructure is pretty overwhelmed at this point. On bad days it can take upwards of 5 hours for an OSX build to start. At night it settles down and you can usually get your build started immediately. You can look at the graphs on https://www.traviscistatus.com/ to get a feel for the patterns of when their infrastructure is completely slammed.

Credits:

  • I used pretty much all of the CI configs from node-serialport as a base. I made very few modifications to them.

@Abrahamic-God
Copy link
Author

Abrahamic-God commented Nov 11, 2017

Oh, this also includes a pretty comprehensive testing matrix for once we actually have tests that are okay for CI. In the meantime, this matrix just ensures that everything at least compiles on all the various platforms, architectures, and a few versions of Node.

@lovell
Copy link

lovell commented Nov 11, 2017

@lange You should be able to simplify the Travis CI config by by switching to an Ubuntu 14.04 image and removing the manual g++-4.8 boilerplate - see https://docs.travis-ci.com/user/reference/trusty/

@Abrahamic-God
Copy link
Author

@lovell Good call! I've gone ahead and made that simplification. I'm not very knowledgable on C/C++ in general, but I think I did the correct thing by leaving the g++-4.8-multilib and gcc-multilib packages in the apt config?

@Abrahamic-God
Copy link
Author

I was able to further simplify the build config and get away with installing fewer apt packages. The build times are now wicked fast on Linux:

image

MadLittleMods pushed a commit that referenced this pull request Nov 11, 2017
@MadLittleMods
Copy link
Owner

MadLittleMods commented Nov 11, 2017

Thanks for the contribution @lange 鉂わ笍

Merged via b49c568 馃殌

First set of built binaries on a tagged release here, https://github.com/MadLittleMods/node-usb-detection/releases/tag/v1.4.1 馃槑


We should add some documentation to the README around our new binary builds and how to use them. Is there a popular pattern for downloading, requiring and using prebuilt binaries? (best way to skip native addon compilation for that particular dependency and download/unzip the binary in the right place instead)

@Abrahamic-God
Copy link
Author

Abrahamic-God commented Nov 12, 2017

@MadLittleMods All the installation is handled automatically by prebuild-install, which is already set up in the npm scripts. No further user action should be necessary if I've set everything up correctly.

@MadLittleMods
Copy link
Owner

@lange 馃槷 Fancy!

I'm noticing that the install just hangs after it prints the Successfully installed prebuilt binary! message. Are things installing correctly for you?

$ npm install usb-detection --save

> usb-detection@1.4.1 install C:\Users\MLM\Downloads\usb-detection-install-test3\node_modules\usb-detection
> prebuild-install || node-gyp rebuild

prebuild-install info begin Prebuild-install version 2.3.0
prebuild-install info looking for local prebuild @ prebuilds\usb-detection-v1.4.1-node-v48-win32-x64.tar.gz
prebuild-install info looking for cached prebuild @ C:\Users\MLM\AppData\Roaming\npm-cache\_prebuilds\https-github.com-MadLittleMods-node-usb-detection-releases-download-v1.4.1-usb-detection-v1.4.1-node-v48-win32-x64.tar.gz
prebuild-install http request GET https://github.com/MadLittleMods/node-usb-detection/releases/download/v1.4.1/usb-detection-v1.4.1-node-v48-win32-x64.tar.gz
prebuild-install http 200 https://github.com/MadLittleMods/node-usb-detection/releases/download/v1.4.1/usb-detection-v1.4.1-node-v48-win32-x64.tar.gz
prebuild-install info downloading to @ C:\Users\MLM\AppData\Roaming\npm-cache\_prebuilds\https-github.com-MadLittleMods-node-usb-detection-releases-download-v1.4.1-usb-detection-v1.4.1-node-v48-win32-x64.tar.gz.20984-0d339e9b36bc3.tmp
prebuild-install info renaming to @ C:\Users\MLM\AppData\Roaming\npm-cache\_prebuilds\https-github.com-MadLittleMods-node-usb-detection-releases-download-v1.4.1-usb-detection-v1.4.1-node-v48-win32-x64.tar.gz
prebuild-install info unpacking @ C:\Users\MLM\AppData\Roaming\npm-cache\_prebuilds\https-github.com-MadLittleMods-node-usb-detection-releases-download-v1.4.1-usb-detection-v1.4.1-node-v48-win32-x64.tar.gz
prebuild-install info unpack resolved to C:\Users\MLM\Downloads\usb-detection-install-test3\node_modules\usb-detection\build\Release\detection.node
prebuild-install info unpack required C:\Users\MLM\Downloads\usb-detection-install-test3\node_modules\usb-detection\build\Release\detection.node successfully
prebuild-install info install Successfully installed prebuilt binary!

@Abrahamic-God
Copy link
Author

@MadLittleMods Oh, you're right. That can't be good. At this time I'm unsure what the cause of this could be

@Abrahamic-God
Copy link
Author

Abrahamic-God commented Nov 12, 2017

Got it, the problem is that this module doesn't let the node process exit by default, and prebuild-install does a test require of it to verify that it loads: prebuild/prebuild-install#45 (comment)

@MadLittleMods
Copy link
Owner

MadLittleMods commented Nov 12, 2017

@lange Ahh, nice catch! We would need to shove a usbDetect.stopMonitoring(); in there somehow but doesn't look very possible.

Because of the side-effects of the module currently when required, I think we should perhaps make a v2 with usbDetect.startMonitoring() added to the API. And make a new usb-detect@1.4.2 release without the prebuild-install. wdyt?

@Abrahamic-God
Copy link
Author

@MadLittleMods I agree, that seems like the fastest way forward and a reasonable approach.

@Abrahamic-God
Copy link
Author

Though actually we don't need to make a new 1.4.2, just delete the pre-build binaries from the github release and the existing 1.4.2 release will automatically fallback to building from source, same as usual.

@MadLittleMods
Copy link
Owner

MadLittleMods commented Nov 12, 2017

@lange and I chatted a bit more here, 鈽濓笍 November 11, 2017 11:25 PM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants