> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codecrafters.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Zig

> Learn how to solve CodeCrafters challenges in Zig

<Note>
  **New to Zig?** We recommend checking out
  [ziglang.org/learn](https://ziglang.org/learn/) to get up to speed.
</Note>

## Local development

To run the code for your challenge locally, you'll need `zig` installed. Our test runners use version `0.11` (as of November 2023).

The script for your challenge (like `./your_bittorrent.sh`) will automatically compile your code using `zig build-exe` before executing it. It'll
look something like this:

```sh theme={null}
#!/bin/sh
set -e

zig build-exe ./app/main.zig
exec ./main "$@"
```

## File structure

* The files for your solution are placed in the `app` directory.
* `app/main.zig` contains the `main` function, which is what the test runner executes.

## Adding more files

You can add more files and directories to the `app` directory. The test runner will include them when compiling your code.

For example, if you added a file at `app/foo.zig`, you could use it like so:

<CodeGroup>
  ```zig app/main.zig theme={null}
  const foo = @import("foo.zig");

  pub fn main() void {
    foo.bar() // Uses the bar function from foo.zig
  }
  ```

  ```zig app/foo.zig theme={null}
  const std = @import("std");

  pub fn bar() void {
    std.debug.print("Hello World!", .{});
  }
  ```
</CodeGroup>

You can also add files in subdirectories. For example, if you added a file at `app/foo/bar.zig`, you could use it like so:

<CodeGroup>
  ```zig app/foo/bar.zig theme={null}
  const std = @import("std");

  pub fn baz() void {
    std.debug.print("Hello World!", .{});
  }
  ```

  ```zig app/main.zig theme={null}
  const bar = @import("foo/bar.zig");

  pub fn main() void {
    bar.baz() // Uses the baz function from foo/bar.zig
  }
  ```
</CodeGroup>

## Adding dependencies

We don't support the package manager added in Zig 0.11 yet. For now, you'll need to copy in any dependencies you need into your project
and import them using `@import`.

<Note>
  We'd love help adding support for the new package manager added in Zig 0.11.
  If you're interested in this, feel free to open a PR to the [SQLite challenge
  repository](https://github.com/codecrafters-io/build-your-own-sqlite/tree/main/starter_templates/zig).
  You can find more details on contributing language support
  [here](/contributors/adding-language-support/introduction).
</Note>
