pixi-make-cu-build-env

Guides the agent to setup a new or existing Pixi environment for compiling C++ and CUDA code. It ensures the correct compilers, toolkits, and CMake configurations are in place for a robust user-space build.

7 stars

Best use case

pixi-make-cu-build-env is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Guides the agent to setup a new or existing Pixi environment for compiling C++ and CUDA code. It ensures the correct compilers, toolkits, and CMake configurations are in place for a robust user-space build.

Teams using pixi-make-cu-build-env should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/pixi-make-cu-build-env/SKILL.md --create-dirs "https://raw.githubusercontent.com/igamenovoer/magic-context/main/skills/tools/pixi/pixi-make-cu-build-env/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/pixi-make-cu-build-env/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How pixi-make-cu-build-env Compares

Feature / Agentpixi-make-cu-build-envStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Guides the agent to setup a new or existing Pixi environment for compiling C++ and CUDA code. It ensures the correct compilers, toolkits, and CMake configurations are in place for a robust user-space build.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Pixi Make CUDA Build Env

## Trigger

Use this skill when the user asks to:
- "Setup a CUDA build environment in this project"
- "Prepare the current Pixi project for compiling .cu files"
- "Add CUDA compilation support to <project_path>"

## Workflow

### 1. Requirements Gathering
**Mandatory**: You MUST identify:
1.  **Project Context**: The existing Pixi project path. (Default to current working directory if valid).
2.  **Manifest File**: Identify if the project uses `pixi.toml` or `pyproject.toml`.
3.  **Target Environment Name**: "Which Pixi environment should this be set up in?"
    *   *Default*: If not specified, assume the `default` environment.
    *   *Named*: If the user provides a name (e.g., `cuda-12`), use that feature.
4.  **CUDA Version**: "Which CUDA version do you need?" (e.g., 11.8, 12.1).
5.  **Host Tools**: Check if `cmake`, `ninja`, and a C++ compiler are available and suitable.
    *   *Action*: Run `cmake --version`, `ninja --version`, and check for `gcc`/`clang` (Linux) or `cl` (Windows).
    *   *Decision*: If missing or old, include them in the Pixi environment.

6.  **Tools**: "Do you need profiling/debugging tools like `nsight-compute`?"

### 2. Conflict Detection & Resolution
Before modifying the project, verify the current state of `<MANIFEST_FILE>`.
*   **Check**: Are there existing CUDA libs (`cuda-toolkit`, `cudnn`)? Is the `nvidia` channel prioritized? Are versions conflicting?
*   **Conflict Logic**: If conflicts are detected (e.g., `conda-forge` prioritized, incompatible pins):
    *   **Autonomous Check**: Did the user say "adjust settings", "proceed without asking", or "do what you have to"?
        *   *Yes*: **Automatically proceed** with **Option 1** (New Env) for safety, or **Option 2** (Force) if the user explicitly asked to fix *this* environment.
    *   **Manual Resolution**: If no authorization, **STOP** and offer:
        1.  **Create New Environment (Recommended)**: Create a separate environment (e.g., `cu<VERSION>-build`) with its own `solve-group` to isolate dependencies.
        2.  **Force Adjust (Risky)**: Reorder channels and overwrite pins in the target environment. **Warn**: This may break existing code.
        3.  **Cancel**: Abort the operation.
        4.  **Custom**: Ask the user for specific instructions on how to handle the conflict.

### 3. Adding Dependencies (Based on Selection)
Execute the workflow corresponding to the user's choice.

#### Option 1: New Isolated Environment (Recommended)
Create a new feature and environment with a dedicated `solve-group`.

```bash
# 1. Add Feature with Dependencies (Pin channel to nvidia)
pixi add --manifest-path <MANIFEST_FILE> --feature <NEW_ENV_NAME> --channel nvidia \
    cmake ninja cxx-compiler make pkg-config \
    cuda-toolkit=<VERSION> cuda-nvcc=<VERSION> \
    [cudnn nccl nsight-compute]

# 2. Create Environment with Dedicated Solve-Group
# (Use 'pixi workspace environment add' or edit manifest manually if CLI lacks support)
# TOML equivalent:
# [tool.pixi.environments]
# <NEW_ENV_NAME> = { features = ["<NEW_ENV_NAME>"], solve-group = "<NEW_ENV_NAME>" }
```

