Arquivos .zar e .zex
Nesta página
O zolo build suporta dois formatos de saída baseados em ZIP:
.zar(Zolo ARchive) — arquivo de biblioteca. Agrupa bytecode e assets para ser reutilizado como dependência por outros projetos..zex(Zolo EXecutable archive) — arquivo executável. Empacota o programa inteiro e pode ser executado comzolo run.
Um arquivo .zar é gerado com a flag --emit zar. O arquivo ainda pode ser
executado diretamente com zolo run (os statements de nível superior rodam),
mas seu propósito principal é ser linkado como dependência:
pub fn exporta símbolos; zolo build --emit zar gera o arquivo reutilizável.
// 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
Requer a CLI/host do Zolo — abra no playground ou rode localmente.
Para empacotar um programa como executável portátil, use --emit zex. O
.zex produzido ainda depende do zolo instalado na máquina destino — mas
elimina a necessidade de distribuir o código-fonte:
zolo build --emit zex empacota; zolo run target/app.zex executa sem fonte.
// 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
Requer a CLI/host do Zolo — abra no playground ou rode localmente.
Desafio
Crie um arquivo util.zolo com uma função pub fn greet(name: str) -> str e
compile-o com --emit zar. Em seguida, escreva um segundo arquivo que importe
o .zar gerado e chame greet.
Veja também