bare-make
bare-make is an opinionated build system generator designed to simplify the CMake workflow by enforcing a consistent build environment. It leverages CMake to generate build files specifically for Ninja, utilizing Clang as the compiler toolchain across all supported operating systems. This approach ensures highly reliable and reproducible compilation processes by standardizing the build system and compiler. While it imposes these specific tools, it remains fully compatible with standard CMake, allowing developers to easily "eject" to a plain CMake flow if needed. The current stable version is 1.7.2, and it appears to follow an active release cadence tied to its parent organization's projects. Its primary differentiators include its programmatic JavaScript API for build automation and its strong focus on build consistency through fixed toolchains, making it ideal for projects requiring strict build guarantees.
Common errors
-
Error: Command failed with exit code 1: cmake ... (or ninja ... or clang ...)
cause Underlying build tools (CMake, Ninja, or Clang) are either not found in the system's PATH, or there's a fundamental configuration error within your CMake project's `CMakeLists.txt`.fixFirst, verify that CMake, Ninja, and Clang are installed and added to your system's PATH. If they are, enable verbose output (`verbose: true` in options, `stdio: 'inherit'`) to see the exact command output and diagnose `CMakeLists.txt` errors. -
Error: Source directory '...' does not contain a CMakeLists.txt file.
cause The `source` option provided to `make.generate()` or via the CLI points to a directory that does not contain a `CMakeLists.txt` file, which is the required entry point for a valid CMake project.fixAdjust the `source` option to correctly point to the root directory of your CMake project where the primary `CMakeLists.txt` file is located. This is typically the directory containing your project's top-level build definition. -
Error: Target '...' not found
cause The specified `target` in `make.build()` (or via the `--target` CLI flag) does not exist in your CMake project. Common targets include 'all', 'install', or names of executables/libraries you define.fixReview your `CMakeLists.txt` files to identify the correct target names. Use `cmake --build <build-dir> --target help` from the command line to list available targets if you are unsure.
Warnings
- gotcha bare-make explicitly enforces the use of Ninja as the build system generator and Clang as the compiler toolchain. Projects expecting to use other compilers (e.g., GCC, MSVC) or alternative build systems (e.g., Makefiles, Visual Studio) will need to adapt their `CMakeLists.txt` or use plain CMake directly.
- gotcha bare-make relies on CMake, Ninja, and Clang being pre-installed and discoverable in the system's PATH. It does not bundle or automatically install these fundamental underlying tools itself.
- gotcha The package lists 'bare-pipe' as a peer dependency (`"bare-pipe": "*"`). While not a direct runtime dependency that `npm install` would automatically fetch, it is crucial for `bare-make`'s internal process management and might require explicit installation by the user (`npm install bare-pipe`).
Install
-
npm install bare-make -
yarn add bare-make -
pnpm add bare-make
Imports
- make
import { generate, build } from 'bare-make';import make from 'bare-make';
- make (CJS)
const make = require('bare-make'); - GenerateOptions
import { GenerateOptions } from 'bare-make';import type { GenerateOptions } from 'bare-make';
Quickstart
import make from 'bare-make';
import path from 'path';
import os from 'os';
async function runBuildProcess() {
// Define your project's root, build directory, and install prefix
const projectRoot = process.cwd(); // Or specify a different path
const buildDir = path.join(projectRoot, 'build-bare-make');
const installPrefix = path.join(projectRoot, 'dist-prebuilds');
console.log(`Starting bare-make build process in: ${projectRoot}`);
try {
console.log('\n--- Generating build system ---');
// Generate build files for Ninja using Clang, enabling debug symbols
await make.generate({
source: projectRoot,
build: buildDir,
platform: os.platform(),
arch: os.arch(),
debug: true, // Configure a debug build
verbose: true, // Enable verbose output for generation
stdio: 'inherit' // Stream output directly to console
});
console.log(`Build system successfully generated in: ${buildDir}`);
console.log('\n--- Building project ---');
// Build all targets in parallel
await make.build({
build: buildDir,
target: 'all', // Build all targets defined in CMakeLists.txt
parallel: os.cpus().length, // Use all available CPU cores
verbose: true,
stdio: 'inherit'
});
console.log('Project built successfully.');
console.log('\n--- Installing artifacts ---');
// Install built artifacts to a specified prefix
await make.install({
build: buildDir,
prefix: installPrefix,
verbose: true,
stdio: 'inherit'
});
console.log(`Artifacts installed to: ${installPrefix}`);
console.log('\n--- Running tests (if enabled) ---');
// Run CTest tests if enabled in CMakeLists.txt
await make.test({
build: buildDir,
timeout: 60, // Max 60 seconds per test
parallel: os.cpus().length,
verbose: true,
stdio: 'inherit'
});
console.log('Tests completed.');
} catch (error) {
console.error('\nBuild process failed:', error.message);
process.exit(1);
}
}
runBuildProcess();