# VXM Native Module Linking Architecture

VXM carries package declarations and semantic information between a producer
and its consumers. VRI embeds the runtime semantic image used by the compiler.
They solve different distribution problems, and each has its own identity and
compatibility checks.

## The Problem

Reusable packages need a way to supply declarations and implementation information to a consumer without requiring every build to repeat all work. An artifact format must also identify the compiler and semantic compatibility assumptions under which it can be consumed.

## The VXM Solution

VXM V2 package images expose a semantic inventory that the CLI can inspect and
verify. A consumer needs an image compatible with its compiler, target, and
package dependencies. An image is a typed package artifact, not a promise
that every consumer skips analysis or receives one pre-optimized bitcode file.

### Phase 1: Library Mode Compilation

A producer publishes an image for an identified package and compiler context.
Keep its locator, identity, dependency information, and verification material
together. Use `vex vxm --help` for the publication options exposed by the
producer toolchain; standard-library publication uses `publish-std`.

### Phase 2: Transparent Consumer Linking

Inspect and verify an image with a compatible compiler toolchain. The
`vex vxm` command group includes `publish-std`, `install-std`, `inspect`,
`verify`, `size`, `attach-origins`, and `attach-validations`. The first two
manage the standard-library distribution; the inspection commands let a
consumer examine an image before incorporating it into a build.

For an existing image-bearing package, inspect and validate without publishing:

```sh
vex vxm inspect ./package --json
vex vxm verify ./package --json
vex vxm size ./package
```

Replace `./package` with the package root, source, locator or immutable image
path supplied by the producer. `inspect` decodes inventory; `verify` must
succeed before the image is treated as structurally and semantically valid.
Publisher authentication additionally needs the trusted key/key-id inputs
shown by `vex vxm verify --help`; receiving an image does not itself establish
trust in its publisher. Compatibility with a concrete consumer still needs
that consumer's compile and behavior checks.

`attach-origins` and `attach-validations` enrich an image using consumer
compilations. They are not substitutes for compiler/target identity checks or
blanket proof for future consumers and flags.

### Link-Time Optimization (LTO) Integration

Do not assume that VXM implies LTO, cross-module inlining, a particular linker, a zero runtime cost, or a fixed LLVM version. A workspace LLVM dependency does not establish the backend version bundled
with a published release. Confirm compatibility and performance with that release's build metadata and a representative workload.

## Local Workspaces and Standard Library

Standard-library image publication and installation are separate operations
from runtime embedding. VRI embeds VexArch semantic sources into the compiler
for the path described in [Runtime Architecture](../../architecture/runtime-architecture.md#runtime-semantic-image-and-fusion).
Inspect the selected package to learn which artifacts its distribution carries.

| Artifact | Role | Consumer responsibility |
| --- | --- | --- |
| VXM V2 package image | Portable package and semantic inventory; `.vxm/package.vxm2` appears as a package locator | Package-specific publication, validation, and source-free consumption need their own tests. |
| VRI runtime image | Embedded VexArch runtime semantic source image | Separate from a package image or a linked bitcode library; see the runtime architecture page. |
| Native object or final executable | Target-specific code produced and linked by a build | Target, linker, features, and release packaging must be verified separately. |

For implementation details, start with `tools/vex-cli/src/commands/vxm.rs`, `crates/vex-vir/src/`, and `tools/vex-cli/src/runtime_image.rs` in the matching source checkout. Match those source paths to the toolchain whose artifacts you are inspecting.
