Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite as node cli using prebuild/docker-images #7

Merged
merged 8 commits into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .dockerignore

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/output/
/apt-cacher-ng/
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

104 changes: 32 additions & 72 deletions README.md
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
Loading