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
const binBuild = require('bin-build');
binBuild.url('http://www.lcdf.org/gifsicle/gifsicle-1.80.tar.gz', [
'./configure --disable-gifview --disable-gifdiff',
'make install'
]).then(() => {
console.log('gifsicle built successfully');
});
binBuild.file('gifsicle-1.80.tar.gz', [
'./configure --disable-gifview --disable-gifdiff',
'make install'
]).then(() => {
console.log('gifsicle built successfully');
});
API
binBuild.directory(directory, commands)
directory
Type: string
Path to a directory containing the source code.
commands
Type: Array
Commands to run when building.
binBuild.file(file, commands, [options])
file
Type: string
Path to a archive file containing the source code.
commands
Type: Array
Commands to run when building.
options
Type: Object
strip
Type: number
Default: 1
Strip a number of leading paths from file names on extraction.
binBuild.url(url, commands, [options])
url
Type: string
URL to a archive file containing the source code.
commands
Type: Array
Commands to run when building.
options
Type: Object
strip
Type: number
Default: 1
Strip a number of leading paths from file names on extraction.
License
MIT © Kevin Mårtensson