# Installation

This guide targets Vex 0.4.0. Install the compiler package for your operating
system and CPU architecture, then check the executable before creating a
project. A release candidate such as `0.4.0-rc.39` is a different artifact from
the final `0.4.0` package; see [Versioning](versioning.md).

## Install a compiler package

1. Open the [download page](https://www.vex-lang.org/download) or the
   [official release list](https://github.com/vex-org/releases/releases).
2. Select a **Vex compiler** release and the archive matching your machine.
   Vex HDL Studio is a separate application and does not replace the compiler
   package used in this guide.
3. Download the archive and its matching checksum file when provided. Compare
   the archive's SHA-256 with that file before extracting it.
4. Keep the extracted package together, including its bundled libraries and
   tools. Add the directory containing the `vex` executable to `PATH` using
   your shell's configuration.
5. Start a new shell and run:

```bash
vex --version
vex --help
```

The version should match the package you selected. If an older version appears,
check which executable your shell resolves (`command -v vex` in a POSIX shell,
or `Get-Command vex` in PowerShell). If no matching archive is listed, use a
supported release target or the source-build route below; do not substitute an
archive for a different CPU architecture.

On macOS or Linux, a checksum file in the usual `SHA256  filename` format can
be checked from the download directory with `shasum -a 256 -c filename.sha256`
or `sha256sum -c filename.sha256`, respectively. Replace `filename.sha256`
with the actual downloaded name. In PowerShell, use `Get-FileHash -Algorithm
SHA256` on the archive and compare the result with the published digest.

Continue with [Your first project](first-project.md) once the compiler
starts successfully. The remaining build instructions are for contributors
and users with access to a source checkout.

## Requirements for a source build

To build the compiler from a checkout, you need:

- a Rust toolchain with Cargo that supports the checkout's Rust 2024 edition;
- the LLVM 23.1 toolchain selected by this checkout's `llvm-sys` 231 bindings,
  including the corresponding development libraries;
- a native linker for your operating system;
- Git to obtain the repository.

The workspace manifest and release workflow define the dependency versions for
a particular source revision. The current LLVM binding uses
`LLVM_SYS_231_PREFIX` to locate an installed LLVM toolchain. Do not mix an LLVM
16, 21, or 22 installation with bindings configured for LLVM 23.1. See
[Contributing](contributing.md) for the build environment and focused checks.

## Build from source

This route requires an accessible source checkout and its dependencies. The
previously listed repository URL is not confirmed to be publicly accessible;
obtain access to the checkout from the project maintainer before using the
commands below. From the checkout root:

~~~bash
cargo build --release -p vex-cli --target-dir target
~~~

The explicit `--target-dir target` places the release binary at
`target/release/vex` (`vex.exe` on Windows). Without this option, the checkout
configuration currently uses `.vex/cargo-target`; `CARGO_TARGET_DIR` can also
change the location. Confirm the build before using it:

~~~bash
target/release/vex --version
target/release/vex --help
~~~

For a faster edit-check cycle, use the debug build instead:

~~~bash
cargo build -p vex-cli --target-dir target
target/debug/vex lint examples/01_basics/hello_world.vx
~~~

## Run a first program

Create hello.vx:

~~~vex [hello.vx]
fn main(): i32 {
    $println("Hello, Vex!");
    return 0;
}
~~~

Then check and run it:

~~~bash
vex lint hello.vx
vex run hello.vx
~~~

These commands assume the selected executable is on `PATH`; source-build users
can use `target/release/vex` instead. The program prints `Hello, Vex!` and exits
with status 0. Use `lint` while writing code: it performs correctness and
configured lint analysis without creating a final executable. Use `run` to
build a temporary executable and launch it.

> **warning Native execution is a separate gate**
`vex lint` does not emit an object, link, or execute the program. `vex run`
uses the fused embedded VexArch image plus the requested target's native
support and system ABI, so validate that path on the exact deployment target.


## Command-line tools

The compiler currently exposes these high-level commands:

| Command | Purpose |
| --- | --- |
| `vex lint [target]` | Run correctness analysis, semantic lints and verified fixes without code generation. |
| `vex run <file>` | Compile and run a source file. |
| `vex compile <file>` | Compile and link a persistent artifact. |
| vex build | Build a Vex package or project. |
| vex test | Discover and run Vex tests. |
| vex format | Format Vex source. |
| vex doc | Generate API documentation from Vex source. |
| vex view | Inspect compiler representations and analyses. |
| vex new / vex init | Create or initialize a project. |
| vex mod / vex workspace | Manage module and workspace workflows. |
| vex env / vex setup | Inspect or initialize the Vex environment. |

Run `vex <command> --help` for the options supported by the binary you built. The [CLI reference](../references/vex-cli-reference.md) describes the command surface in more detail.

## Project layout

The current `vex new my-project` scaffold creates this layout:

~~~text
my-project/
├── vex.json
├── src/
│   └── lib.vx
└── tests/
    └── lib_test.vx
~~~

From the project directory, the scaffold's starter source can be selected with
`vex run src/lib.vx`; `vex test` discovers the test file. The [first-project guide](first-project.md) develops and tests that scaffold
with a second module. For manifest details,
start with the [package manager reference](../references/vex-pm-reference.md).

## Editor support

The repository includes an LSP implementation and a VS Code extension under editors/vscode. Build the LSP server with:

~~~bash
cargo build --release -p vex-lsp --target-dir target
~~~

The resulting binary is target/release/vex-lsp. Configure your editor to start it for .vx files. LSP capabilities and editor integration are evolving alongside the compiler, so treat advanced refactoring features as experimental.

## Troubleshooting

### LLVM or Clang is not found

Install the development packages for your operating system and ensure the compiler can find them through the environment used by Cargo. On macOS, the Xcode Command Line Tools are usually required. On Linux, install the distribution's LLVM, Clang, and development packages.

### The binary fails before printing its version

A missing dynamic library can prevent a compiler binary from starting. Record
the loader's missing library name and the binary's origin, then use a matching
release/toolchain or rebuild from an accessible source checkout. This failure
occurs before Vex can check your program.

### The compiler accepts a file but linking fails

`lint` and `compile` exercise different parts of the toolchain. A successful
lint run establishes that the source passed the selected analysis; it does not
establish that target linking or native dependencies are available. Retain the
full compiler output and the target triple when reporting the failure.

### An example does not match your checkout

Check the compiler version first:

~~~bash
target/release/vex --version
git rev-parse --short HEAD
~~~

The documentation site follows the repository's current development line. Pin both the compiler revision and the documentation revision in CI when reproducibility matters.

## Next steps

- [Introduction](introduction.md)
- [Your first project](first-project.md)
- [Language Status](language-status.md)
- [Syntax](basics/syntax.md)
- [Testing](tooling/testing.md)
- [CLI Reference](../references/vex-cli-reference.md)
