What is bin-build?
The bin-build npm package is a tool for building binaries using Node.js. It allows you to compile and install binaries from source, making it useful for developers who need to automate the process of building and installing command-line tools or other binary dependencies.
What are bin-build's main functionalities?
Building a binary from source
This feature allows you to build a binary from a source URL. The code sample demonstrates how to download a source tarball, configure the build, and run the build commands.
const BinBuild = require('bin-build');
const sourceUrl = 'https://example.com/source.tar.gz';
const buildCommands = [
'./configure --disable-shared',
'make',
'make install'
];
const builder = new BinBuild();
builder.src(sourceUrl)
.cmd(buildCommands.join(' && '))
.run((err) => {
if (err) {
console.error('Build failed:', err);
} else {
console.log('Build succeeded');
}
});
Customizing build environment
This feature allows you to customize the build environment by setting environment variables. The code sample shows how to set CFLAGS and LDFLAGS before running the build commands.
const BinBuild = require('bin-build');
const sourceUrl = 'https://example.com/source.tar.gz';
const buildCommands = [
'./configure --disable-shared',
'make',
'make install'
];
const builder = new BinBuild();
builder.src(sourceUrl)
.cmd(buildCommands.join(' && '))
.env({
'CFLAGS': '-O2',
'LDFLAGS': '-L/usr/local/lib'
})
.run((err) => {
if (err) {
console.error('Build failed:', err);
} else {
console.log('Build succeeded');
}
});
Checking for binary existence
This feature allows you to check if a binary exists after the build process. The code sample demonstrates how to run the build commands and then check for the existence of the binary.
const BinBuild = require('bin-build');
const builder = new BinBuild();
builder.src('https://example.com/source.tar.gz')
.cmd('./configure && make && make install')
.run((err) => {
if (err) {
console.error('Build failed:', err);
} else {
console.log('Build succeeded');
builder.exists('path/to/binary', (exists) => {
if (exists) {
console.log('Binary exists');
} else {
console.log('Binary does not exist');
}
});
}
});
Other packages similar to bin-build
node-gyp
node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It is similar to bin-build in that it helps automate the build process, but it is specifically designed for compiling Node.js native addons.
prebuild
prebuild is a tool for building and publishing prebuilt binaries for Node.js native addons. It is similar to bin-build in that it helps with the build process, but it focuses on creating and distributing prebuilt binaries to avoid the need for users to compile the code themselves.
node-pre-gyp
node-pre-gyp is a Node.js tool that allows you to publish and install Node.js C++ addons from binaries. It is similar to bin-build in that it helps with the build and installation process, but it also includes features for packaging and distributing prebuilt binaries.
bin-build
Easily build binaries
Install
$ npm install --save bin-build
Usage
var BinBuild = require('bin-build');
var build = new BinBuild();
build
.src('http://www.lcdf.org/gifsicle/gifsicle-1.80.tar.gz')
.cfg('./configure --disable-gifview --disable-gifdiff')
.make('make install')
.build(function (err) {
if (err) {
throw err;
}
console.log('gifsicle built successfully');
});
API
new BinBuild
Creates a new BinBuild
instance.
.src(str)
Accepts a URL to a archive containing the source code.
.cfg(str)
String with configuration options to be run before make
.
.make(str)
String with make
commands.
.build(cb)
Runs the build.
License
MIT © Kevin Mårtensson