Skip to content

.zar and .zex Files

On this page

zolo build supports two ZIP-based output formats:

  • .zar (Zolo ARchive) — library archive. Bundles bytecode and assets to be reused as a dependency by other projects.
  • .zex (Zolo EXecutable archive) — executable archive. Packages the entire program and can be run with zolo run.

A .zar file is generated with the --emit zar flag. The file can still be run directly with zolo run (top-level statements execute), but its main purpose is to be linked as a dependency:

pub fn exports symbols; zolo build --emit zar generates the reusable archive.

01-zar-library.zolo
// Feature: library archive — `zolo build --emit zar`

// Syntax: `zolo build file.zolo --emit zar`

// When to use: package reusable code as a `.zar` (Zolo ARchive) that

//   other Zolo programs can depend on / link against.


// Run:

//   zolo build 31-distribution/01-zar-library.zolo --emit zar

//   # -> Built target/01-zar-library-0.0.0.zar (...)

//

// A `.zar` is a ZIP-based container (alongside `.zbc` bytecode and the

// `.zex` executable archive). It bundles the module's bytecode + any

// assets/manifest so it can be shipped and reused as a dependency.


pub fn add(a: int, b: int) -> int {
  return a + b
}

pub fn mul(a: int, b: int) -> int {
  return a * b
}

// A library file still runs on its own (the top-level statements execute):

print("add(2, 3) =", add(2, 3))
print("mul(2, 3) =", mul(2, 3))

// See ../../../specs/zar-zex-archives.md for the container format.

// expected:

//   add(2, 3) =	5

//   mul(2, 3) =	6

Requires the Zolo CLI/host — open in the playground or run locally.

To package a program as a portable executable, use --emit zex. The resulting .zex still depends on zolo being installed on the target machine — but eliminates the need to distribute the source code:

zolo build --emit zex packages it; zolo run target/app.zex runs it without source.

02-zex-executable.zolo
// Feature: executable archive — `zolo build --emit zex`

// Syntax: `zolo build file.zolo --emit zex`

// When to use: ship a single runnable `.zex` (Zolo EXecutable archive)

//   that `zolo run` can execute directly.


// Run:

//   zolo build 31-distribution/02-zex-executable.zolo --emit zex

//   # -> Built target/02-zex-executable-0.0.0.zex (...)

//   zolo run target/02-zex-executable-0.0.0.zex

//   # -> runs the program below

//

// A `.zex` packages bytecode + assets into one ZIP-based file. Unlike a

// native `zolo build`, a plain `.zex` still needs the `zolo` runtime to

// execute it — use `--standalone` (see 03) to embed the runtime and make

// it self-contained.


print("This program was shipped as a .zex archive.")
for i in 1..=3 {
  print("  tick", i)
}

// expected:

//   This program was shipped as a .zex archive.

//     tick	1

//     tick	2

//     tick	3

Requires the Zolo CLI/host — open in the playground or run locally.

Challenge

Create a util.zolo file with a pub fn greet(name: str) -> str function and compile it with --emit zar. Then write a second file that imports the generated .zar and calls greet.

Search Zolo

9 results

enespt-br