Zig NEWS

Cover image for 🧩 Zig multi-project workflow in VS Code (with dynamic debug/build and one `tasks.json` to rule them all)
pierangelomiceli
pierangelomiceli

Posted on

🧩 Zig multi-project workflow in VS Code (with dynamic debug/build and one `tasks.json` to rule them all)

Zig is awesome for low-level systems programming, but when working on multiple projects in a shared workspace, VS Code can get repetitive fast.

I wanted a clean way to:

  • 🔧 Build and debug multiple Zig projects
  • 🚀 Without duplicating configurations tasks.json and launch.json
  • 🎯 And have a smooth, native experience in VS Code

Turns out, you can do it entirely using inputs in VS Code's task system — no .env files, no shell scripts, no hacks.


🧠 What this setup gives you

  • A single tasks.json
  • A single launch.json
  • You choose your Zig project from a dropdown
  • It builds and debugs the right one choosing by a dropdown
  • Everything works with zig build, zig-out/bin/..., and LLDB breakpoints

📦 Project structure

multi-zig-project/
├── project1/
│   ├── src/
│   └── build.zig
├── project2/
│   ├── src/
│   └── build.zig
└── .vscode/
    ├── tasks.json
    └── launch.json
Enter fullscreen mode Exit fullscreen mode

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Zig Project (LLDB)",
      "type": "lldb",
      "request": "launch",
      "program": "${workspaceFolder}/${input:targetProject}/zig-out/bin/${input:targetProject}",
      "args": [],
      "cwd": "${workspaceFolder}",
      "terminal": "integrated",
      "preLaunchTask": "build-zig-dynamic",
      "env": {}
    }
  ],
  "inputs": [
    {
      "id": "targetProject",
      "type": "pickString",
      "description": "DEBUG: Choose project to debug...",
      "options": ["project1", "project2"],
      "default": "project1"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Tasks.json


{
  "version": "2.0.0",
  "inputs": [
    {
      "id": "targetProject",
      "type": "pickString",
      "description": "BUILD TASK: Choose project a project to build...",
      "options": ["project1", "project2"],
      "default": "project1"
    }
  ],
  "tasks": [
    {
      "label": "build-zig-dynamic",
      "type": "shell",
      "command": "zig build -Doptimize=Debug",
      "options": {
        "cwd": "${workspaceFolder}/${input:targetProject}"
      },
      "problemMatcher": []
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

🚀 How to use it

  1. Open the workspace in VS Code
  2. Place a breakpoint on project1 or project2 main.zig files.
  3. Press F5 to Debug
  4. you'll be prompted to pick a project to Debug
  5. you'll be prompted to pick a project to pre build

There are 2 projects, but you can add more simply adding projects and add a reference in input sections of tasks.json and launch.json

🛠 Requirements

  • Working on Zig (0.14)
  • VS Code
  • CodeLLDB extension (for debugging)
  • LLDB

Github repo link

Complete repo available at:
https://github.com/pierangelomiceli/multi-zig-project

💬 Why share this?

Because I thought someone else might be tired of juggling 5 copies of the same config too.
This setup is clean, scalable, and 100% portable. Hope it helps someone!

Feel free to fork, tweak, or give feedback 🚀

Top comments (0)