Saltar al contenido

Archivos .zar y .zex

En esta página

zolo build admite dos formatos de salida basados en ZIP:

  • .zar (Zolo ARchive) — archivo de biblioteca. Agrupa bytecode y assets para ser reutilizado como dependencia por otros proyectos.
  • .zex (Zolo EXecutable archive) — archivo ejecutable. Empaqueta el programa completo y puede ejecutarse con zolo run.

Un archivo .zar se genera con la flag --emit zar. El archivo aún puede ejecutarse directamente con zolo run (los statements de nivel superior se ejecutan), pero su propósito principal es enlazarse como dependencia:

pub fn exporta símbolos; zolo build --emit zar genera el archivo reutilizable.

01-zar-library.zolo
Playground
// 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

Requiere la CLI o el host de Zolo; ábrelo en el playground o ejecútalo localmente.

Para empaquetar un programa como ejecutable portátil, usa --emit zex. El .zex generado aún depende de que zolo esté instalado en la máquina destino — pero elimina la necesidad de distribuir el código fuente:

zolo build --emit zex empaqueta; zolo run target/app.zex ejecuta sin fuente.

02-zex-executable.zolo
Playground
// 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

Requiere la CLI o el host de Zolo; ábrelo en el playground o ejecútalo localmente.

Desafío

Crea un archivo util.zolo con una función pub fn greet(name: str) -> str y compílalo con --emit zar. Luego escribe un segundo archivo que importe el .zar generado y llame a greet.

Buscar en Zolo

9 resultados

enespt-br