Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build.zig): cross-compile, install, and run on remote hosts over ssh #535

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dnut
Copy link
Contributor

@dnut dnut commented Feb 4, 2025

This makes it easy to use zig build to target a remote host while building, installing, and running executables.

Examples

Cross-compile all binaries for a remote host called myec2's build target and install them on that host:

zig build -Dssh-host=myec2

Compile, install, and run sig on myec2:

zig build -Dssh-host=myec2 sig -- gossip -n testnet

Run the tests on myec2:

zig build -Dssh-host=myec2 test

How it works

Determine the build target: ssh.getHostTarget - SSH into the server, run zig targets, then parse the json.

Install to the remote host: ssh.addSendArtifact - Analogous to Build.addInstallArtifact, except that it installs on a remote server. Uses Build.addSystemCommand to call rsync if installed, falling back to scp. rsync is preferred since it uses checksums to avoid redundant uploads. This depends on an InstallArtifact step.

Run on the remote host: ssh.addRemoteCommand - Analogous to Build.addSystemCommand, except that it runs on a remote host. Uses Build.addSystemCommand to run ssh.

CLI arguments

  -Dssh-host=[string]          Builds will target this remote host, binaries will be installed there, and executables will run there.
  -Dssh-installdir=[string]    When using ssh-host, this configures the directory to install binaries (relative to ssh-workdir) (default: zig-out/bin).
  -Dssh-workdir=[string]       When using ssh-host, this configures the working directory where executables will run (default: sig).

This is also compatible with no-run and no-bin. Those options will be respected when deciding whether to install or run the binary on the remote host, with one exception. If you specify only no-bin for an artifact that needs to run on the remote host, then it will still install the artifact, because that is necessary in order to run it.

@dnut dnut requested review from 0xNineteen and kprotty February 4, 2025 19:26
@dnut dnut marked this pull request as ready for review February 4, 2025 19:26
@dnut dnut self-assigned this Feb 4, 2025
@InKryption InKryption self-requested a review February 5, 2025 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant