Creating Flame Packages & Libraries
Creating a package in Flame allows you to bundle reusable Flame code, modules, interfaces, and native Rust plugins into a single, distributable unit. Consumers and test suites can import packages directly through clean, public interfaces with zero internal path leakage.
1. Scaffolding a Library (fmp new --lib)
Section titled “1. Scaffolding a Library (fmp new --lib)”To scaffold a brand new Flame library project, run:
fmp new --lib my_libraryThis generates a library project structure with canonical manifest settings, a library entry point (src/lib.fm), and an automated public API test harness (tests/test_api.fm):
my_library/├── flame.toml # Manifest configured with type = "library"├── src/│ └── lib.fm # Public library entry point└── tests/ └── test_api.fm # Automated package test suiteFor applications or binary executables, use standard fmp new my_app.
2. Package Configuration (flame.toml)
Section titled “2. Package Configuration (flame.toml)”Libraries are declared with type = "library" under [package] and specify their primary entry point in [lib]:
[package]name = "my_library"version = "0.1.0"edition = "2026"type = "library"
[lib]path = "src/lib.fm"
[options]rust-plugins = "default"closure-types = "default"
# Optional: define local native Rust plugins bundled with this package[plugins]native_core = "./native"Manifest Conventions:
Section titled “Manifest Conventions:”type = "library"(or legacy"pkg"): Declares a reusable source package. Defaults entry point tosrc/lib.fm.type = "executable": Declares a standalone application. Defaults entry point tosrc/main.fm(or configurable via[application].entry).
3. Strict Export Boundaries & Visibility
Section titled “3. Strict Export Boundaries & Visibility”Flame enforces strict export boundaries. Only declarations explicitly annotated with export are made available to importing consumers:
package my_library
// Private to this package — cannot be accessed by consumers or external moduleslet internal_seed = 42
fn private_helper(val: Int) -> Int { return val + internal_seed}
// Public API — visible to consumers@Docs("Computes the sum of two integers.")export fn add(a: Int, b: Int) -> Int { return a + b}
@Docs("Processes input using the package's internal engine.")export fn process(input: Int) -> Int { return private_helper(input)}
// Export custom structs and typesexport struct Config { timeout_ms: Int}4. Documenting Packages with @Docs
Section titled “4. Documenting Packages with @Docs”When consumers hover over your package name or imported functions in their IDE, Flame displays the documentation attached via @Docs annotations or doc comments (///):
@Docs("# My LibraryFast, lightweight algorithms and data structures for Flame applications.")package my_library
@Docs("Calculates factorial of a positive integer.")export fn factorial(n: Int) -> Int { if n <= 1 { 1 } else { n * factorial(n - 1) }}Hovering over import my_library or my_library.factorial shows markdown documentation directly in the editor hover card.
5. Testing the Public Package Interface
Section titled “5. Testing the Public Package Interface”Package tests should test what consumers can import. In Flame test files under tests/, simply import your package by name:
import my_library
@Testfn test_public_add() { assertEq(my_library.add(10, 20), 30, "Should add correctly")}
@Testfn test_public_process() { assertEq(my_library.process(8), 50, "Should process with internal seed")}
@ExpectPanicfn test_private_symbols_blocked() { // Attempting to access private symbols panics with missing property error let _ = my_library.private_helper}Run tests from the package root:
fmp testFlame’s module resolver automatically resolves import my_library to src/lib.fm as declared in your flame.toml. You never need to write import src.main or import main.
6. The Packaging Pipeline (fmp package)
Section titled “6. The Packaging Pipeline (fmp package)”Flame includes a dedicated packaging command to validate source graphs and produce deterministic .fmp package archives:
Inspection & Validation Flags:
Section titled “Inspection & Validation Flags:”fmp package --list: Displays all source files and public exports that will be included in the package.fmp package --check: Recursively parses and validates all source files, ensures exports are valid, and validates dependency declarations without building an archive.fmp package: Validates the entire package graph and emits:- A verified package directory at
target/pkg/<name>/. - A deterministic
.fmpzip archive attarget/pkg/<name>.fmp.
- A verified package directory at
fmp package --out <custom_path.fmp>: Specifies a custom output archive destination.
Example output:
$ fmp package --listPackage: my_library (type: library)Entry point: src/lib.fm
Source files (1): • src/lib.fm
Public exports (2): • export fn add (src/lib.fm) • export fn process (src/lib.fm)7. Local Package Dependencies & Live Updates (fmp i <path>)
Section titled “7. Local Package Dependencies & Live Updates (fmp i <path>)”To use your local library inside another Flame application during development:
# Inside your application directory:fmp i ../my_library# orfmp install ../my_libraryWhat Flame Does:
Section titled “What Flame Does:”- Installs Whole Package: Links the entire package directory into
.flame/pkg/my_library. - Generates Interface Metadata: Automatically creates
.flame/pkg/my_library/my_library.fmi. - Live Updates for Tests & Development: On Unix systems, Flame creates a filesystem symlink so changes made in
my_libraryare immediately live in your consumer app’s tests and runs without needing to reinstall. - Records in Manifest: Adds the local dependency to
flame.toml:[dependencies]my_library = "../my_library"
Consumers can immediately write:
// In consumer app src/main.fm or tests/test_app.fm:import my_library
let result = my_library.add(100, 25)println($"Result: {result}")