---
title: "Generate a depfile for HLSL includes"
url: https://recursiveai.org/oneshader/cookbook/write-hlsl-include-dependency-file/
description: "Generate a Make-style depfile for HLSL includes with OneShader so edits to nested shader headers trigger an incremental SPIR-V rebuild."
version: "1.7.1"
---

# Generate a depfile for HLSL includes

**OneShader** is a free, open-source HLSL compiler library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneShader.Tool) · [GitHub](https://github.com/recursive-ai-oss/oneshader-csharp) · [Docs](https://recursiveai.org/oneshader/docs/) · [Download example (.zip)](https://recursiveai.org/oneshader/cookbook/write-hlsl-include-dependency-file/write-hlsl-include-dependency-file.zip)

A depfile lists the HLSL files your build should watch for changes, including nested headers.

```shell
dotnet tool install -g RecursiveAI.OneShader.Tool
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```shell
oneshader -T cs_6_0 -I include fill.hlsl \
  -Fo fill.spv --depfile fill.d
```

Unzip [the example](https://recursiveai.org/oneshader/cookbook/write-hlsl-include-dependency-file/write-hlsl-include-dependency-file.zip), then `dotnet run`.

Run the command with `fill.hlsl` and the `include/` directory shown below and supplied in the zip. It writes `fill.spv` and a Make-style rule in `fill.d` without printing anything on success. The rule lists the input files by their full paths.

**`fill.hlsl`**

```hlsl
#include <value.hlsli>
RWStructuredBuffer<uint> Output : register(u0);

[numthreads(1, 1, 1)]
void main()
{
    Output[0] = VALUE;
}
```

**`include/value.hlsli`**

```hlsl
#include "base.hlsli"
#define VALUE (BASE_VALUE + 1u)
```

**`include/base.hlsli`**

```hlsl
#define BASE_VALUE 41u
```

## The full program

The zip restores the tool version in its manifest and invokes the same CLI. It strips the current directory prefix only when printing the rule; the depfile on disk keeps the compiler’s paths. You don’t need the global install for the zip.

```csharp
using System.Diagnostics;

RunDotnet("tool", "restore");
RunDotnet("oneshader", "-T", "cs_6_0", "-I", "include", "fill.hlsl",
    "-Fo", "fill.spv", "--depfile", "fill.d");
// Shorten local paths for display only; leave the depfile intact for Make.
string prefix = Path.GetFullPath(".").Replace('\\', '/') + "/";
string rule = File.ReadAllText("fill.d");
Console.Write(rule.Replace(prefix.Replace("$", "$$").Replace("#", "\\#")
    .Replace(" ", "\\ "), "", StringComparison.Ordinal));

static void RunDotnet(params string[] args)
{
    var command = new ProcessStartInfo("dotnet");
    foreach (string arg in args) command.ArgumentList.Add(arg);
    using var process = Process.Start(command)!;
    process.WaitForExit();
    if (process.ExitCode != 0)
        throw new InvalidOperationException($"dotnet {args[0]} exited with {process.ExitCode}.");
}
```

After the tool restore messages, it prints:

```text
fill.spv: fill.hlsl include/base.hlsli include/value.hlsli
```

If an included file can’t be found, the compile fails and no new depfile is written; don’t reuse an old one as if the compile succeeded.

## Variations

**Use a space in the output filename.** Quote the path at the shell; the compiler escapes the space for Make.

```shell
oneshader -T cs_6_0 -I include fill.hlsl \
  -Fo "fill test.spv" --depfile "fill test.d"
```

The new rule starts with `fill\ test.spv:`.

## Related recipes

- [Compile HLSL with in-memory includes](https://recursiveai.org/oneshader/cookbook/compile-hlsl-with-in-memory-includes/)
- [Export HLSL reflection as JSON](https://recursiveai.org/oneshader/cookbook/export-hlsl-reflection-json/)

---

## The short answer

Pass `--depfile fill.d` on the same command that compiles `fill.hlsl`. The compiler writes a rule with the compiled output on the left and the files it read on the right. Give that rule to your build system so it can recompile just the shaders that depend on an edited header.

## Does the depfile include nested headers?

[`#include`](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-pre-include) inserts the contents of another file into the shader source. In this example, `-I include` tells OneShader where to look for `value.hlsli`. That file includes `base.hlsli`, so an edit to the base file can change the shader even when `fill.hlsl` hasn’t changed. The generated rule includes both headers; it doesn’t stop at the first level. The [command-line documentation](https://recursiveai.org/oneshader/docs/command-line/#oneshader-options) also notes that the depfile escapes spaces, `#`, and `$` for Make.

## How do you make a shader recompile when an included file changes?

Include the generated file in your Makefile. With [GNU Make 4.3 or newer](https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html), use `&:` to tell Make that one command creates both outputs. Start with `dotnet tool restore` in the unzipped folder to make the local `dotnet oneshader` command available. Keep the tab before the recipe command.

```makefile
.DEFAULT_GOAL := fill.spv
-include fill.d

fill.spv fill.d &: fill.hlsl
	dotnet oneshader -T cs_6_0 -I include fill.hlsl \
	  -Fo fill.spv --depfile fill.d
```

Run `make` once to create both files. A second run without edits leaves the shader up to date. Edit `include/base.hlsli` and Make runs the compile again, even though `fill.hlsl` hasn’t changed. Keep `fill.hlsl` in the explicit rule so the first build works before the generated rule exists. If you change compiler flags in the Makefile, add the Makefile as a prerequisite too: the depfile only lists files the shader compiler read.
