Skip to content

Commit 15951e0

Browse files
committed
Add github action to build binaries
1 parent 7f3a624 commit 15951e0

File tree

4 files changed

+229
-8
lines changed

4 files changed

+229
-8
lines changed

.github/workflows/release.yaml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
commit_sha:
10+
description: Git commit sha, on which, to run this workflow
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
jobs:
17+
build_and_test:
18+
name: Build and Test Binaries
19+
strategy:
20+
matrix:
21+
include:
22+
- target: aarch64-apple-darwin
23+
host_operating_system: macos-14
24+
use_cross: false
25+
test_method: native
26+
27+
- target: x86_64-apple-darwin
28+
host_operating_system: macos-14
29+
use_cross: false
30+
test_method: native
31+
32+
- target: x86_64-unknown-linux-gnu
33+
host_operating_system: ubuntu-22.04
34+
use_cross: false
35+
test_method: native
36+
37+
- target: x86_64-unknown-linux-musl
38+
host_operating_system: ubuntu-22.04
39+
use_cross: true
40+
test_method: native
41+
42+
- target: aarch64-unknown-linux-gnu
43+
host_operating_system: ubuntu-22.04
44+
use_cross: true
45+
test_method: qemu
46+
qemu_architecture: aarch64
47+
48+
- target: aarch64-unknown-linux-musl
49+
host_operating_system: ubuntu-22.04
50+
use_cross: true
51+
test_method: qemu
52+
qemu_architecture: aarch64
53+
54+
- target: armv7-unknown-linux-musleabihf
55+
host_operating_system: ubuntu-22.04
56+
use_cross: true
57+
test_method: qemu
58+
qemu_architecture: arm
59+
60+
runs-on: ${{ matrix.host_operating_system }}
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
64+
with:
65+
ref: ${{ github.event.inputs.commit_sha }}
66+
67+
- name: Setup rust toolchain
68+
run: |
69+
rustup show
70+
rustup target add ${{ matrix.target }}
71+
72+
- name: Install build dependencies
73+
if: matrix.host_operating_system == 'ubuntu-22.04'
74+
run: |
75+
set -x
76+
77+
if [ "${{ matrix.use_cross }}" == "true" ]; then
78+
cargo install cross --git https://github.com/cross-rs/cross
79+
else
80+
sudo apt-get update
81+
sudo apt-get install -y --no-install-recommends \
82+
gcc g++ libclang-dev xz-utils liblz4-tool musl-tools
83+
fi
84+
85+
if [ "${{ matrix.test_method }}" == "qemu" ]; then
86+
sudo apt-get update
87+
sudo apt-get install -y qemu-user-static
88+
89+
# Install libraries needed for QEMU to properly execute dynamically
90+
# linked binaries for the target architectures.
91+
if [ "${{ matrix.qemu_architecture }}" == "aarch64" ]; then
92+
sudo apt-get install -y libc6-dev-arm64-cross
93+
elif [ "${{ matrix.qemu_architecture }}" == "arm" ]; then
94+
sudo apt-get install -y libc6-dev-armhf-cross
95+
fi
96+
fi
97+
98+
- name: Build binary
99+
run: |
100+
set -ex
101+
cd source/rust/autonomy_command
102+
103+
# Build the compile tool first (natively for the host)
104+
# This must be done before setting RUSTFLAGS=+crt-static to avoid
105+
# the Rust compiler bug where proc-macros cannot be built with static
106+
# linking https://github.com/rust-lang/rust/issues/78210
107+
cargo build --bin compile
108+
109+
# Set RUSTFLAGS for musl targets only when building the target binary
110+
# The compile tool will use these flags when building the final autonomy binary
111+
if [[ "${{ matrix.target }}" =~ .+-musl(.+)? ]]; then
112+
export RUSTFLAGS='-C target-feature=+crt-static'
113+
fi
114+
115+
# Use the compile tool to build the target binary
116+
if [ "${{ matrix.use_cross }}" == "true" ]; then
117+
./target/debug/compile --configuration compile.yaml \
118+
--target ${{ matrix.target }} --use-cross --release
119+
else
120+
./target/debug/compile --configuration compile.yaml \
121+
--target ${{ matrix.target }} --release
122+
fi
123+
124+
BINARY_PATH="./target/${{ matrix.target }}/release/autonomy"
125+
chmod +x "$BINARY_PATH"
126+
127+
if [ "${{ matrix.test_method }}" == "qemu" ]; then
128+
qemu-${{ matrix.qemu_architecture }}-static "$BINARY_PATH" --version
129+
else
130+
"$BINARY_PATH" --version
131+
fi
132+
133+
- name: Upload binary artifact
134+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
135+
with:
136+
name: autonomy.${{ matrix.target }}
137+
path: source/rust/autonomy_command/target/${{ matrix.target }}/release/autonomy
138+
if-no-files-found: error
139+
compression-level: 0
140+
141+
create_release:
142+
name: Create Release
143+
needs: build_and_test
144+
runs-on: ubuntu-22.04
145+
if: github.event_name == 'workflow_dispatch'
146+
steps:
147+
- name: Checkout
148+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
149+
with:
150+
ref: ${{ github.event.inputs.commit_sha }}
151+
152+
- name: Download all artifacts
153+
uses: actions/download-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
154+
with:
155+
path: artifacts
156+
157+
- name: Create Release
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160+
run: |
161+
RELEASE_TAG="v0.158.0"
162+
RELEASE_NAME="Release v0.158.0"
163+
COMMIT_SHA="${{ github.event.inputs.commit_sha || github.sha }}"
164+
RELEASE_BODY="Release v0.158.0"
165+
166+
gh release create "$RELEASE_TAG" \
167+
--title "$RELEASE_NAME" \
168+
--notes "$RELEASE_BODY" \
169+
--target "$COMMIT_SHA" \
170+
--draft
171+
172+
for artifact_dir in artifacts/autonomy.*; do
173+
if [ -d "$artifact_dir" ]; then
174+
target=$(basename "$artifact_dir" | sed 's/autonomy\.//')
175+
for binary_file in "$artifact_dir"/*; do
176+
if [ -f "$binary_file" ]; then
177+
asset_name="autonomy-${target}"
178+
echo "Uploading $binary_file as $asset_name"
179+
gh release upload "$RELEASE_TAG" "$binary_file#$asset_name"
180+
fi
181+
done
182+
fi
183+
done

rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
channel = "1.88"
3+
components = ["clippy", "rustfmt"]
4+
profile = "minimal"

source/rust/autonomy_command/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "autonomy_command"
3-
version = "0.1.0"
3+
version = "0.158.0"
44
edition = "2021"
55

66
[[bin]]

source/rust/autonomy_command/compile.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ struct Args {
2323
/// Prints the processed configuration without building the binaries
2424
#[clap(long)]
2525
dry_run: bool,
26+
27+
/// Target triple for cross-compilation (e.g., x86_64-unknown-linux-gnu)
28+
#[clap(long)]
29+
target: Option<String>,
30+
31+
/// Use cross for cross-compilation instead of cargo
32+
#[clap(long)]
33+
use_cross: bool,
34+
35+
/// Build in release mode
36+
#[clap(long)]
37+
release: bool,
2638
}
2739

2840
/// Builds the binaries with the passed configuration:
@@ -47,7 +59,7 @@ fn main() -> Result<()> {
4759
let cmd = OckamCommand::command();
4860
let top_level_commands = top_level_command_names(&cmd);
4961
for (bin_name, brand_config) in config.items {
50-
build_binary(bin_name, brand_config, &top_level_commands, args.dry_run)?;
62+
build_binary(bin_name, brand_config, &top_level_commands, &args)?;
5163
}
5264
Ok(())
5365
}
@@ -57,7 +69,7 @@ fn build_binary(
5769
bin_name: String,
5870
brand_settings: Brand,
5971
top_level_commands: &[String],
60-
dry_run: bool,
72+
args: &Args,
6173
) -> Result<()> {
6274
brand_settings.validate()?;
6375

@@ -70,14 +82,36 @@ fn build_binary(
7082
let brand_name = brand_settings.brand_name(&bin_name);
7183
let home_dir = brand_settings.home_dir(&bin_name);
7284

73-
if dry_run {
85+
if args.dry_run {
7486
return Ok(());
7587
}
7688

77-
let mut cmd = std::process::Command::new("cargo");
78-
cmd.args(["build", "--bin", &bin_name]);
79-
if let Some(build_args) = &brand_settings.build_args {
80-
cmd.args(build_args);
89+
// Determine build command and arguments
90+
let (build_cmd, mut build_args) = if args.use_cross {
91+
("cross", vec!["build"])
92+
} else {
93+
("cargo", vec!["build"])
94+
};
95+
96+
// Add target if specified
97+
if let Some(target) = &args.target {
98+
build_args.extend_from_slice(&["--target", target]);
99+
}
100+
101+
// Add release flag if specified
102+
if args.release {
103+
build_args.push("--release");
104+
}
105+
106+
// Add binary name
107+
build_args.extend_from_slice(&["--bin", &bin_name]);
108+
109+
let mut cmd = std::process::Command::new(build_cmd);
110+
cmd.args(&build_args);
111+
112+
// Add any additional build args from config
113+
if let Some(config_build_args) = &brand_settings.build_args {
114+
cmd.args(config_build_args);
81115
}
82116

83117
cmd.envs([

0 commit comments

Comments
 (0)