Skip to content

Commit

Permalink
chore: cross-builds
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Oct 8, 2023
1 parent b286ea0 commit 632d74e
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 27 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: ⚃ Builds

on:
workflow_dispatch:
inputs:
force-builds:
required: true
type: boolean
description: Publish Builds at Anytime

pull_request:
branches: [ '**' ]

release:
types: [published]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write

jobs:
builds:
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-unknown-linux-gnu
- target: aarch64-unknown-linux-musl
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
- target: x86_64-unknown-linux-musl
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-unknown-freebsd

timeout-minutes: 60
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install OpenSSL
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt update && sudo apt install -y libssl-dev

- name: Install musl-tools
run: sudo apt update && sudo apt install -y musl-dev musl-tools
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'

- name: Cache Project
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
shared-key: check-${{ matrix.platform.target }}-${{ matrix.platform.os }}
save-if: ${{ github.event_name == 'push' }}

- name: Install Rust Toolchain
id: toolchain
uses: dtolnay/rust-toolchain@stable

- name: Override rust-toolchain.toml
run: rustup override set ${{steps.toolchain.outputs.name}}

- name: cross-build
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}

- name: crt-static
run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >>"${GITHUB_ENV}"
if: endsWith(matrix.target, 'windows-msvc')

- name: Build Binary
run: cargo build -p homestar-runtime --target ${{ matrix.target }} --locked --release

- name: Publish Release Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}
path: target/${{ matrix.target }}/release/homestar*
if-no-files-found: error

- uses: taiki-e/upload-rust-binary-action@v1
with:
bin: homestar
target: ${{ matrix.target }}
tar: all
zip: windows
include: LICENSE,README.md
token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[build.env]
passthrough = [
"CARGO_INCREMENTAL",
"RUST_BACKTRACE",
"CARGO_TERM_COLOR",
"RUSTFLAGS",
]

[target.x86_64-unknown-linux-musl]
image = "messense/rust-musl-cross:x86_64-musl"

[target.aarch64-unknown-linux-musl]
image = "messense/rust-musl-cross:aarch64-musl"

[target.x86_64-apple-darwin]
image = "freeznet/x86_64-apple-darwin-cross:11.3"

[target.aarch64-apple-darwin]
image = "freeznet/aarch64-apple-darwin-cross:11.3"
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@

rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = ["cargo" "clippy" "rustfmt" "rust-src" "rust-std"];
targets = ["wasm32-unknown-unknown" "wasm32-wasi"];
targets = [
"wasm32-unknown-unknown"
"wasm32-wasi"
"x86_64-apple-darwin"
"aarch64-apple-darwin"
"x86_64-unknown-linux-musl"
"aarch64-unknown-linux-musl"
];
};

nightly-rustfmt = pkgs.rust-bin.nightly.latest.rustfmt;
Expand All @@ -45,6 +52,7 @@

