feat(build.zig): cross-compile, install, and run on remote hosts over ssh #535
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:Compile, install, and run sig on
myec2
:Run the tests on
myec2
:zig build -Dssh-host=myec2 test
How it works
Determine the build target:
ssh.getHostTarget
- SSH into the server, runzig targets
, then parse the json.Install to the remote host:
ssh.addSendArtifact
- Analogous toBuild.addInstallArtifact
, except that it installs on a remote server. UsesBuild.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 toBuild.addSystemCommand
, except that it runs on a remote host. UsesBuild.addSystemCommand
to run ssh.CLI arguments
This is also compatible with
no-run
andno-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 onlyno-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.