You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
20
20
21
21
## Getting started in Rust
22
22
@@ -57,6 +57,8 @@ If you're building for macOS or iOS, see included xcodeproj file (add it as a [s
57
57
58
58
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`.
59
59
60
+
See [imagequant-sys readme](https://lib.rs/imagequant-sys#readme-building-for-c) for instructions how to make smaller builds.
61
+
60
62
### C dynamic library for package maintainers
61
63
62
64
If you're an application developer, please use the static linking option above — that option is much easier, and gives smaller executables.
Copy file name to clipboardExpand all lines: imagequant-sys/README.md
+30-6Lines changed: 30 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Add to `Cargo.toml`:
18
18
19
19
```toml
20
20
[dependencies]
21
-
imagequant = "4.0"
21
+
imagequant = "4.4"
22
22
```
23
23
24
24
[See docs.rs for the library API documentation](https://docs.rs/imagequant).
@@ -27,23 +27,47 @@ imagequant = "4.0"
27
27
28
28
### Building for C
29
29
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`.
31
31
2.`cd imagequant-sys`
32
32
33
33
The C API is exposed by a separate package called [`imagequant-sys`](https://github.com/ImageOptim/libimagequant/tree/main/imagequant-sys).
34
+
34
35
3. Run `cargo build --release`
35
36
36
37
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`.
38
38
39
39
The repository includes an Xcode project file that can be used on iOS and macOS.
40
40
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:
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:
42
63
43
64
1.`cargo install cargo-c`
44
65
2.`cd imagequant-sys`
45
66
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.
47
71
48
72
### C API usage
49
73
@@ -638,6 +662,6 @@ For animated GIFs see `liq_image_set_background()` which remaps images for GIF's
638
662
639
663
You can compile the library for other platforms via `cargo build --target=…`. See `rustup target list` for the list of platforms.
640
664
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).
642
666
643
667
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).
0 commit comments