Skip to content

Projects & Imports ​

Neo supports multi-file hardware projects using a neo.toml manifest, module-path import declarations, and explicit pub visibility.

Project Manifest (neo.toml) ​

Place a neo.toml file at the root of your project directory:

toml
[project]
root = "src"
entry = "src/main.neo"
  • [project].root (optional, defaults to "src"): Base directory for root-relative module imports.
  • [project].entry (optional, defaults to <root>/main.neo): Default entry file when running neo check or neo build on a project directory or neo.toml.
  • Top-level root or entry keys outside [project] are rejected as invalid schema.

When running neo check path/to/file.neo or neo build path/to/file.neo:

  1. Neo walks upward from the target file or directory looking for neo.toml.
  2. If found, root comes from [project].root (or <manifest_dir>/src) unless overridden with --root <dir>.
  3. If no neo.toml exists, the entry file's parent directory serves as the import root (unless --root <dir> is supplied).

Visibility: pub and pub import ​

Top-level declarations (enum, struct, union, interface, module) are private to their file by default. Mark a declaration pub to allow other files to import it:

neo
// src/types.neo
pub enum Op {
  Add = 0,
  Sub = 1,
}

pub struct Pair {
  a: Int(32),
  b: Int(32),
}

// Private helper — cannot be imported by other files
struct InternalTemp {
  v: Bits(8),
}

Attempting to import a non-pub symbol produces a private_import error with related span information pointing to its declaration.

You can re-export imported symbols from another file using pub import:

neo
// src/reexport.neo
pub import types::Pair as ReexportedPair;

Import Syntax & Path Resolution ​

Import statements appear at the top of a .neo file and use ::-separated module paths:

neo
// Single item import
import types::Op;

// Renamed import using `as`
import types::Op as AluOp;

// Grouped imports from the same file
import types::{Op, Pair as DataPair};

// Nested directory module (resolves to `<root>/alu/adder.neo`)
import alu::adder::Alu;

// Relative to the current file's directory (`self::`)
import self::helpers::Mux2;

// Relative to parent directories (`super::`, repeatable)
import super::common::{Word, Byte};

Path Resolution Rules ​

  • Root-relative (foo::bar::Item): Resolves to <root>/foo/bar.neo and imports Item.
  • Sibling-relative (self::foo::Item): Resolves to <current_file_dir>/foo.neo.
  • Parent-relative (super::...::foo::Item): Pops one directory per leading super:: from <current_file_dir>, then resolves foo.neo.
  • Sandboxed to root: Any resolved import path that escapes <root> (e.g., too many super:: segments) is rejected.
  • Acyclic dependency graph: Circular file imports are detected and reported cleanly during workspace loading, while forward references within the same file are supported.

Example Layout ​

text
my-project/
├── neo.toml
└── src/
    ├── main.neo          # Entry file with @top module
    ├── types.neo         # pub enum / pub struct definitions
    ├── reexport.neo      # pub import re-exports
    └── alu/
        └── adder.neo     # pub module Alu

Run neo check or neo build --format sv from my-project/ and Neo automatically discovers neo.toml, resolves the transitive import graph, checks all files in topological order, and elaborates every @top module in src/main.neo.