Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CLI-only features optional #62

Merged
merged 5 commits into from
Jun 17, 2023
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: Run cargo test
run: cargo test
- name: Run cargo test in lib mode
run: cargo test --no-default-features
16 changes: 12 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ license = "MIT"
keywords = ["sprite", "svg", "cartography", "vector-tiles", "maplibre"]
categories = ["command-line-utilities", "encoding", "filesystem", "graphics"]

[features]
default = ["cli"]
cli = ["dep:clap", "dep:exitcode", "dep:rayon"]

[dependencies]
assert_fs = "1.0.13"
clap = { version = "4.3", features = ["derive"] }
clap = { version = "4.3", features = ["derive"], optional = true }
crunch = "0.5.3"
exitcode = "1.1"
exitcode = { version = "1.1", optional = true }
multimap = "0.9"
oxipng = { version = "8.0", features = ["parallel", "zopfli", "filetime"], default-features = false }
png = "0.17"
rayon = "1.7"
rayon = { version = "1.7", optional = true }
resvg = "0.34"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[dev-dependencies]
assert_cmd = "2.0"
assert_fs = "1.0.13"
predicates = "3"

[profile.release]
lto = "thin"
strip = true
codegen-units = 1

[[bin]]
name = "spreet"
required-features = ["cli"]
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ _Spreet_ (also _spreit_, _spret_, _sprit_) is the [Scots](https://en.wikipedia.o

- [Installation](#installation)
- [Tutorial](#tutorial)
- [Usage](#usage)
- [Command-line usage](#command-line-usage)
- [Using Spreet as a Rust library](#using-spreet-as-a-rust-library)
- [Benchmarks](#benchmarks)

## Installation
Expand Down Expand Up @@ -83,7 +84,7 @@ By default the JSON index file is pretty-printed, but you can minify it with the

When you create a spritesheet for your production environment, use `--unique --minify-index-file` for best results.

## Usage
## Command-line usage

```
$ spreet --help
Expand All @@ -105,6 +106,16 @@ Options:
-V, --version Print version
```

## Using Spreet as a Rust library

The main purpose of Spreet is to be command-line tool, but you can also use it as a library in your own Rust code. To add Spreet as a dependency, include this in your `Cargo.toml`:

```toml
spreet = { version = "0.8.0", default-features = false }
```

To learn how to build your spritesheets programatically, see the [Spreet crate docs on docs.rs](https://docs.rs/spreet) and have a [look at the spritesheet tests](https://github.com/flother/spreet/blob/master/tests/sprite.rs).

## Benchmarks

To compare the output from [spritezero](https://github.com/mapbox/spritezero-cli) and Spreet, benchmarks are run against SVG sprite sets from four diverse map styles: [osm-bright-gl-style](https://github.com/openmaptiles/osm-bright-gl-style), [openstreetmap-americana](https://github.com/ZeLonewolf/openstreetmap-americana), [mapbox-gl-styles (basic)](https://github.com/mapbox/mapbox-gl-styles), and [mapbox-gl-whaam-style](https://github.com/mapbox/mapbox-gl-whaam-style). Unique, retina spritesheets are output (`--unique --retina`), and Spreet also uses `--minify-index-file` (spritezero doesn't have that option).
Expand Down
2 changes: 2 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "cli")]

use std::path::Path;
use std::process::Command;

Expand Down