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

Support cmake-js #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]`. At least one of `--target`, `--all` or `--napi` must be specified.

Expand All @@ -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
Expand Down
53 changes: 53 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down