Skip to content

Commit

Permalink
Added build.rs & Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoradocchia committed Aug 3, 2022
1 parent a1b5a25 commit c438c95
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
/completions
/man
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

# [0.1.0] - 2022-07-09
## [0.2.0] - 2022-08-03

### Added

- `directory` CLI option to specify output CSV file directory.
- `format` CLI option to specify output CSV filename format.
- `quiet` CLI option to mute standard output.
- `csv` CLI option to enable CSV file output at launch.
- Signal handler listening for `SIGUSR1` signals to toggle (*enable*/*disable*)
CSV file output at runtime (e.g. `pkill --signal=SIGUSR1 datalogger`).
- [build.rs](build.rs) build script to generate manpage & shell completions.
- [Makefile](Makefile) to compile/install/uninstall `datalogger` alongside
manpage & shell completions.

## [0.1.0] - 2022-07-09

Initial release.
70 changes: 69 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datalogger"
version = "0.1.0"
version = "0.2.0"
authors = ["Marco Radocchia <marco.radocchia@outlook.com"]
edition = "2021"
rust-version = "1.61.0"
Expand All @@ -22,6 +22,15 @@ directories = "4.0.1"
termcolor = "1.1.3"
atty = "0.2.14"

[build-dependencies]
clap = { version = "3.2.16", features = ["derive"] }
clap_mangen = "0.1.10"
clap_complete = "3.2.3"
qrcodegen = "1.8.0"
lazy_static = "1.4.0"
regex = "1.6.0"
directories = "4.0.1"

[profile.release]
lto = true # link-time-optimization
strip = true # strip symbols from binary
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Paths.
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
COMPPREFIX = /usr/share

all:
# Compile & generate manpage and completions for Bash, Fish, Zsh.
cargo build --release

install:
# Install binary.
mkdir -p ${DESTDIR}${PREFIX}/bin
setcap 'cap_sys_nice=eip' target/release/datalogger
install -Dm 755 target/release/datalogger -t "${DESTDIR}${PREFIX}/bin"
# Install manpage.
mkdir -p ${DESTDIR}${MANPREFIX}/man1
install -Dm 644 man/datalogger.1 -t "${DESTDIR}${MANPREFIX}/man1"
# Install shell completions.
mkdir -p ${COMPPREFIX}/bash-completion/completions\
${COMPPREFIX}/zsh/site_functions\
${COMPPREFIX}/fish/vendor_completions.d
install -Dm 644 completions/datalogger.bash -t "${COMPPREFIX}/bash-completion/completions"
install -Dm 644 completions/_datalogger -t "${COMPPREFIX}/zsh/site-functions"
install -Dm 644 completions/datalogger.fish -t "${COMPPREFIX}/fish/vendor_completions.d"

uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/datalogger\
${DESTDIR}${MANPREFIX}/man1/datalogger.1\
${COMPPREFIX}/bash-completion/completions/datalogger.bash\
${COMPPREFIX}/zsh/site-functions/_datalogger\
${COMPPREFIX}/fish/vendor_completions.d/datalogger.fish

clean:
cargo clean
rm -rf completions man

.PHONY: all install uninstall clean
58 changes: 36 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
<!-- ![Crates.io version](https://img.shields.io/crates/v/datalogger?logo=rust&color=%23d8a657) -->
</div>

Humidity & Temperature datalogger for DHT22 sensor on Raspberry Pi.
Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi.

## Index

- [Install](#install)
* [Master branch](#master-branch)
* [Latest release from crates.io](#latest-release-from-crates.io)
- [Git](#git)
- [Cargo](#cargo)
- [Master branch](#master-branch)
- [Latest release from crates.io](#latest-release-from-crates.io)
- [Uninstall](#uninstall)
- [Usage](#usage)
- [Changelog](#changelog)
Expand All @@ -30,46 +32,58 @@ on the system. In order to install such toolchain you can use `rusutp`: see
https://www.rust-lang.org/tools/install for further installation
instructions and notes.

### Master branch
### Git

If you want to install `datalogger`, including **manpage** and shell
**completions** (Bash, Zsh, Fish), clone this repository and compile/install
using `make`:
```sh
git clone https://github.com/marcoradocchia/datalogger
cd datalogger
make
sudo make install
```

### Cargo

#### Master branch

To build and install from master branch run:
```sh
cargo install --git https://github.com/marcoradocchia/datalogger --branch master
```

### Latest release from crates.io
#### Latest release from crates.io

To build and install the latest release from
[crates.io](https://crates.io/crates/datalogger) run:
```
cargo install datalogger
```

## Uninstall

To uninstall run:
```
cargo uninstall datalogger
```

## Usage

```
datalogger 0.1.0
datalogger 0.2.0
Marco Radocchia <marco.radocchia@outlook.com>
Humidity & Temperature datalogger for DHT22 sensor on Raspberry Pi.
Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi.
USAGE:
datalogger [OPTIONS] --pin <PIN> [OUTPUT]
ARGS:
<OUTPUT> Output CSV data file
datalogger [OPTIONS] --pin <PIN>
OPTIONS:
-h, --help Print help information
-i, --interval <INTERVAL> Interval in seconds between consecutive measures [default: 120]
-p, --pin <PIN> GPIO pin for DHT22 data connection
-V, --version Print version information
--csv Dumps data to CSV file (can be swapped at runtime signalling
`datalogger` process with SIGUSR1)
-d, --directory <DIRECTORY> Output CSV directory [default: ~]
-f, --format <FORMAT> Output CSV filename format (see
https://docs.rs/chrono/latest/chrono/format/strftime/index.html
for valid specifiers) [default: %Y%m%d]
-h, --help Print help information
-i, --interval <INTERVAL> Interval in seconds between consecutive measures [default: 120]
-p, --pin <PIN> GPIO pin for DHT22 data connection
-P, --pipe Print output as `<hum,temp>` to stdout (for use in unix pipeline)
-q, --quiet Mute standard output
-V, --version Print version information
```

## Changelog
Expand Down
1 change: 0 additions & 1 deletion TODO

This file was deleted.

35 changes: 35 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use clap::CommandFactory;
use clap_complete::{generate_to, Shell::*};
use clap_mangen::{self, Man};
use std::env;

// Include Args struct.
include!("src/args.rs");

fn main() {
// Generate man & completions directories.
let manifest_dir =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("unable to determine manifest dir"));
let man_dir = manifest_dir.join("man");
let comp_dir = manifest_dir.join("completions");

fs::create_dir_all(&man_dir).expect("unable to create man directory");
fs::create_dir_all(&comp_dir).expect("unable to create completions directory");

// Retrieve Args and set binary name.
let mut cmd = Args::command();
cmd.set_bin_name("datalogger");

// Generate & write man page.
let mut buffer: Vec<u8> = Vec::new();
Man::new(cmd.clone())
.render(&mut buffer)
.expect("unable to generate man page");
fs::write(man_dir.join("datalogger.1"), buffer).expect("unable to write man page");

// Generate shell completions.
for shell in [Bash, Fish, Zsh] {
generate_to(shell, &mut cmd, "datalogger", &comp_dir)
.expect("unable to generate completions");
}
}

0 comments on commit c438c95

Please sign in to comment.