diff --git a/README.md b/README.md index 0421337..cd15d87 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ Options can be provided via (in order of precedence) the programmatic API, the C | `--node-gyp` | `PREBUILD_NODE_GYP` | `'node-gyp(.cmd)'` | Custom `node-gyp` binary\*\*\*\* | `--quiet` | - | `false` | Suppress `node-gyp` output | `--cwd` | - | `process.cwd()` | Working directory +| `--backend` | - | `node-gyp` | The build backend to use, e.g. `cmake-js` \* A target takes the form of `(runtime@)?version`, where `runtime` defaults to `'node'`. For example: `-t 8.14.0 -t electron@3.0.0`. At least one of `--target`, `--all` or `--napi` must be specified. @@ -112,6 +113,12 @@ Options can be provided via (in order of precedence) the programmatic API, the C \*\*\*\* To enable the use of forks like [`nodejs-mobile-gyp`](https://www.npmjs.com/package/nodejs-mobile-gyp). +When using the `cmake-js` backend additional parameters can be passed through. + +``` +prebuildify --backend cmake-js -- --prefer-clang --CDUV_INCLUDE_DIR=... +``` + ## License MIT diff --git a/index.js b/index.js index dc185d7..9083660 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var mkdirp = require('mkdirp-classic') var tar = require('tar-fs') var pump = require('pump') var npmRunPath = require('npm-run-path') +var which = require('npm-which')(process.cwd()) module.exports = prebuildify @@ -175,6 +176,58 @@ function run (cmd, opts, cb) { } function build (target, runtime, opts, cb) { + if (opts.backend === 'cmake-js') { + runCmake(target, runtime, opts, cb) + } else { + runGyp(target, runtime, opts, cb) + } +} + +function runCmake (target, runtime, opts, cb) { + which('cmake-js', function (err, cmakeJsPath) { + if (err) return cb(err) + + var args = [ + 'rebuild', + '--out=' + opts.output + ] + + if (runtime !== 'napi') args.push('--runtime-version=' + target) + args.push('--arch=' + opts.arch) + if (runtime !== 'napi') args.push('--runtime=' + runtime) + if (runtime === 'napi' && target) { + args.push('--CDnapi_build_version=' + target) + } + + if (opts.debug) args.push('--debug') + + for (var arg of opts._) { + args.push(arg) + } + + console.log(args); + var child = proc.spawn(cmakeJsPath, args, { + cwd: opts.cwd, + env: opts.env, + stdio: opts.quiet ? 'ignore' : 'inherit' + }) + + child.on('exit', function (code) { + if (code) return cb(spawnError('cmake-js', code)) + + findBuild(opts.output, function (err, output) { + if (err) return cb(err) + + strip(output, opts, function (err) { + if (err) return cb(err) + cb(null, output) + }) + }) + }) + }) +} + +function runGyp (target, runtime, opts, cb) { var args = [ 'rebuild', '--target=' + target diff --git a/package.json b/package.json index a77a5aa..8d8fbca 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,12 @@ "description": "Create and package prebuilds for native modules", "main": "index.js", "dependencies": { + "cmake-js": "^7.2.1", "execspawn": "^1.0.1", "mkdirp-classic": "^0.5.3", "node-abi": "^3.3.0", "npm-run-path": "^3.1.0", + "npm-which": "^3.0.1", "minimist": "^1.2.5", "pump": "^3.0.0", "tar-fs": "^2.1.0"