Skip to content

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.


To scaffold a brand new Flame library project, run:

Terminal window
fmp new --lib my_library

This 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 suite

For applications or binary executables, use standard fmp new my_app.


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"
  • type = "library" (or legacy "pkg"): Declares a reusable source package. Defaults entry point to src/lib.fm.
  • type = "executable": Declares a standalone application. Defaults entry point to src/main.fm (or configurable via [application].entry).

Flame enforces strict export boundaries. Only declarations explicitly annotated with export are made available to importing consumers:

src/lib.fm
package my_library
// Private to this package — cannot be accessed by consumers or external modules
let 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 types
export struct Config {
timeout_ms: Int
}

When consumers hover over your package name or imported functions in their IDE, Flame displays the documentation attached via @Docs annotations or doc comments (///):

src/lib.fm
@Docs("
# My Library
Fast, 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.


Package tests should test what consumers can import. In Flame test files under tests/, simply import your package by name:

tests/test_api.fm
import my_library
@Test
fn test_public_add() {
assertEq(my_library.add(10, 20), 30, "Should add correctly")
}
@Test
fn test_public_process() {
assertEq(my_library.process(8), 50, "Should process with internal seed")
}
@ExpectPanic
fn 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:

Terminal window
fmp test

Flame’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.


Flame includes a dedicated packaging command to validate source graphs and produce deterministic .fmp package archives:

  • 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:
    1. A verified package directory at target/pkg/<name>/.
    2. A deterministic .fmp zip archive at target/pkg/<name>.fmp.
  • fmp package --out <custom_path.fmp>: Specifies a custom output archive destination.

Example output:

$ fmp package --list
Package: 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:

Terminal window
# Inside your application directory:
fmp i ../my_library
# or
fmp install ../my_library
  1. Installs Whole Package: Links the entire package directory into .flame/pkg/my_library.
  2. Generates Interface Metadata: Automatically creates .flame/pkg/my_library/my_library.fmi.
  3. Live Updates for Tests & Development: On Unix systems, Flame creates a filesystem symlink so changes made in my_library are immediately live in your consumer app’s tests and runs without needing to reinstall.
  4. 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}")