Skip to content

Commit

Permalink
Make desktop notifications feature (dbus) optional
Browse files Browse the repository at this point in the history
This makes dbus dependency opt-in by making desktop notifications an
optional feature.

We also make native-tls optional and rustls the default. The idea is
that `cargo build` will be easier to build because it doesn't need any
system dependencies, and features that need system dependencies will be
hidden behind feature flags.

After this patch: (all commands in 'tiny' directory)

- dbus + rustls:
  cargo build --features="desktop-notifications"
- dbus + native-tls
  cargo build --features="desktop-notifications tls-native" \
              --no-default-features

Removing "desktop-notifications" will make a build without dbus
dependency.

It's now possible to make a statically-linked executable with

    $ cargo build --target=x86_64-unknown-linux-musl

(#65)
  • Loading branch information
osa1 committed Feb 14, 2020
1 parent db9ac5f commit 70c88ed
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 50 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Install native dependencies
run: sudo apt-get install libdbus-1-dev pkg-config libssl-dev

- name: Get nightly toolchain
uses: actions-rs/toolchain@v1
with:
Expand All @@ -28,14 +25,14 @@ jobs:
- name: Check formatting
run: cargo fmt --all -- --check

Linux_rustls:
name: '[Linux, rustls] Build'
Linux_native_tls_notif:
name: '[Linux, native TLS + notifications] Build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install native dependencies
run: sudo apt-get install libdbus-1-dev
run: sudo apt-get install libdbus-1-dev pkg-config libssl-dev

- name: Get nightly toolchain
uses: actions-rs/toolchain@v1
Expand All @@ -44,10 +41,13 @@ jobs:
components: rustfmt
override: true

- name: Build with rustls
run: cd tiny && cargo build --verbose --no-default-features --features tls-rustls
- name: Build with rustls and dbus
run: |
cd tiny
cargo build --verbose --no-default-features \
--features "tls-native desktop-notifications"
OSX:
OSX_default:
name: '[OSX, default] Build and test'
runs-on: macos-latest
steps:
Expand All @@ -66,11 +66,8 @@ jobs:
- name: Run tests
run: cargo test --verbose

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

OSX_rustls:
name: '[OSX, rustls] Build'
OSX_native_tls_notif:
name: '[OSX, native TLS + notifications] Build'
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -83,4 +80,7 @@ jobs:
override: true

- name: Build
run: cd tiny && cargo build --verbose --no-default-features --features tls-rustls
run: |
cd tiny
cargo build --verbose --no-default-features \
--features "tls-native desktop-notifications"
65 changes: 57 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,58 @@ jobs:
components: rustfmt
override: true

- name: Make release tarball (libssl + libdbus)
- name: Make release tarball (default)
run: |
(cd tiny && cargo build --release --verbose)
tar -C target/release -czvf tiny-ubuntu-18.04.tar.gz tiny
- name: Make release tarball (default, statically linked)
run: |
(cd tiny && cargo build --release --verbose --target=x86_64-unknown-linux-musl)
tar -C target/x86_64-unknown-linux-musl/release \
-czvf tiny-ubuntu-18.04-static.tar.gz tiny
- name: Make release tarball (libssl)
run: |
(cd tiny && cargo build --release --verbose \
--no-default-features --features="tls-native")
tar -C target/release -czvf tiny-ubuntu-18.04-libssl.tar.gz tiny
- name: Make release tarball (rustls + libdbus)
- name: Make release tarball (libdbus)
run: |
(cd tiny && cargo build --release --verbose \
--no-default-features --features="desktop-notifications")
tar -C target/release -czvf tiny-ubuntu-18.04-dbus.tar.gz tiny
- name: Make release tarball (libssl + libdbus)
run: |
(cd tiny && cargo build --release --verbose --no-default-features --features tls-rustls)
tar -C target/release -czvf tiny-ubuntu-18.04-rustls.tar.gz tiny
(cd tiny && cargo build --release --verbose \
--no-default-features --features="tls-native desktop-notifications")
tar -C target/release -czvf tiny-ubuntu-18.04-libssl-dbus.tar.gz tiny
# TODO: Can I not do this in one step?

- name: Upload executable (1/2)
- name: Upload executable (1/5)
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: tiny-ubuntu-18.04.tar.gz
asset_name: tiny-ubuntu-18.04.tar.gz
asset_content_type: application/gzip

- name: Upload executable (2/5)
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: tiny-ubuntu-18.04-static.tar.gz
asset_name: tiny-ubuntu-18.04-static.tar.gz
asset_content_type: application/gzip

- name: Upload executable (3/5)
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -56,12 +95,22 @@ jobs:
asset_name: tiny-ubuntu-18.04-libssl.tar.gz
asset_content_type: application/gzip

- name: Upload executable (2/2)
- name: Upload executable (4/5)
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: tiny-ubuntu-18.04-dbus.tar.gz
asset_name: tiny-ubuntu-18.04-dbus.tar.gz
asset_content_type: application/gzip

- name: Upload executable (4/5)
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: tiny-ubuntu-18.04-rustls.tar.gz
asset_name: tiny-ubuntu-18.04-rustls.tar.gz
asset_path: tiny-ubuntu-18.04-libssl-dbus.tar.gz
asset_name: tiny-ubuntu-18.04-libssl-dbus.tar.gz
asset_content_type: application/gzip
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,30 @@ tiny is an IRC client written in Rust.

- SASL authentication

- Configurable desktop notifications on new messages
- Configurable desktop notifications on new messages (opt-in feature behind a
feature flag, see below)

- znc compatible

- TLS support

## Installation

Install the Rust nightly toolchain, clone the repo, and run
For pre-build binaries see [releases]. To build from source install Rust nightly
toolchain. By default tiny uses [rustls] for TLS support, and desktop
notifications are disabled.

[releases]: https://github.com/osa1/tiny/releases
[rustls]: https://github.com/ctz/rustls

- To use system TLS library (OpenSSL or LibreSSL), add `--no-default-features
--features=tls-native` to the command you're using. Note that this requires
OpenSSL or LibreSSL headers and runtime libraries on Linux.

- To enable desktop notifications add `--features=desktop-notifications`. This
requires libdbus on Linux.

To install in a clone:

```
cargo install --path tiny
Expand All @@ -62,30 +77,10 @@ cargo install --git https://github.com/osa1/tiny
If you have an older version installed, add `--force` to the command you're
using.

Arch Linux users can install tiny from the [AUR].
Arch Linux users can install tiny from [AUR].

[AUR]: https://aur.archlinux.org/packages/tiny-irc-client-git/

Since version 0.3.0 tiny needs OpenSSL or LibreSSL headers and runtime
libraries. See [rust-openssl documentation] for installation instructions.

[rust-openssl documentation]: https://docs.rs/openssl/0.10.26/openssl/#automatic

### Using rustls instead of native TLS library

To use [rustls], add `--no-default-features --features tls-rustls` to the
install command you're using.

When building with rustls tiny doesn't require a native SSL library (OpenSSL or
LibreSSL).

[rustls]: https://github.com/ctz/rustls

### Dependencies

* OpenSSL or LibreSSL (default, not when rustls is used)
* libdbus (Linux only)

tiny is tested on Linux and OSX.

## Configuration
Expand Down
2 changes: 1 addition & 1 deletion libtiny_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "An IRC client library, mainly to be used in tiny"
edition = "2018"

[features]
default = ["tls-native"]
default = ["tls-rustls"]
tls-native = ["native-tls", "tokio-tls"]
tls-rustls = ["rustls-native-certs", "tokio-rustls"]

Expand Down
6 changes: 5 additions & 1 deletion libtiny_tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ version = "0.1.0"
description = "A terminal UI for tiny"
edition = "2018"

[features]
default = []
desktop-notifications = ["notify-rust"]

[dependencies]
env_logger = "0.7"
futures = "0.3.1"
libtiny_ui = { path = "../libtiny_ui" }
log = "0.4"
notify-rust = "3"
notify-rust = { version = "3", optional = true }
serde = { version = "1.0.8", features = ["derive"] }
serde_yaml = "0.7.1"
tempfile = "3.0.3"
Expand Down
6 changes: 6 additions & 0 deletions libtiny_tui/src/notifier.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{utils::remove_irc_control_chars, MsgTarget};

#[cfg(feature = "desktop-notifications")]
use notify_rust::Notification;

/// Destktop notification handler
Expand All @@ -12,11 +14,15 @@ pub(crate) enum Notifier {
Messages,
}

#[cfg(feature = "desktop-notifications")]
fn notify(summary: &str, body: &str) {
// TODO: Report errors somehow
let _ = Notification::new().summary(summary).body(body).show();
}

#[cfg(not(feature = "desktop-notifications"))]
fn notify(_summary: &str, _body: &str) {}

impl Notifier {
pub(crate) fn notify_privmsg(
&mut self,
Expand Down
5 changes: 3 additions & 2 deletions tiny/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ description = "An IRC client"
edition = "2018"

[features]
default = ["tls-native"]
default = ["tls-rustls"]
tls-native = ["libtiny_client/tls-native"]
tls-rustls = ["libtiny_client/tls-rustls"]
desktop-notifications = ["libtiny_tui/desktop-notifications"]

[dependencies]
dirs = "1.0.2"
env_logger = "0.7"
futures = "0.3.1"
libtiny_client = { path = "../libtiny_client", default-features = false }
libtiny_logger = { path = "../libtiny_logger" }
libtiny_tui = { path = "../libtiny_tui" }
libtiny_tui = { path = "../libtiny_tui", default-features = false }
libtiny_ui = { path = "../libtiny_ui" }
libtiny_wire = { path = "../libtiny_wire" }
log = "0.4"
Expand Down

0 comments on commit 70c88ed

Please sign in to comment.