Skip to content

Commit

Permalink
Merge pull request #223 from 007harshmahajan/macos_build
Browse files Browse the repository at this point in the history
MacOS Build
  • Loading branch information
Shourya742 committed Aug 17, 2024
2 parents 691c937 + f2b3278 commit e49fee8
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 37 deletions.
30 changes: 18 additions & 12 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
on:
push:
branches:
- master
- master
pull_request:

name: build

jobs:

build:
name: Build
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- stable
- nightly
features:
- default
- integration-test
os: [ubuntu-latest, macos-latest]
rust: [stable, nightly]
features: [default, integration-test]
steps:
- name: checkout
uses: actions/checkout@v3

- name: Generate cache key
run: echo "${{ matrix.rust }} ${{ matrix.features }}" | tee .cache_key
run: echo "${{ matrix.os }}-${{ matrix.rust }}-${{ matrix.features }}" | tee .cache_key

- name: cache
uses: actions/cache@v2
with:
Expand All @@ -32,11 +30,19 @@ jobs:
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}

- name: Set default toolchain
run: rustup default ${{ matrix.rust }}

- name: Set profile
run: rustup set profile minimal

- name: Update toolchain
run: rustup update
- name: Build
run: cargo build --features ${{ matrix.features }}

- name: Install dependencies on macOS
if: matrix.os == 'macos-latest'
run: brew install automake libtool zeromq

- name: Build for OS
run: cargo build --features=${{ matrix.features }}
21 changes: 17 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
on:
push:
branches:
- master
- master
pull_request:

name: lint

jobs:

fmt:
name: rust fmt
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set default toolchain
run: rustup default nightly

- name: Set profile
run: rustup set profile minimal

- name: Add rustfmt
run: rustup component add rustfmt

- name: Add clippy
run: rustup component add clippy

- name: Install dependencies on macOS
if: matrix.os == 'macos-latest'
run: brew install automake libtool zeromq

- name: Update toolchain
run: rustup update

- name: Check fmt
run: cargo fmt --all -- --check

- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
run: cargo clippy --all-targets --all-features -- -D warnings
20 changes: 13 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
on:
push:
branches:
- master
- master
pull_request:

name: test

jobs:
test_with_codecov:
name: Run tests with coverage reporting
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set default toolchain
run: rustup default nightly

- name: Set profile
run: rustup set profile minimal

# Pin grcov to v0.8.2 because of build failure at 0.8.3
- name: Install grcov
run: cargo install grcov --force --version 0.8.2

# Tests are run with code coverage support
- name: Install dependencies on macOS
if: matrix.os == 'macos-latest'
run: brew install automake libtool zeromq

- name: Run cargo test
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off'
run: cargo test --features=integration-test -- --nocapture

- id: coverage
name: Generate coverage
uses: actions-rs/grcov@v0.1.5

# Upload coverage report

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ${{ steps.coverage.outputs.report }}
directory: ./coverage/reports/
directory: ./coverage/reports/
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ dirs = "3.0.1"
tokio-socks = "0.5"
clap = { version = "3.2.22", features = ["derive"] }
bitcoind = "0.36"
libtor = { version = "47.13.0", optional = true }
libtor = { version = "47.13.0", optional = true, features = ["vendored-openssl"] }
mitosis = { version = "0.1.1", optional = true }
log4rs = "1.3.0"
openssl-sys = { version = "0.9.68", optional = true }

#Empty default feature set, (helpful to generalise in github actions)
[features]
default = ['tor']
# Mac OS needs to use the vendored version of openssl-sys as upstream `libtor` is not updated for to support mac os aarch (M series)
build-macos-aarch = ["openssl-sys/vendored"]
# The following feature set is in response to the issue described at https://github.com/rust-lang/rust/issues/45599
# Only used for running the integration tests
integration-test = []
# Only used for running the tor
tor = ['dep:libtor', 'dep:mitosis']
# Used for spawning Tor process and connecting to the Tor socks port
tor = ['dep:libtor', 'dep:mitosis']
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ CoinSwap is a rust implementation of a variant of atomic-swap protocol, using HT
* [Developer's resources](/docs/dev-book.md)

## Build and Test
Macos (M series) needs some feature for compilation

```console
$ cargo build --target=aarch64-apple-darwin --features=build-macos-aarch
```

The repo contains a fully automated integration testing framework on Bitcoin Regtest. The bitcoin binary used for testing is
included [here](./bin/bitcoind).
Expand Down
Binary file added bin/bitcoind_macos
Binary file not shown.
15 changes: 11 additions & 4 deletions tests/test_framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
//! The test data also includes the backend bitcoind data-directory, which is useful for observing the blockchain states after a swap.
//!
//! Checkout `tests/standard_swap.rs` for example of simple coinswap simulation test between 1 Taker and 2 Makers.
use bitcoin::secp256k1::rand::{distributions::Alphanumeric, thread_rng, Rng};
use bitcoin::{
secp256k1::rand::{distributions::Alphanumeric, thread_rng, Rng},
Address, Amount,
};
use std::{
collections::HashMap,
fs,
Expand All @@ -21,8 +24,6 @@ use std::{
time::Duration,
};

use bitcoin::{Address, Amount};

use bitcoind::{
bitcoincore_rpc::{Auth, Client, RpcApi},
BitcoinD, Conf,
Expand Down Expand Up @@ -94,9 +95,15 @@ impl TestFramework {
conf.staticdir = Some(temp_dir.join(".bitcoin"));
log::info!("bitcoind configuration: {:?}", conf.args);

let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;
let key = "BITCOIND_EXE";
let curr_dir_path = std::env::current_dir().unwrap();
let bitcoind_path = curr_dir_path.join("bin").join("bitcoind");

let bitcoind_path = match (os, arch) {
("macos", "aarch64") => curr_dir_path.join("bin").join("bitcoind_macos"),
_ => curr_dir_path.join("bin").join("bitcoind"),
};
std::env::set_var(key, bitcoind_path);
let exe_path = bitcoind::exe_path().unwrap();

Expand Down

0 comments on commit e49fee8

Please sign in to comment.