# Contributing to Vex

A useful contribution connects an observable behavior to a focused change and
its verification. Language and standard-library changes should update the
public examples that teach that behavior as well as the implementation tests.

## Building from Source

Use a source checkout you can access. Compiler packages are distributed through
the [official release repository](https://github.com/vex-org/releases/releases);
that repository is not itself a compiler source checkout. Check the source
revision's build instructions before installing dependencies.

### Prerequisites

| Component | Requirement for the inspected 0.4.0 source line |
| --- | --- |
| Rust and Cargo | Rust 2024 edition support; the release workflow selects the stable Rust toolchain. No lower minimum Rust version is declared here. |
| LLVM | LLVM 23.1, matching `llvm-sys` 231 and the configured LLVM backend. |
| Native toolchain | A C compiler, linker, SDK or development headers appropriate to the host and target. |
| Git | Access to the checkout and its required submodules or local dependency forks. |

`Cargo.toml` owns compiler dependency selection. `.github/workflows/release.yml`
records the concrete release build environments. A distribution package called
`llvm` may install a different major version; inspect `llvm-config --version`
from the selected installation rather than assuming the package name is enough.

### Select LLVM

Set `LLVM_SYS_231_PREFIX` to the LLVM 23.1 installation directory, not its `bin`
subdirectory. For example, in a POSIX shell:

```bash
export LLVM_SYS_231_PREFIX=/absolute/path/to/llvm-23.1
export PATH="$LLVM_SYS_231_PREFIX/bin:$PATH"
llvm-config --version
clang --version
rustc --version
cargo --version
```

The macOS release workflow uses Homebrew's `llvm@23` and the platform SDK. The
Linux workflow installs versioned LLVM/Clang 23 development packages. The
Windows workflow uses an identified LLVM 23.1 toolchain and the Windows native
build environment. These are build recipes, not evidence that an arbitrary
host or cross target has passed the release tests.

### Build the command-line tools

From the checkout root:

```bash
cargo build -p vex-cli --target-dir target
target/debug/vex --version
cargo build --release -p vex-cli --target-dir target
target/release/vex --version
```

Use `.exe` on Windows. The explicit target directory keeps these paths
predictable; without it the checkout currently defaults to `.vex/cargo-target`
and an environment override may select another location. Keep separate build
directories when working in multiple checkouts.

For editor integration, build `vex-lsp` with the same toolchain. A debug profile
may be configured without debug symbols in this checkout; inspect the selected
Cargo profile before relying on source-level debugger information.

## Project Structure

| Path | Responsibility |
| --- | --- |
| `crates/vex-lexer`, `vex-parser`, `vex-syntax` | Tokens, concrete syntax, and syntax-tree APIs. |
| `crates/vex-hir` | Typed representation, inference, ownership, borrowing, and compile-time semantics. |
| `crates/vex-sir` | Data-parallel representation, transformations, and backend lowering. |
| `crates/vex-compiler` | Compilation orchestration and code generation. |
| `lib/runtime/VexArch` | Runtime and prelude sources used by the compiler. |
| `lib/std` | Standard-library packages and their tests. |
| `tools/vex-cli` | User-facing commands and their execution paths. |
| `tools/vex-pm`, `vex-doc`, `vex-lsp` | Package management, API documentation, and editor services. |
| `web/documentation/docs` | Public language, library, and tooling documentation. |
| `tests`, `examples`, `docs` | Integration/regression cases, examples, and internal design records. |

## Running Tests

Begin with the component that owns the behavior. For example:

```bash
cargo test -p vex-parser --target-dir target
cargo test -p vex-hir --target-dir target test_name
cargo test -p vex-compiler --target-dir target test_name -- --nocapture
```

Replace `test_name` with the relevant Rust test filter and inspect how many
tests actually ran. A filtered command that selects zero tests is not a passing
regression check.

For Vex test files, use the compiled CLI:

```bash
target/release/vex test --run '^test_add_bonus$' tests/lib_test.vx
```

This command illustrates path selection and test-name filtering; use an actual
file in the checkout or the example from [Your first project](first-project.md).
The [testing guide](tooling/testing.md) explains assertions, context tests,
timeouts, and result reporting.

Broaden testing according to the change: syntax changes affect parser and
semantic users; ownership changes need accepted and rejected examples;
code-generation changes need native execution; platform changes need the
actual target. Consult the current repository checks rather than a fixed
historical test count.

## Debugging the Compiler

Keep the smallest input that preserves the behavior and record the phase that
fails: analysis, object generation, linking, or program execution.

```bash
target/debug/vex lint problematic.vx
target/debug/vex compile --emit-llvm problematic.vx
RUST_BACKTRACE=1 target/debug/vex run problematic.vx
```

The last environment-assignment form is for POSIX shells. Set the equivalent
environment variable in your shell on other platforms. Backtraces describe the
compiler process; they do not replace a debugger or runtime diagnostic for the
compiled Vex program.

## Contribution Workflow

1. Reproduce the behavior on an identified source revision and compiler.
2. Agree on the expected language or API contract using the relevant tests and
   design record. Record ambiguity before changing observable behavior.
3. Keep the change focused and preserve unrelated work in the checkout.
4. Add a regression that distinguishes the old behavior from the intended one.
5. Run the affected checks and report their scope, including any untested
   targets or blocked commands.
6. Update the public examples and reference text affected by the change.
7. Submit a description of the problem, resulting behavior, and validation.

Follow the checked-out repository's contribution and `AGENTS.md` instructions
for style and workflow. A public tutorial does not override those local rules.

## Documentation

The [public documentation repository](https://github.com/vex-org/documentation)
contains the website and these guides. Use it for documentation changes; compiler
source access is separate from this repository and the binary release repository.

A complete example should say where its files go, which directory commands run
from, what stdout and exit status to expect, and which inputs or failure paths
it demonstrates. Mark schematic fragments before the code block and identify
application-provided names. Do not label Rust or pseudocode as executable Vex.

From `web/documentation`, the website provides these existing checks:

```bash
bun run docs:bundle:check
bun run build
bun run docs:fragments:check
```

The build regenerates documentation output and checks generated local page and
fragment targets. It does not establish native example behavior or external
link availability. The website README lists the focused example checks; the
[verification guide](verification-evidence.md) explains how to retain their
compiler identity and results.

## Reporting a problem

Include the source or a minimal reproduction, exact command, compiler version,
source revision when available, operating system and architecture, and complete
stdout/stderr. For a website issue, include the page URL, fragment, and the
navigation path that failed.

For documentation and website problems, search the
[documentation issue tracker](https://github.com/vex-org/documentation/issues)
before opening a report. Include the incorrect text or example, its expected
behavior, and any compiler result that helped identify the discrepancy.

For compiler, runtime, or library implementation problems, use the issue or
feedback channel supplied with the relevant release or source access. The
documentation repository is not presented as the compiler's issue tracker.

<!-- Retain useful older contribution links. -->
<a id="macos"></a>
<a id="linux-ubuntu-debian"></a>
<a id="linux-fedora"></a>
<a id="full-test-suite"></a>
<a id="subset-of-tests"></a>
<a id="running-individual-vex-files"></a>
<a id="emitting-llvm-ir"></a>
<a id="rust-backtrace"></a>
<a id="debugging-with-lldb"></a>
<a id="logging"></a>
<a id="code-conventions"></a>
<a id="getting-help"></a>
<a id="best-practices"></a>
