-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: rewrite as node cli using prebuild/docker-images (#7)
Usage and behavior changed. Best to treat this as a new module.
- Loading branch information
Showing
12 changed files
with
254 additions
and
389 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
/output/ | ||
/apt-cacher-ng/ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,74 @@ | ||
# prebuildify-cross | ||
|
||
cross-compile [prebuild](https://github.com/mafintosh/prebuildify)s | ||
**Compile prebuilds in Docker, supporting Linux (including Debian 8, Ubuntu 14.04, RHEL 7, CentOS 7 and up), Alpine Linux, ARM Linux devices like the Raspberry Pi and mobile ARM devices like Android.** | ||
|
||
## background | ||
Runs [`prebuildify`](https://github.com/mafintosh/prebuildify) in preconfigured [`prebuild/docker-images`](https://github.com/prebuild/docker-images) containers to compile and name prebuilds for a certain platform. This means you don't have to worry about GCC flags, environment variables or system dependencies. In addition, `prebuildify-cross` copies only npm package files to Docker (following the rules of `.npmignore` and `files`) and mounts `node_modules` removing the need for a repeated `npm install`. | ||
|
||
i want to build native modules for [Scuttlebutt](https://scuttlebutt.nz) pubs, to use on ARM Linux devices like the Raspberry Pi. meanwhile, i also want to support mobile ARM devices like Android. | ||
## Install | ||
|
||
## how does it work? | ||
|
||
`prebuildify-cross` will: | ||
|
||
- build a Docker image for your intended target, based on the respective [`dockcross`](https://github.com/dockcross/dockcross) image | ||
- create a Docker container with your input (default is `.`) mounted inside | ||
- run `npm install --ignore-scripts` and `npm run prebuild` | ||
- copy out `./prebuilds` from the container to your output (default is `./prebuilds`) | ||
|
||
## supported targets | ||
|
||
- `prebuildify-cross --platform=linux --arch=x32` | ||
- `prebuildify-cross --platform=linux --arch=x64` | ||
- `prebuildify-cross --platform=linux --arch=arm --arm-version=5` | ||
- `prebuildify-cross --platform=linux --arch=arm --arm-version=6` | ||
- `prebuildify-cross --platform=linux --arch=arm --arm-version=7` | ||
- `prebuildify-cross --platform=linux --arch=arm64` | ||
- `prebuildify-cross --platform=android --arch=arm --arm-version=7` | ||
- `prebuildify-cross --platform=android --arch=arm64` | ||
|
||
## usage | ||
|
||
(note: `prebuildify-cross` depends on having Docker installed.) | ||
|
||
in the module you want to cross-compile prebuilds, | ||
|
||
ensure you have an npm script `prebuild`, like: | ||
Depends on having Docker installed, as well as `prebuildify` and `node-gyp`: | ||
|
||
``` | ||
{ | ||
"scripts": { | ||
"prebuild": "prebuildify --all --strip" | ||
} | ||
} | ||
npm install --save-dev prebuildify node-gyp prebuildify-cross | ||
``` | ||
|
||
then install `prebuildify-cross` as a dev-dependency: | ||
## Usage | ||
|
||
The `prebuildify-cross` cli forwards all command line arguments to `prebuildify`, but adds an `--image` or `-i` argument. For example, the following command will invoke `prebuildify -t 8.14.0 --napi --strip` in a CentOS container and copy the resulting prebuild to `./prebuilds`: | ||
|
||
``` | ||
npm install --save-dev prebuildify-cross | ||
prebuildify-cross -i centos7-devtoolset7 -t 8.14.0 --napi --strip | ||
``` | ||
|
||
then add new `prebuild:cross:${TARGET}` scripts for the targets you want to support: | ||
To build for more than one platform, multiple `--image` arguments may be passed: | ||
|
||
``` | ||
{ | ||
"scripts": { | ||
"prebuild:cross:linux-armv7": "prebuildify-cross --platform linux --arch arm --arm-version 7", | ||
"prebuild:cross:android-armv7": "prebuildify-cross --platform android --arch arm --arm-version 7" | ||
} | ||
} | ||
prebuildify-cross -i linux-armv7 -i linux-arm64 -t .. | ||
``` | ||
|
||
then when you want to cross-compile prebuilds, `npm run` the appropriate script. | ||
|
||
for the full command-line usage: | ||
Lastly, it's possible to use your own custom image with e.g. `-i my-namespace/my-image`. | ||
|
||
``` | ||
Usage: | ||
prebuildify-cross [options] | ||
## Images | ||
|
||
Arguments: | ||
### `centos7-devtoolset7` | ||
|
||
--arch <arch>: **required** architecture (supported: x32, x64, arm, arm64) | ||
--arm-version <version>: if using arm architecture, **required* arm version (supported: 5, 6, 7, 8) | ||
--platform: **required** platform (supported: linux, android) | ||
Compile in CentOS 7, as a better alternative to (commonly) Ubuntu 16.04 on Travis. Makes the prebuild compatible with Debian 8, Ubuntu 14.04, RHEL 7, CentOS 7 and other Linux flavors with an old glibc. | ||
|
||
--input <path>: _optional_ directory of input image spec (default: cwd) | ||
--output <path>: _optional_ directory to output build results (default: prebuilds) | ||
> The neat thing about this is that you get to compile with gcc 7 but glibc 2.17, so binaries are compatible for \[among others] Ubuntu 14.04 and Debian 8. | ||
> | ||
> The RHEL folks put in a ton of work to make the devtoolsets work on their older base systems (libc mainly), which involves shipping a delta library that contains the new stuff that can be statically linked in where it's used. We use this method for building Node binary releases. | ||
> | ||
> \-- <cite>[**@rvagg**](https://github.com/rvagg) ([prebuild/docker-images#8](https://github.com/prebuild/docker-images/pull/8))</cite> | ||
Flags: | ||
By default the prebuild will be [tagged](https://github.com/prebuild/prebuildify#options) with the libc flavor to set it apart from Alpine prebuilds, e.g. `linux-x64/node.libc.node`. | ||
|
||
-h, --help: show this usage | ||
### `alpine` | ||
|
||
Examples: | ||
Compile in Alpine, which uses musl instead of glibc and therefore can't run regular linux prebuilds. Worse, it sometimes does successfully _load_ such a prebuild during `npm install` - which prevents a compilation fallback from kicking in - and then segfaults at runtime. You can fix this situation in two ways: by shipping an `alpine` prebuild and/or by shipping a `centos7-devtoolset7` prebuild, because the latter will be skipped in Alpine thanks to the `libc` tag. | ||
|
||
prebuildify-cross --platform linux --arch x64 | ||
By default the prebuild will be [tagged](https://github.com/prebuild/prebuildify#options) with the libc flavor, e.g. `linux-x64/node.musl.node`. | ||
|
||
prebuildify-cross --platform linux --arch arm --arm-version 7 | ||
### `linux-armv7` and `linux-arm64` | ||
|
||
prebuildify-cross --platform linux --arch arm64 | ||
Cross-compile for Linux ARM. These images thinly wrap [`dockcross`](https://github.com/dockcross/dockcross) images. | ||
|
||
prebuildify-cross --platform android --arch arm --arm-version 7 | ||
By default the prebuild will be [tagged](https://github.com/prebuild/prebuildify#options) with the armv version (7 or 8, respectively). | ||
|
||
prebuildify-cross --platform android --arch arm64 | ||
``` | ||
### `android-armv7` and `android-arm64` | ||
|
||
you can also pass in environment variables instead of command-line arguments, e.g. | ||
Cross-compile for Android ARM. These images thinly wrap [`dockcross`](https://github.com/dockcross/dockcross) images. | ||
|
||
```shell | ||
PLATFORM=linux ARCH=arm ARM_VERSION=7 prebuildify-cross | ||
``` | ||
By default the prebuild will be [tagged](https://github.com/prebuild/prebuildify#options) with the armv version (7 or 8, respectively). | ||
|
||
## references | ||
## References | ||
|
||
- [Debian multiarch tuples](https://wiki.debian.org/Multiarch/Tuples) | ||
- [Rust support tuples](https://forge.rust-lang.org/platform-support.html) | ||
- [GCC flags](https://stackoverflow.com/questions/16044020/gcc-and-linking-environment-variables-and-flags) | ||
- [Arm options](https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html) | ||
- [Rust cross-compiling tutorial](https://github.com/japaric/rust-cross) | ||
- [Rust cross-compilation tool](https://github.com/rust-embedded/cross) | ||
- [`leveldown` cross-compilation discussion](https://github.com/Level/leveldown/pull/572) | ||
|
||
## license | ||
## License | ||
|
||
GPL-3.0 |
Oops, something went wrong.