#### Option 2: Force Adjust Existing
**Best Practice**: Always add the `nvidia` channel to the project configuration *before* installing packages.

**Command Logic**:
*   **Default Environment**: Do NOT use `--feature`.
*   **Named Environment**: Use `--feature <ENV_NAME>`.

```bash
# 1. Setup Channels (Prioritize NVIDIA)
pixi project channel add nvidia --prepend --manifest-path <PROJECT_PATH>/<MANIFEST_FILE>

# 2. Core Build Tools
pixi add --manifest-path <PROJECT_PATH>/<MANIFEST_FILE> [--feature <ENV_NAME>] cmake ninja cxx-compiler make pkg-config

# 3. CUDA Toolchain
pixi add --manifest-path <PROJECT_PATH>/<MANIFEST_FILE> [--feature <ENV_NAME>] cuda-toolkit=<VERSION> cuda-nvcc=<VERSION>
```

*Optional Extras/Tools (Only if requested):*
```bash
pixi add --manifest-path <PROJECT_PATH>/<MANIFEST_FILE> [--feature <ENV_NAME>] cudnn=<VERSION> nccl=<VERSION> nsight-compute
```

### 4. Configuring Build Tasks
Add a standard CMake build task to `<MANIFEST_FILE>`.
*   **Note**: Tasks typically run in the activated environment. Ensure `CMAKE_CUDA_COMPILER` points to the *Pixi-managed* `nvcc` ($CONDA_PREFIX/bin/nvcc).

**Task Definition:**
```toml
[tool.pixi.tasks]
configure = { cmd = "cmake -G Ninja -S . -B build -DCMAKE_CUDA_COMPILER=$CONDA_PREFIX/bin/nvcc -DCUDAToolkit_ROOT=$CONDA_PREFIX", env = { CUDACXX = "$CONDA_PREFIX/bin/nvcc" } }
build = "cmake --build build"
test = "ctest --test-dir build"
```

### 5. Verification (Automated)
To verify the setup, deploy the self-contained test suite from the skill's resource directory.

**1. Deploy Test Suite:**
Check if the project has a `tmp/` directory. If so, place the verification project there to keep the root clean.
```bash
# Determine verification path
TARGET_DIR="build-check"
if [ -d "tmp" ]; then TARGET_DIR="tmp/build-check"; fi

# Deploy
mkdir -p "$TARGET_DIR"
cp -r magic-context/skills/tools/pixi/pixi-make-cu-build-env/demo-code/* "$TARGET_DIR"/
chmod +x "$TARGET_DIR/build-and-run.sh"
```

**2. Execute:**
Run the script using the configured environment. The script automatically handles source path detection.
```bash
pixi run --manifest-path <MANIFEST_FILE> [--feature <ENV_NAME>] "$TARGET_DIR/build-and-run.sh"
```
*   **Note**: If the host has no GPU or an incompatible driver, the **build step** should still succeed, but the binary execution will fail. In this case, verify that `$TARGET_DIR/build/check_app` exists to confirm the compilation setup.

## Troubleshooting

### CMake Errors
*   **Source Directory**: The provided `build-and-run.sh` handles directory context automatically. If you see errors about missing `CMakeLists.txt`, ensure you haven't moved the script out of the verification directory.
*   **Pthread Failure**: `Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed` is often normal; CMake usually finds `pthread` in the next step.
*   **Architecture Warnings**: `nvcc warning : Support for offline compilation...` indicates the default architecture might be older. You can safely ignore this warning for verification purposes.

### Runtime Errors
*   **Driver Mismatch**: If the kernel fails to launch, check `nvidia-smi`. The host driver must support the installed CUDA Toolkit version.

## Best Practices
*   **Never mix channels** for CUDA: Stick to `nvidia` for `cuda-*` packages.
*   **Explicit Compilation**: Always prefer passing `-DCMAKE_CUDA_COMPILER` over relying on implicit path resolution, as CMake might pick up `/usr/bin/nvcc`.
*   **User Space**: Remind the user that this setup requires NO `sudo` and works on any Linux machine with a driver.

Related Skills

pixi-make-offline-channel

7
from igamenovoer/magic-context

Use when the user wants to create a self-hosted, offline-installable Conda channel (mirror) containing a specific subset of packages using Pixi.

