githubEdit

Cross-Compilation Guide

The spuff-agent runs on Linux cloud VMs, but you might develop on macOS or Windows. This guide covers cross-compiling the agent.

Overview

flowchart TB
    subgraph dev["Development Machine (macOS)"]
        code["Rust Code<br/>(src/agent/)"]
        zigbuild["cargo zigbuild<br/>--target x86_64-unknown-linux-gnu"]
        binary["target/x86_64-unknown-linux-gnu/<br/>release/spuff-agent<br/>(Linux ELF binary)"]

        code --> zigbuild --> binary
    end

    subgraph vm["Cloud VM (Linux)"]
        agent["/opt/spuff/spuff-agent"]
    end

    binary -->|"SCP / cloud-init"| agent

Install Zig

macOS:

Linux:

Verify:

Install cargo-zigbuild

Cross-Compile

The binary will be at:

Why zigbuild?

  • Uses Zig as a C compiler/linker

  • No need for cross-compilation toolchain

  • Works out of the box on macOS

  • Handles glibc linking properly

Using Docker (Alternative)

If you prefer Docker:

Or with a Dockerfile:

Using cross (Alternative)

Note: cross requires Docker.

Testing the Binary

Check Binary Type

Test on VM

Use spuff up --dev to upload and test your local agent:

The --dev flag:

  1. Creates VM normally

  2. Uploads local agent binary via SCP

  3. Restarts agent service

Manual Upload

Build Script

Create a build script for convenience:

Troubleshooting

Missing Target

Solution:

Zig Not Found

Solution: Install Zig (see above) and ensure it's in PATH.

glibc Version Mismatch

Solution: The VM has an older glibc. Options:

  1. Target an older glibc: cargo zigbuild --target x86_64-unknown-linux-gnu.2.17

  2. Use Ubuntu 24.04 images (has newer glibc)

Linking Errors

Solution: Ensure you're using cargo zigbuild not cargo build for cross-compilation.

CI/CD Integration

GitHub Actions

Supported Targets

Target
Architecture
Notes

x86_64-unknown-linux-gnu

x86-64 Linux

Primary target

aarch64-unknown-linux-gnu

ARM64 Linux

For ARM VMs

x86_64-unknown-linux-musl

x86-64 Linux (static)

No glibc dependency

Building for ARM64

Static Linking (musl)

Static binaries work on any Linux distribution but may be slightly slower.

Last updated

Was this helpful?