Skip to content

Commit d239c50

Browse files
committed
Updated docs
1 parent f22c489 commit d239c50

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ _internal_c_ffi = []
3232

3333
[profile.release]
3434
debug = false
35+
strip = true
3536
panic = "abort"
3637

3738
[lib]

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ This library can be used in C programs via [imagequant-sys](https://github.com/I
1111
```bash
1212
rustup update
1313
git clone https://github.com/ImageOptim/libimagequant
14-
cd imagequant-sys
15-
cargo build --release
14+
cd libimagequant/imagequant-sys
15+
cargo build --release --target-dir=target
1616
# makes target/release/libimagequant_sys.a
1717
```
1818

19-
See [the C library documentation for more details](https://pngquant.org/lib/).
19+
See [the C library API documentation](https://pngquant.org/lib/) and [the readme](https://lib.rs/imagequant-sys) for more info.
2020

2121
## Getting started in Rust
2222

@@ -57,6 +57,8 @@ If you're building for macOS or iOS, see included xcodeproj file (add it as a [s
5757

5858
If you're building for Android, run `rustup target add aarch64-linux-android; cargo build --release --target aarch64-linux-android` and use `target/aarch64-linux-android/release/libimagequant_sys.a`. Same for cross-compiling to other platforms. See `rustup target list`.
5959

60+
See [imagequant-sys readme](https://lib.rs/imagequant-sys#readme-building-for-c) for instructions how to make smaller builds.
61+
6062
### C dynamic library for package maintainers
6163

6264
If you're an application developer, please use the static linking option above — that option is much easier, and gives smaller executables.

imagequant-sys/README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add to `Cargo.toml`:
1818

1919
```toml
2020
[dependencies]
21-
imagequant = "4.0"
21+
imagequant = "4.4"
2222
```
2323

2424
[See docs.rs for the library API documentation](https://docs.rs/imagequant).
@@ -27,23 +27,47 @@ imagequant = "4.0"
2727

2828
### Building for C
2929

30-
1. Get Rust 1.70 or later via [rustup](https://rustup.rs) and run `rustup update`.
30+
1. Get Rust 1.80 or later via [rustup](https://rustup.rs) and run `rustup update`.
3131
2. `cd imagequant-sys`
3232

3333
The C API is exposed by a separate package called [`imagequant-sys`](https://github.com/ImageOptim/libimagequant/tree/main/imagequant-sys).
34+
3435
3. Run `cargo build --release`
3536

3637
This will build `target/release/libimagequant_sys.a` or `target\release\libimagequant_sys.lib` that you can use for static linking.
37-
Please don't worry about the size of the `.a` file. It includes a few unused objects. It only adds 500KB when linked. Use Link-Time-Optimization (LTO) option in your compiler, and/or add `-Wl,--as-needed` to linker flags if necessary. You can make the binary a bit smaller by building with `cargo +nightly build --target $TARGET_ARCH --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort`.
3838

3939
The repository includes an Xcode project file that can be used on iOS and macOS.
4040

41-
If you want to build a C dynamic library (DLL, so, dylib), then:
41+
#### Smaller static library
42+
43+
Please don't worry about the size of the `.a` file. It includes a few unused objects, but it should add only ~500KB when linked, and less if you use other Rust libraries, because it reuses some common standard library code.
44+
45+
Add `-Wl,--as-needed` and `-Wl,--gc-sections` to the linker flags (`LDFLAGS`) to ensure unused code is removed.
46+
47+
If you use `clang`, then enable Link-Time-Optimization (`-flto`) option in your compiler and linker, and set `CARGO_PROFILE_RELEASE_LTO=true` env var when running `cargo build`.
48+
49+
You can make the binary a bit smaller by building with a trimmed version of the standard library:
50+
51+
```bash
52+
rustup default nightly
53+
rustup update
54+
cargo clean
55+
cargo +nightly build --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
56+
```
57+
58+
It's also possible to remove Rust's standard library entirely by building with `--no-default-features --features no_std`, but , at the performance cost of losing multi-threading support. Add to `cargo build` invocations.
59+
60+
#### Dynamic library
61+
62+
If you want to build a C dynamic library (DLL, so, dylib), then the best is to use a helper tool:
4263

4364
1. `cargo install cargo-c`
4465
2. `cd imagequant-sys`
4566
3. `cargo cinstall --destdir=.`
46-
This will build `./usr/local/lib/libimagequant.0.0.0.{so,dylib,dll}`
67+
68+
This will build `./usr/local/lib/libimagequant.0.4.{so,dylib,dll}`
69+
70+
You can also use regular `cargo build --release` if you know how to set `rpath`. Set `CARGO_PROFILE_RELEASE_LTO=true` env var for a smaller binary.
4771

4872
### C API usage
4973

@@ -638,6 +662,6 @@ For animated GIFs see `liq_image_set_background()` which remaps images for GIF's
638662

639663
You can compile the library for other platforms via `cargo build --target=…`. See `rustup target list` for the list of platforms.
640664

641-
When compiling for WASM, you need to disable default features of this library (compile with `--no-default-features` flag). Otherwise it will use mult-threading, which requires [special handling in WASM](https://github.com/GoogleChromeLabs/wasm-bindgen-rayon).
665+
When compiling for WASM, you need to disable default features of this library (compile with `--no-default-features` flag). Otherwise it will use mult-threading, which requires [special handling in WASM](https://github.com/RReverser/wasm-bindgen-rayon).
642666

643667
If you're cross-compiling a dynamic library (so/dylib/DLL), you may need to [configure a linker](https://doc.rust-lang.org/cargo/reference/config.html#target) for Cargo. For building for Android see [this tutorial](https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html) and [cargo-ndk](https://lib.rs/crates/cargo-ndk).

src/quant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl QuantizationResult {
308308
hist.quantize(attr)
309309
}
310310

311-
/// Getter for the value set in [`set_dithering_level`]
311+
/// Getter for the value set in [`Self::set_dithering_level`]
312312
#[must_use]
313313
pub fn dithering_level(&self) -> f32 {
314314
self.dither_level

0 commit comments

Comments
 (0)