cargo-installs = with pkgs; [
cargo-deny
cargo-cross
cargo-expand
cargo-nextest
cargo-outdated
Expand All @@ -53,6 +61,7 @@
cargo-unused-features
cargo-udeps
cargo-watch
rustup
twiggy
wasm-tools
];
Expand Down
1 change: 0 additions & 1 deletion homestar-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ autotests = false
path = "src/lib.rs"
bench = false
doctest = true
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "homestar"
Expand Down
2 changes: 1 addition & 1 deletion homestar-runtime/src/network/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub(crate) fn init(
swarm.listen_on(settings.listen_address.to_string().parse()?)?;

// add external addresses from settings
if settings.announce_addresses.is_empty() {
if !settings.announce_addresses.is_empty() {
for addr in settings.announce_addresses.iter() {
swarm.add_external_address(addr.clone());
}
Expand Down
26 changes: 16 additions & 10 deletions homestar-runtime/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use assert_cmd::prelude::*;
use once_cell::sync::Lazy;
use predicates::prelude::*;
use retry::{delay::Fixed, retry};
use retry::{delay::Exponential, retry};
use serial_test::file_serial;
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr, TcpStream},
Expand Down Expand Up @@ -143,8 +143,8 @@ fn test_server_serial() -> Result<()> {
.spawn()
.unwrap();

let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 9998);
let result = retry(Fixed::from_millis(1000).take(10), || {
let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 9991);
let result = retry(Exponential::from_millis(1000).take(10), || {
TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both))
});

Expand All @@ -158,7 +158,7 @@ fn test_server_serial() -> Result<()> {
.arg("--host")
.arg("::1")
.arg("-p")
.arg("9998")
.arg("9991")
.assert()
.success()
.stdout(predicate::str::contains("::1"))
Expand Down Expand Up @@ -205,14 +205,16 @@ fn test_workflow_run_serial() -> Result<()> {

let mut homestar_proc = Command::new(BIN.as_os_str())
.arg("start")
.arg("-c")
.arg("tests/fixtures/test_workflow.toml")
.arg("--db")
.arg("homestar.db")
.stdout(Stdio::piped())
.spawn()
.unwrap();

let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 3030);
let result = retry(Fixed::from_millis(1000).take(30), || {
let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 9888);
let result = retry(Exponential::from_millis(1000).take(20), || {
TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both))
});

Expand All @@ -223,6 +225,8 @@ fn test_workflow_run_serial() -> Result<()> {

Command::new(BIN.as_os_str())
.arg("run")
.arg("-p")
.arg("9888")
.arg("-w")
.arg("tests/fixtures/test-workflow-add-one.json")
.assert()
Expand All @@ -239,6 +243,8 @@ fn test_workflow_run_serial() -> Result<()> {
// run another one of the same!
Command::new(BIN.as_os_str())
.arg("run")
.arg("-p")
.arg("9888")
.arg("-w")
.arg("tests/fixtures/test-workflow-add-one.json")
.assert()
Expand Down Expand Up @@ -289,7 +295,7 @@ fn test_daemon_serial() -> Result<()> {
.success();

let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9997);
let result = retry(Fixed::from_millis(1000).take(10), || {
let result = retry(Exponential::from_millis(1000).take(10), || {
TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both))
});

Expand Down Expand Up @@ -332,7 +338,7 @@ fn test_signal_kill_serial() -> Result<()> {
.unwrap();

let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 3030);
let result = retry(Fixed::from_millis(1000).take(10), || {
let result = retry(Exponential::from_millis(1000).take(10), || {
TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both))
});

Expand Down Expand Up @@ -386,7 +392,7 @@ fn test_server_v4_serial() -> Result<()> {
.unwrap();

let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9999);
let result = retry(Fixed::from_millis(1000).take(30), || {
let result = retry(Exponential::from_millis(1000).take(20), || {
TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both))
});

Expand Down Expand Up @@ -443,7 +449,7 @@ fn test_daemon_v4_serial() -> Result<()> {
.success();

let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9999);
let result = retry(Fixed::from_millis(1000).take(30), || {
let result = retry(Exponential::from_millis(1000).take(20), || {
TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both))
});

Expand Down
4 changes: 4 additions & 0 deletions homestar-runtime/tests/fixtures/test_v4.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[monitoring]
process_collector_interval = 500
metrics_port = 4010

[node]

[node.network]
Expand Down
2 changes: 1 addition & 1 deletion homestar-runtime/tests/fixtures/test_v6.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ metrics_port = 4006

[node.network]
events_buffer_len = 1000
rpc_port = 9998
rpc_port = 9991
rpc_host = "::1"
8 changes: 4 additions & 4 deletions homestar-runtime/tests/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::utils::{stop_homestar, BIN_NAME};
use anyhow::Result;
use once_cell::sync::Lazy;
use reqwest::StatusCode;
use retry::{delay::Fixed, retry, OperationResult};
use retry::{delay::Exponential, retry, OperationResult};
use serial_test::file_serial;
use std::{
net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpStream},
Expand All @@ -20,7 +20,7 @@ const METRICS_URL: &str = "http://localhost:4004";
fn test_metrics_serial() -> Result<()> {
fn sample_metrics() -> prometheus_parse::Value {
let body = retry(
Fixed::from_millis(1000).take(10),
Exponential::from_millis(1000).take(10),
|| match reqwest::blocking::get(METRICS_URL) {
Ok(response) => match response.status() {
StatusCode::OK => OperationResult::Ok(response.text()),
Expand Down Expand Up @@ -57,7 +57,7 @@ fn test_metrics_serial() -> Result<()> {
.unwrap();

let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 4004);
let result = retry(Fixed::from_millis(1000).take(10), || {
let result = retry(Exponential::from_millis(1000).take(10), || {
TcpStream::connect(socket).map(|stream| stream.shutdown(Shutdown::Both))
});

Expand All @@ -68,7 +68,7 @@ fn test_metrics_serial() -> Result<()> {

let sample1 = sample_metrics();

let sample2 = retry(Fixed::from_millis(500).take(3), || {
let sample2 = retry(Exponential::from_millis(500).take(3), || {
let sample2 = sample_metrics();
if sample1 != sample2 {
OperationResult::Ok(sample2)
Expand Down

0 comments on commit 632d74e

Please sign in to comment.