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:
lgs build script.lgsThis creates a binary named script (your filename without .lgs)
in the current directory.
How It Works
Under the hood, lgs build does the following:
- Parses and validates your Logos code
- Creates a temporary Go project
- Generates a
main.gothat embeds your script as a string - Links in the Logos interpreter and standard library
- Runs
go buildto 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:
# Check Go is installed
go version
# go version go1.21+Example Workflow
From script to binary in a few commands:
# 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 stagingShebang Support
Add a shebang to make scripts directly executable. The shebang is ignored during build:
#!/usr/bin/env lgs
print("I can be run directly!")
print("And built into a binary too.")# Make executable
chmod +x hello.lgs
# Run directly
./hello.lgs
# Or build it
lgs build hello.lgs
./helloCustom Module Imports
If your script imports local modules, they're bundled automatically:
// In myapp.lgs
use "utils"
use "helpers"
print(formatMessage("Hello", "World"))// 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:
Built: myappThe 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:
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:
ls -la
# -rw-r--r-- myapp.lgs
# -rw-r--r-- utils.lgs
# -rw-r--r-- helpers.lgsGo 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.
