Skip to content
Logos / Building Binaries

Building Binaries

Turn your Logos scripts into standalone executables. No Logos installation required on target machines — just run the binary.

Build Command

Run lgs build with your script:

bash
lgs build script.lgs

This creates a binary named script (your filename without .lgs) in the current directory.

How It Works

Under the hood, lgs build does the following:

  1. Parses and validates your Logos code
  2. Creates a temporary Go project
  3. Generates a main.go that embeds your script as a string
  4. Links in the Logos interpreter and standard library
  5. Runs go build to produce a native executable

The resulting binary is fully self-contained. It includes the Logos interpreter, your script, and the stdlib — everything bundled together.

Requirements

Building requires Go to be installed. The build process uses go build internally:

bash
# Check Go is installed
go version
# go version go1.21+

Example Workflow

From script to binary in a few commands:

bash
# 1. Write your script
cat > deploy.lgs << 'EOF'
let version = "1.2.0"
let target = args()[1]

print("Deploying ${version} to ${target}...")

let res = httpGet("https://api.example.com/health")
if res.ok {
    print("Server healthy, deploying...")
} else {
    print("Error: Server not ready")
    exit(1)
}

print("Deployment complete!")
EOF

# 2. Test with Logos interpreter
lgs deploy.lgs staging

# 3. Build to binary
lgs build deploy.lgs

# 4. Distribute and run the binary
./deploy staging

Shebang Support

Add a shebang to make scripts directly executable. The shebang is ignored during build:

hello.lgs
#!/usr/bin/env lgs

print("I can be run directly!")
print("And built into a binary too.")
bash
# Make executable
chmod +x hello.lgs

# Run directly
./hello.lgs

# Or build it
lgs build hello.lgs
./hello

Custom Module Imports

If your script imports local modules, they're bundled automatically:

myapp.lgs
// In myapp.lgs
use "utils"
use "helpers"

print(formatMessage("Hello", "World"))
utils.lgs
// utils.lgs — in the same directory
let formatMessage = fn(prefix, name) {
    return "${prefix}, ${name}!"
}

Local modules (use "mymodule") must be in the same directory as the main script. Standard library imports (use "std/array") are always included.

Output

On success, you see the output filename:

text
Built: myapp

The binary is created in your current working directory. Move it anywhere and run it — no Logos installation needed.

Troubleshooting

Parse errors

Your script is validated before building. Fix syntax errors:

bash
lgs build script.lgs
# Error: parse error at line 5: unexpected token '}'

Module not found

Ensure all use "modulename" imports exist in the same directory:

bash
ls -la
# -rw-r--r--  myapp.lgs
# -rw-r--r--  utils.lgs
# -rw-r--r--  helpers.lgs

Go not found

Install Go first: https://go.dev/doc/install

Binary too large

Binary size is typically 10-20MB depending on platform. This includes the full interpreter. For comparison, a "hello world" in C is ~15KB; a Logos binary includes the runtime.