Skip to content

Commit b80c356

Browse files
committed
Make desktop notifications feature (dbus) optional
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)
1 parent db9ac5f commit b80c356

File tree

7 files changed

+105
-50
lines changed

7 files changed

+105
-50
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v2
1111

12-
- name: Install native dependencies
13-
run: sudo apt-get install libdbus-1-dev pkg-config libssl-dev
14-
1512
- name: Get nightly toolchain
1613
uses: actions-rs/toolchain@v1
1714
with:
@@ -28,14 +25,14 @@ jobs:
2825
- name: Check formatting
2926
run: cargo fmt --all -- --check
3027

31-
Linux_rustls:
32-
name: '[Linux, rustls] Build'
28+
Linux_native_tls_notif:
29+
name: '[Linux, native TLS + notifications] Build'
3330
runs-on: ubuntu-latest
3431
steps:
3532
- uses: actions/checkout@v2
3633

3734
- name: Install native dependencies
38-
run: sudo apt-get install libdbus-1-dev
35+
run: sudo apt-get install libdbus-1-dev pkg-config libssl-dev
3936

4037
- name: Get nightly toolchain
4138
uses: actions-rs/toolchain@v1
@@ -44,10 +41,13 @@ jobs:
4441
components: rustfmt
4542
override: true
4643

47-
- name: Build with rustls
48-
run: cd tiny && cargo build --verbose --no-default-features --features tls-rustls
44+
- name: Build with rustls and dbus
45+
run: |
46+
cd tiny
47+
cargo build --verbose --no-default-features \
48+
--features "tls-native desktop-notifications"
4949
50-
OSX:
50+
OSX_default:
5151
name: '[OSX, default] Build and test'
5252
runs-on: macos-latest
5353
steps:
@@ -66,11 +66,8 @@ jobs:
6666
- name: Run tests
6767
run: cargo test --verbose
6868

69-
- name: Check formatting
70-
run: cargo fmt --all -- --check
71-
72-
OSX_rustls:
73-
name: '[OSX, rustls] Build'
69+
OSX_native_tls_notif:
70+
name: '[OSX, native TLS + notifications] Build'
7471
runs-on: macos-latest
7572
steps:
7673
- uses: actions/checkout@v2
@@ -83,4 +80,7 @@ jobs:
8380
override: true
8481

8582
- name: Build
86-
run: cd tiny && cargo build --verbose --no-default-features --features tls-rustls
83+
run: |
84+
cd tiny
85+
cargo build --verbose --no-default-features \
86+
--features "tls-native desktop-notifications"

.github/workflows/release.yml

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,58 @@ jobs:
3434
components: rustfmt
3535
override: true
3636

37-
- name: Make release tarball (libssl + libdbus)
37+
- name: Make release tarball (default)
3838
run: |
3939
(cd tiny && cargo build --release --verbose)
40+
tar -C target/release -czvf tiny-ubuntu-18.04.tar.gz tiny
41+
42+
- name: Make release tarball (default, statically linked)
43+
run: |
44+
(cd tiny && cargo build --release --verbose --target=x86_64-unknown-linux-musl)
45+
tar -C target/x86_64-unknown-linux-musl/release \
46+
-czvf tiny-ubuntu-18.04-static.tar.gz tiny
47+
48+
- name: Make release tarball (libssl)
49+
run: |
50+
(cd tiny && cargo build --release --verbose \
51+
--no-default-features --features="tls-native")
4052
tar -C target/release -czvf tiny-ubuntu-18.04-libssl.tar.gz tiny
4153
42-
- name: Make release tarball (rustls + libdbus)
54+
- name: Make release tarball (libdbus)
55+
run: |
56+
(cd tiny && cargo build --release --verbose \
57+
--no-default-features --features="desktop-notifications")
58+
tar -C target/release -czvf tiny-ubuntu-18.04-dbus.tar.gz tiny
59+
60+
- name: Make release tarball (libssl + libdbus)
4361
run: |
44-
(cd tiny && cargo build --release --verbose --no-default-features --features tls-rustls)
45-
tar -C target/release -czvf tiny-ubuntu-18.04-rustls.tar.gz tiny
62+
(cd tiny && cargo build --release --verbose \
63+
--no-default-features --features="tls-native desktop-notifications")
64+
tar -C target/release -czvf tiny-ubuntu-18.04-libssl-dbus.tar.gz tiny
4665
4766
# TODO: Can I not do this in one step?
4867

49-
- name: Upload executable (1/2)
68+
- name: Upload executable (1/5)
69+
uses: actions/[email protected]
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
with:
73+
upload_url: ${{ steps.create_release.outputs.upload_url }}
74+
asset_path: tiny-ubuntu-18.04.tar.gz
75+
asset_name: tiny-ubuntu-18.04.tar.gz
76+
asset_content_type: application/gzip
77+
78+
- name: Upload executable (2/5)
79+
uses: actions/[email protected]
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
with:
83+
upload_url: ${{ steps.create_release.outputs.upload_url }}
84+
asset_path: tiny-ubuntu-18.04-static.tar.gz
85+
asset_name: tiny-ubuntu-18.04-static.tar.gz
86+
asset_content_type: application/gzip
87+
88+
- name: Upload executable (3/5)
5089
uses: actions/[email protected]
5190
env:
5291
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -56,12 +95,22 @@ jobs:
5695
asset_name: tiny-ubuntu-18.04-libssl.tar.gz
5796
asset_content_type: application/gzip
5897

