Skip to content

Commit

Permalink
Merge pull request #1 from unfoldedcircle/public-release
Browse files Browse the repository at this point in the history
Prepare public release
  • Loading branch information
zehnm authored Jan 17, 2023
2 parents f1c4cc6 + b09044a commit d0497b7
Show file tree
Hide file tree
Showing 15 changed files with 1,133 additions and 233 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Rust

on:
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
- '**/src/**'
- '**/build.rs'
- '.github/**/*.yml'
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened ]

env:
DEBUG_OUTPUT: "true"
CARGO_TERM_COLOR: always

jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Run rustfmt
run: cargo fmt --all -- --check

test:
name: Test and clippy
runs-on: ubuntu-latest
steps:
- name: Install required libraries
run: |
sudo apt-get update
sudo apt-get install libswupdate-dev -y
shell: bash

- name: Checkout repository
uses: actions/checkout@v3

- name: Install toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- run: cargo test

- name: Run clippy
run: cargo clippy -- -D warnings

build:
name: Build release
needs: test
runs-on: ubuntu-latest
steps:
- name: Install required libraries
run: |
sudo apt-get update
sudo apt-get install libswupdate-dev -y
shell: bash

- name: Checkout repository
uses: actions/checkout@v3
with:
# History of 200 should be more than enough to calculate commit count since last release tag.
fetch-depth: 200
- name: Fetch all tags to determine version
run: |
git fetch origin +refs/tags/*:refs/tags/*
APP_VERSION=$(git describe --match "v[0-9]*" --tags HEAD --always)
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
echo "ARTIFACT_NAME=${{ env.APP_NAME }}-$APP_VERSION-${{ env.LINUX_ARTIFACT_SUFFIX }}" >> $GITHUB_ENV
- name: Install toolchain
uses: dtolnay/rust-toolchain@stable

- name: Release build
shell: bash
run: cargo build --release

release:
name: GitHub release
if: github.ref == 'refs/heads/main' || contains(github.ref, 'tags/v')
needs: build
runs-on: ubuntu-latest

steps:
- name: Create Pre-Release
uses: "marvinpinto/action-automatic-releases@latest"
if: "!contains(github.ref, 'tags/v')"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Development Build"

- name: Create Release
uses: "marvinpinto/action-automatic-releases@latest"
if: "contains(github.ref, 'tags/v')"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Cargo.lock
/target/
/.cargo/
/.idea/
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SWUpdate client library wrapper Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
- Initial manual bindings to SWUpdate's [progress_ipc.h](https://github.com/sbabic/swupdate/blob/master/include/progress_ipc.h)
and [network_ipc.h](https://github.com/sbabic/swupdate/blob/master/include/network_ipc.h) client APIs.
- Rust wrapper for the progress interface with a simple example.
48 changes: 0 additions & 48 deletions Cargo.lock

This file was deleted.

11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# SWUpdate client library wrapper

`libswupdate` is Rust wrapper for the [SWUpdate C client library](https://sbabic.github.io/swupdate/swupdate-ipc-interface.html#client-library).
`libswupdate` is a Rust wrapper for the [SWUpdate C client library](https://sbabic.github.io/swupdate/swupdate-ipc-interface.html#client-library).

At the moment only the progress API in [progress_ipc.h](https://github.com/sbabic/swupdate/blob/master/include/progress_ipc.h)
is supported!
is supported! The network IPC functions are only available as low-level bindings (see [libswupdate-sys](./libswupdate-sys)).

## Usage

This crate is not yet published on [crates.io](https://crates.io/).
It will be published once we have an initial release after some more testing.

Add the following to your `Cargo.toml`:

```toml
[dependencies]
libswupdate = "0.1"
libswupdate = { git = "https://github.com/unfoldedcircle/libswupdate-rs.git", rev = "$COMMIT" }
```

Replace `$COMMIT` with the desired Git commit hash.

Also see [examples](./examples) directory.

## License
Expand Down
8 changes: 4 additions & 4 deletions examples/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use libswupdate::*;
use std::io;

fn main() -> Result<(), io::Error> {
let mut swupdate = SWUpdate::new();
let mut progress = SWUpdateProgress::new();

println!("Connecting to: {}", swupdate.get_prog_socket());
println!("Connecting to: {}", progress.get_socket_path());

swupdate.connect_progress()?;
progress.connect()?;

loop {
println!("{:?}", swupdate.receive_progress()?);
println!("{:?}", progress.receive()?);
}
}
17 changes: 12 additions & 5 deletions libswupdate-sys/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# libswupdate-sys - Raw FFI bindings to SWUpdate client library

Implemented SWUpdate client APIs:
Bindings for SWUpdate client APIs:

- [x] [progress_ipc.h](https://github.com/sbabic/swupdate/blob/master/include/progress_ipc.h)
- [ ] [network_ipc.h](https://github.com/sbabic/swupdate/blob/master/include/network_ipc.h)
- [progress_ipc.h](https://github.com/sbabic/swupdate/blob/master/include/progress_ipc.h)
- [network_ipc.h](https://github.com/sbabic/swupdate/blob/master/include/network_ipc.h)

Generated from Ubuntu `libswupdate-dev` package version: `2021.11-1`.

## Usage

Expand All @@ -17,11 +19,16 @@ libswupdate-sys = "0.1"
## Update bindings

We use [bindgen](https://crates.io/crates/bindgen) to generate the Rust declarations from SWUpdate's C header file.
At the moment we don't run `bindgen` at build-time, but use pregenerated bindings (see [src/bindings.rs](./src/bindings.rs)).
At the moment we don't run `bindgen` at build-time, but use pre-generated bindings with a few manual fixes
(see [src/bindings.rs](./src/bindings.rs)).

Bindgen command:
```shell
cargo install bindgen-cli
bindgen /usr/include/progress_ipc.h -o src/bindings.rs
bindgen wrapper.h -o src/bindings.rs \
--allowlist-function '(^.*ipc.*|^get_.*_socket|^swupdate.*)' \
--allowlist-type 'msgtype.*' \
--allowlist-var '(IPC_.*|SWUPDATE_.*|CMD_.*|SOCKET_PROGRESS_PATH)'
```

## License
Expand Down
2 changes: 1 addition & 1 deletion libswupdate-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
println!("cargo:rustc-link-lib=swupdate");
println!("cargo:rustc-link-lib=swupdate");
}
Loading

0 comments on commit d0497b7

Please sign in to comment.