pixi-install-nvidia

7
from igamenovoer/magic-context

Use when the user says "use pixi to install <some nvidia tool>" (or similar) and wants NVIDIA/CUDA/GPU packages installed via Pixi (no sudo/apt), e.g., CUDA toolkit pieces, cuDNN/NCCL, PyTorch CUDA builds, RAPIDS.

init-pixi-project

7
from igamenovoer/magic-context

Initialize and scaffold a new Pixi-managed Python project, or upgrade an existing one. Use when the user explicitly mentions "init", "initialize", or "setup" in conjunction with "pixi". Handles existing projects by prompting for confirmation before merging.

vscode-make-offline-installer

7
from igamenovoer/magic-context

Build a VS Code air-gapped "offline kit" for Remote-SSH: desktop VS Code installers/archives for Windows/macOS/Linux, matching VS Code Server+CLI tarballs for headless Linux (commit-aligned), and pinned extension .vsix bundles for both local (client) and remote (server) sides. Use when you need a reproducible offline deployment, or when you want to mirror the VS Code release+extensions currently installed on a host.

docker-pixi-project-offline

7
from igamenovoer/magic-context

Scripted process to build and verify a Pixi-managed project in Docker, then produce a portable WORKDIR/product directory for air-gapped use.

pei-docker-usage

7
from igamenovoer/magic-context

Helper for PeiDocker (`pei-docker-cli`). Trigger ONLY when the user explicitly requests PeiDocker usage OR when working within a PeiDocker-generated project (indicated by `user_config.yml`).

conan-basic-usage

7
from igamenovoer/magic-context

Basic operations for the Conan C++ package manager. Use when the user explicitly asks to 'use conan' for tasks like creating projects, installing dependencies, or building packages, or asks for 'how to' guidance on Conan setup.

explore-dnn-model

7
from igamenovoer/magic-context

Manual invocation only; use only when the user explicitly requests `explore-dnn-model` by name. Explore how to run a given DNN model checkpoint in the current Python environment by locating weights + upstream source code, resolving dependencies with user confirmation, running reproducible experiments under `tmp/`, and producing reports about I/O contracts, timing, and profiling.

openspec-ext-revise-by-decision

7
from igamenovoer/magic-context

Manual invocation only; use only when the user explicitly requests `openspec-ext-revise-by-decision` by exact name. Revise OpenSpec change artifacts from a review or decision document that contains questions plus `DECISION` blocks, applying chosen decisions from a review file such as `openspec/changes/<change>/review/review-*.md` back into proposal, design, specs, and tasks.

openspec-ext-review-plan

7
from igamenovoer/magic-context

Review an OpenSpec change (or a single OpenSpec change artifact file) for completeness, coherence, and alignment with existing system design; capture actionable feedback plus open questions; write a review report under the change directory (review/review-YYYYMMDD-HHMMSS.md).

openspec-ext-respond-to-review

7
from igamenovoer/magic-context

Read an OpenSpec review report critically, evaluate the reviewer's proposals and findings against the current change artifacts and repository context, and write developer-owned final decisions/responses back into the review document. Use when the user explicitly mentions `openspec` or points to a path under `openspec/` while asking to examine a review report carefully, decide open questions, respond to findings, fill `DECISION` blocks, respond to an OpenSpec review file, or record final answers in an OpenSpec review document without yet revising the proposal, design, specs, or tasks.

openspec-ext-hack-through-test

7
from igamenovoer/magic-context

Manual invocation only. OpenSpec-specific hack-through-testing workflow targeting production-level end-to-end paths using real data and real user workflows — not CI smoke/unit/integration tests. Three subskills: `propose` to create an OpenSpec change with HTT-ready test cases (automatic scripts and interactive guides) by invoking `openspec-propose` or `openspec-ff-change`, `revise` to update an existing OpenSpec change so its artifacts support hack-through-testing-driven implementation and testing, and `run` to exercise an implemented OpenSpec change through the full hack-through-testing loop (in-place by default, or in a disposable snapshot worktree when requested). Use when the user explicitly asks for `openspec-ext-hack-through-test`, points to `openspec/changes/...` while asking to propose, revise, run, exercise, or prepare work under hack-through-testing principles, or wants OpenSpec work shaped for fast blocker discovery through patch-forward testing.