Skip to content

Latest commit

 

History

History
234 lines (163 loc) · 5.25 KB

quickstart.md

File metadata and controls

234 lines (163 loc) · 5.25 KB

Quick start: a Netsuke build

This guide walks through creating and running a Netsuke build in under five minutes.

Prerequisites

Before beginning, ensure the following are available:

  • Netsuke installed — install a prebuilt release binary with cargo binstall netsuke-build where cargo binstall is available, install from source inside a repository checkout with cargo install --path . (which puts netsuke on PATH for the commands below), or follow the registry-install command in the users' guide. A bare cargo install is unsupported: registry builds need the pinned nightly toolchain — which is what enables the Polonius borrow checker — selected explicitly, as the guide shows.
  • Ninja build tool in the system PATH (install via the package manager, e.g., apt install ninja-build or brew install ninja)

Step 1: Create a project directory

In a terminal, create a new directory for the project:

mkdir hello-netsuke
cd hello-netsuke

Step 2: Create the first manifest

A file named Netsukefile should be created with the following content:

netsuke_version: "1.0.0"

targets:
  - name: hello.txt
    command: "echo 'Hello from Netsuke!' > hello.txt"

defaults:
  - hello.txt

This manifest defines:

  • A target called hello.txt that creates a file with a greeting.
  • A default target, so running netsuke without arguments builds hello.txt.

Step 3: Run Netsuke

To build the project, run Netsuke:

netsuke

The output should be similar to:

[1/1] echo 'Hello from Netsuke!' > hello.txt

The result can be verified:

cat hello.txt

Output:

Hello from Netsuke!

This completes the first Netsuke build.

Step 4: Add variables and templates

Netsuke supports Jinja templating for dynamic manifests. The Netsukefile can be updated as follows:

netsuke_version: "1.0.0"

vars:
  greeting: "Hello"
  name: "World"

targets:
  - name: greeting.txt
    command: "echo '{{ greeting }}, {{ name }}!' > greeting.txt"

defaults:
  - greeting.txt

Running netsuke again:

netsuke

The output can be checked:

cat greeting.txt

Output:

Hello, World!

Step 5: Use globbing and foreach

For more complex builds, Netsuke can process multiple files. Some input files can be created as follows:

echo "Content A" > input_a.txt
echo "Content B" > input_b.txt

The Netsukefile can be updated to process all .txt files:

netsuke_version: "1.0.0"

targets:
  - foreach: glob('input_*.txt')
    name: "output_{{ item | basename | with_suffix('.out') }}"
    command: "cat {{ item }} | tr 'a-z' 'A-Z' > {{ outs }}"
    sources: "{{ item }}"

defaults:
  - output_input_a.out
  - output_input_b.out

Running netsuke:

netsuke

The outputs can be checked:

cat output_input_a.out
cat output_input_b.out

The input files have been transformed to uppercase.

Next steps

  • Read the full User Guide for comprehensive documentation
  • Explore the examples/ directory for real-world manifest examples:
    • basic_c.yml — C compilation with rules and variables
    • website.yml — Static site generation from Markdown
    • photo_edit.yml — Photo processing with glob patterns
  • Run netsuke --help to see all available options
  • Try netsuke graph to visualize the build dependency graph

Troubleshooting

"No Netsukefile found in the current directory"

Ensure the current directory is correct and that a file named Netsukefile exists. A different manifest path can be specified with -f:

netsuke -f path/to/manifest.yml

"Could not start the Ninja program"

Netsuke reports a Ninja it cannot start as netsuke::runner::ninja_spawn_failed, naming the program it attempted:

Could not start the Ninja program `ninja`.

Install Ninja using the system's package manager:

  • Ubuntu/Debian: sudo apt install ninja-build
  • macOS (Homebrew): brew install ninja
  • Windows (Chocolatey): choco install ninja

A Ninja that is on PATH but cannot be executed, such as a copy that lost its executable bit, fails the same way. Check the file's permissions and restore them, or select an executable Ninja program:

chmod +x /path/to/ninja

If Ninja is installed somewhere off PATH, or the executable is named differently, set NETSUKE_NINJA to its full path:

NETSUKE_NINJA=/opt/ninja/bin/ninja netsuke build

PowerShell sets the variable for the current session instead:

$env:NETSUKE_NINJA = 'C:\tools\ninja\ninja.exe'
netsuke build

"Ninja reported a build failure"

When Ninja runs but a recipe fails, the summary reports Ninja's exit status:

Ninja reported a build failure (exit status 1).

In human mode Ninja's own output, including the failing command, appears above the summary. JSON mode drains that output so stderr stays one machine-readable document, keeping only the command-list attribution Netsuke recovers from the output tail. For a tool subcommand the summary names the tool instead:

Ninja tool `clean` reported a failure (exit status 1).

The temporary build file Netsuke generated is not named in either case.