59-
- name: Upload executable (2/2)
98+
- name: Upload executable (4/5)
99+
uses: actions/[email protected]
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
with:
103+
upload_url: ${{ steps.create_release.outputs.upload_url }}
104+
asset_path: tiny-ubuntu-18.04-dbus.tar.gz
105+
asset_name: tiny-ubuntu-18.04-dbus.tar.gz
106+
asset_content_type: application/gzip
107+
108+
- name: Upload executable (4/5)
60109
uses: actions/[email protected]
61110
env:
62111
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63112
with:
64113
upload_url: ${{ steps.create_release.outputs.upload_url }}
65-
asset_path: tiny-ubuntu-18.04-rustls.tar.gz
66-
asset_name: tiny-ubuntu-18.04-rustls.tar.gz
114+
asset_path: tiny-ubuntu-18.04-libssl-dbus.tar.gz
115+
asset_name: tiny-ubuntu-18.04-libssl-dbus.tar.gz
67116
asset_content_type: application/gzip

README.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,30 @@ tiny is an IRC client written in Rust.
3939

4040
- SASL authentication
4141

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

4445
- znc compatible
4546

4647
- TLS support
4748

4849
## Installation
4950

50-
Install the Rust nightly toolchain, clone the repo, and run
51+
For pre-build binaries see [releases]. To build from source install Rust nightly
52+
toolchain. By default tiny uses [rustls] for TLS support, and desktop
53+
notifications are disabled.
54+
55+
[releases]: https://github.com/osa1/tiny/releases
56+
[rustls]: https://github.com/ctz/rustls
57+
58+
- To use system TLS library (OpenSSL or LibreSSL), add `--no-default-features
59+
--features=tls-native` to the command you're using. Note that this requires
60+
OpenSSL or LibreSSL headers and runtime libraries on Linux.
61+
62+
- To enable desktop notifications add `--features=desktop-notifications`. This
63+
requires libdbus on Linux.
64+
65+
To install in a clone:
5166

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

65-
Arch Linux users can install tiny from the [AUR].
80+
Arch Linux users can install tiny from [AUR].
6681

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

69-
Since version 0.3.0 tiny needs OpenSSL or LibreSSL headers and runtime
70-
libraries. See [rust-openssl documentation] for installation instructions.
71-
72-
[rust-openssl documentation]: https://docs.rs/openssl/0.10.26/openssl/#automatic
73-
74-
### Using rustls instead of native TLS library
75-
76-
To use [rustls], add `--no-default-features --features tls-rustls` to the
77-
install command you're using.
78-
79-
When building with rustls tiny doesn't require a native SSL library (OpenSSL or
80-
LibreSSL).
81-
82-
[rustls]: https://github.com/ctz/rustls
83-
84-
### Dependencies
85-
86-
* OpenSSL or LibreSSL (default, not when rustls is used)
87-
* libdbus (Linux only)
88-
8984
tiny is tested on Linux and OSX.
9085

9186
## Configuration

libtiny_client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description = "An IRC client library, mainly to be used in tiny"
66
edition = "2018"
77

88
[features]
9-
default = ["tls-native"]
9+
default = ["tls-rustls"]
1010
tls-native = ["native-tls", "tokio-tls"]
1111
tls-rustls = ["rustls-native-certs", "tokio-rustls"]
1212

libtiny_tui/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ version = "0.1.0"
44
description = "A terminal UI for tiny"
55
edition = "2018"
66

7+
[features]
8+
default = []
9+
desktop-notifications = ["notify-rust"]
10+
711
[dependencies]
812
env_logger = "0.7"
913
futures = "0.3.1"
1014
libtiny_ui = { path = "../libtiny_ui" }
1115
log = "0.4"
12-
notify-rust = "3"
16+
notify-rust = { version = "3", optional = true }
1317
serde = { version = "1.0.8", features = ["derive"] }
1418
serde_yaml = "0.7.1"
1519
tempfile = "3.0.3"

libtiny_tui/src/notifier.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::{utils::remove_irc_control_chars, MsgTarget};
2+
3+
#[cfg(feature = "desktop-notifications")]
24
use notify_rust::Notification;
35

46
/// Destktop notification handler
@@ -12,11 +14,15 @@ pub(crate) enum Notifier {
1214
Messages,
1315
}
1416

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

23+
#[cfg(not(feature = "desktop-notifications"))]
24+
fn notify(_summary: &str, _body: &str) {}
25+
2026
impl Notifier {
2127
pub(crate) fn notify_privmsg(
2228
&mut self,

tiny/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ description = "An IRC client"
99
edition = "2018"
1010

1111
[features]
12-
default = ["tls-native"]
12+
default = ["tls-rustls"]
1313
tls-native = ["libtiny_client/tls-native"]
1414
tls-rustls = ["libtiny_client/tls-rustls"]
15+
desktop-notifications = ["libtiny_tui/desktop-notifications"]
1516

1617
[dependencies]
1718
dirs = "1.0.2"
1819
env_logger = "0.7"
1920
futures = "0.3.1"
2021
libtiny_client = { path = "../libtiny_client", default-features = false }
2122
libtiny_logger = { path = "../libtiny_logger" }
22-
libtiny_tui = { path = "../libtiny_tui" }
23+
libtiny_tui = { path = "../libtiny_tui", default-features = false }
2324
libtiny_ui = { path = "../libtiny_ui" }
2425
libtiny_wire = { path = "../libtiny_wire" }
2526
log = "0.4"

0 commit comments

Comments
 (0)