bare-make

1.7.2 · active · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

Demonstrates the full programmatic workflow of generating, building, installing, and testing a CMake project using bare-make's API, including verbose output and parallel execution.

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();

view raw JSON →