Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/native-ble.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Builds the shimmerble native BLE library (shimmerble/) for each desktop platform.
#
# The macOS library can only be built on a Mac (Apple's SDK licence), so this is where it comes
# from. Each artifact unzips to native/<platform>/<library>, the layout NativeBleLoader expects:
# unzip into ShimmerDriverPC/src/main/resources/ to bundle it with the driver.
#
# Hosted runners have no Bluetooth, so this builds and compiles the tests; hardware testing is manual.
name: Native BLE library

on:
push:
paths:
- 'shimmerble/**'
- '.github/workflows/native-ble.yml'
pull_request:
paths:
- 'shimmerble/**'
- '.github/workflows/native-ble.yml'
workflow_dispatch:

jobs:
build:
name: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
platform: windows-x64
lib: shimmerble.dll
cli: blecli.exe
- os: macos-latest
target: aarch64-apple-darwin
platform: macos-arm64
lib: libshimmerble.dylib
cli: blecli
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
working-directory: shimmerble
steps:
- uses: actions/checkout@v4

# rust-toolchain.toml pins the compiler version; this installs exactly that one.
- name: Install the pinned toolchain
run: |
rustup toolchain install
rustup target add ${{ matrix.target }}
rustc --version

- name: Test
run: cargo test --release --target ${{ matrix.target }}

- name: Build
run: cargo build --release --target ${{ matrix.target }}

- name: Stage
run: |
out="$GITHUB_WORKSPACE/dist"
mkdir -p "$out/native/${{ matrix.platform }}" "$out/tools/${{ matrix.platform }}"
cp "target/${{ matrix.target }}/release/${{ matrix.lib }}" "$out/native/${{ matrix.platform }}/"
cp "target/${{ matrix.target }}/release/${{ matrix.cli }}" "$out/tools/${{ matrix.platform }}/"
ls -lR "$out"

- uses: actions/upload-artifact@v4
with:
name: shimmerble-${{ matrix.platform }}
path: dist/
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ ShimmerAndroidInstrumentDriver/gen/com/shimmerresearch/androidinstrumentdriver/B
ShimmerAndroidInstrumentDriver/gen/com/shimmerresearch/androidinstrumentdriver/R.java
gradle.properties
github.properties

# Native BLE library binaries. The Windows x64 and macOS arm64 builds are committed, built by the
# native-ble workflow from shimmerble/, so that every build of the driver carries them, Consensys's
# release build included (DEV-1504). Other platforms that ./gradlew buildNative puts here are not.
ShimmerDriverPC/src/main/resources/native/*/
!ShimmerDriverPC/src/main/resources/native/windows-x64/
!ShimmerDriverPC/src/main/resources/native/macos-arm64/
32 changes: 32 additions & 0 deletions ShimmerDriverPC/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,35 @@ shadowJar {

mergeServiceFiles() // Merges service files (if any)
}

// --- Native BLE library (shimmerble/) -------------------------------------------------
// Opt-in: './gradlew buildNative' needs a Rust toolchain, so it is not part of 'build'. It builds
// the library for this machine only and copies it to where NativeBleLoader looks on the classpath.
// The macOS library can only be built on a Mac; otherwise take it from the 'Native BLE library'
// GitHub Actions workflow and unzip it into src/main/resources/.
def nativeOs = org.gradle.internal.os.OperatingSystem.current()
def nativeArch = System.getProperty('os.arch') in ['aarch64', 'arm64'] ? 'arm64' : 'x64'
def nativePlatform = (nativeOs.isWindows() ? 'windows' : nativeOs.isMacOsX() ? 'macos' : 'linux') + '-' + nativeArch
def nativeLibFile = System.mapLibraryName('shimmerble')
def nativeCrateDir = file('../shimmerble')
def cargoInHome = new File(System.getProperty('user.home'), '.cargo/bin/' + (nativeOs.isWindows() ? 'cargo.exe' : 'cargo'))

task cargoBuildNative(type: Exec) {
group = 'native'
description = 'Runs cargo build --release in shimmerble/'
workingDir nativeCrateDir
commandLine(cargoInHome.exists() ? cargoInHome.absolutePath : 'cargo', 'build', '--release')
}

task buildNative(type: Copy) {
group = 'native'
description = "Builds the native BLE library and copies it to src/main/resources/native/${nativePlatform}/"
dependsOn cargoBuildNative
from new File(nativeCrateDir, "target/release/${nativeLibFile}")
into "src/main/resources/native/${nativePlatform}"
}

// The README only keeps src/main/resources in the tree for Eclipse; it does not belong in the jar.
processResources {
exclude 'native/README.md'
}
Loading
Loading