{"id":51915693,"url":"https://github.com/lovasoa/libtiff-sys","last_synced_at":"2026-07-27T10:01:18.110Z","repository":{"id":368400174,"uuid":"1284954375","full_name":"lovasoa/libtiff-sys","owner":"lovasoa","description":"Rust bindings to libtiff","archived":false,"fork":false,"pushed_at":"2026-06-30T11:54:49.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-30T12:25:57.109Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://crates.io/crates/libtiff-sys","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovasoa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-30T10:49:14.000Z","updated_at":"2026-06-30T11:54:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/lovasoa/libtiff-sys","commit_stats":null,"previous_names":["lovasoa/libtiff-sys"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/lovasoa/libtiff-sys","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Flibtiff-sys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Flibtiff-sys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Flibtiff-sys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Flibtiff-sys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovasoa","download_url":"https://codeload.github.com/lovasoa/libtiff-sys/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasoa%2Flibtiff-sys/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35947061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-27T02:00:06.776Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-27T10:01:17.437Z","updated_at":"2026-07-27T10:01:18.106Z","avatar_url":"https://github.com/lovasoa.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libtiff-sys\n\nLow-level Rust FFI bindings for `libtiff`.\n\nThis crate links Rust code to the C `libtiff` library and exposes bindings generated from `tiffio.h`. It intentionally stays close to the C API: functions are unsafe, handles must be closed with `TIFFClose`, and varargs functions such as `TIFFSetField` and `TIFFGetField` must be called with the exact C-compatible argument types expected by libtiff.\n\nHigher-level safe APIs should be built in a separate wrapper crate.\n\n## Supported Platforms\n\nThe crate is tested in CI on:\n\n- Linux GNU, native `x86_64-unknown-linux-gnu`\n- Linux musl, cross `x86_64-unknown-linux-musl`\n- Linux GNU, cross `aarch64-unknown-linux-gnu`\n- macOS, native Apple Silicon runner\n- macOS, cross `aarch64-apple-darwin`\n- Windows MSVC, native `x86_64-pc-windows-msvc`\n- Windows MSVC, cross-check `x86_64-pc-windows-msvc`\n\nOther targets may work if CMake, Clang/libclang, a C compiler, and either a target-compatible system `libtiff` or the bundled source build are available.\n\n## Build Modes\n\nThe build script chooses one of three modes, in this order:\n\n1. Explicit system library mode: use `TIFF_LIB_DIR` and optionally `TIFF_INCLUDE_DIR`.\n2. `pkg-config` system library mode: probe `libtiff-4`, then `libtiff`.\n3. Bundled source mode: build the bundled `libtiff` source with CMake inside Cargo's `OUT_DIR` and link it statically.\n\nThe build script exports `DEP_TIFF_INCLUDE` for dependent crates that need to compile C code against the same headers.\n\n## Linking Defaults\n\nIf you do not request a linking mode explicitly:\n\n- Linux and BSD GNU targets prefer dynamic linking when a system library is found through `pkg-config`.\n- macOS defaults to static linking.\n- Windows defaults to static linking.\n- musl targets default to static linking.\n- bundled source builds are always static.\n\nEnvironment variables take precedence over Cargo features.\n\n## Configuration\n\nUse environment variables for top-level build control:\n\n- `TIFF_LIB_DIR`: directory containing a prebuilt `libtiff` library.\n- `TIFF_INCLUDE_DIR`: directory containing `tiffio.h` and related headers. If omitted with `TIFF_LIB_DIR`, the bundled headers are used for binding generation.\n- `TIFF_STATIC=1`: request static linking.\n- `TIFF_DYNAMIC=1`: request dynamic linking.\n- `LIBTIFF_4_NO_PKG_CONFIG=1` or `LIBTIFF_NO_PKG_CONFIG=1`: disable `pkg-config` probing and force the bundled fallback unless `TIFF_LIB_DIR` is set.\n\nCargo features are also available for simple dependency configuration:\n\n- `static`: request static linking when no env var overrides it.\n- `dynamic`: request dynamic linking when no env var overrides it.\n- `jpeg`: enable embedded JPEG compression support in bundled mode by building and statically linking [mozjpeg](https://github.com/mozilla/mozjpeg) (a drop-in libjpeg replacement) via the `mozjpeg-sys` crate. Has no effect in system library modes.\n\nDo not enable both `static` and `dynamic`. If both are enabled, `static` currently wins because Cargo features are additive and cannot be unset by downstream crates.\n\n## Build-Time Dependencies\n\nAll builds need:\n\n- Rust stable\n- Cargo\n- Clang/libclang, required by `bindgen`\n- A C compiler for bundled builds and most cross builds\n\nBundled source mode also needs:\n\n- CMake\n- A target-compatible C compiler\n- C standard library headers for the target\n\nSystem library modes also need:\n\n- `libtiff` headers, including `tiffio.h`\n- A target-compatible `libtiff` library\n- `pkg-config` when using automatic system discovery\n\nExample Linux packages:\n\n```sh\nsudo apt-get install clang libclang-dev cmake pkg-config libtiff-dev\n```\n\nExample macOS packages:\n\n```sh\nbrew install llvm cmake pkg-config libtiff\n```\n\nWindows MSVC builds require Visual Studio Build Tools. Bundled mode is designed to avoid requiring a separate `libtiff` installation.\n\n## Runtime Dependencies\n\nRuntime requirements depend on the selected link mode:\n\n- Static bundled mode: no separate `libtiff` dynamic library is required.\n- Static system mode: no separate `libtiff` dynamic library is required, but any static dependencies selected by the system `libtiff.pc` must also be linkable.\n- Dynamic system mode: the target machine must have a compatible `libtiff` shared library available to the dynamic loader.\n\nIf dynamic linking succeeds at build time but your binary fails to start, check platform loader paths such as `LD_LIBRARY_PATH`, `DYLD_LIBRARY_PATH`, `PATH`, rpath, or your package manager's runtime dependency metadata.\n\n## Bundled libtiff Features\n\nBundled mode intentionally disables optional external codecs by default:\n\n- zlib/deflate\n- JPEG (can be enabled with the `jpeg` Cargo feature — see below)\n- JBIG\n- LERC\n- LZMA\n- ZSTD\n- WebP\n\nThis keeps the fallback build self-contained and avoids accidentally detecting host libraries that are not linked into Rust binaries, which is a common `-sys` crate failure mode. If you need those codecs, use a system `libtiff` built with the desired features and point this crate at it through `pkg-config` or `TIFF_LIB_DIR`/`TIFF_INCLUDE_DIR`.\n\n### JPEG Support (Bundled Mode)\n\nEnable the `jpeg` Cargo feature to add embedded JPEG compression/decompression to the bundled libtiff build:\n\n```toml\n[dependencies]\nlibtiff-sys = { version = \"0.1\", features = [\"jpeg\"] }\n```\n\nThis feature works by:\n\n1. Building [mozjpeg](https://github.com/mozilla/mozjpeg) (a libjpeg-compatible library) from source via the `mozjpeg-sys` crate.\n2. Staging the compiled mozjpeg static library and headers so CMake can find them.\n3. Configuring libtiff's CMake build with `-Djpeg=ON` pointed at the staged artifacts.\n\nThe result is a fully statically-linked `libtiff` with JPEG support — no system `libjpeg` required. On x86_64, mozjpeg's SIMD optimizations are compiled in automatically when NASM is available.\n\n**Limitations:**\n\n- Only applies to the **bundled** build. When using a system libtiff (`TIFF_LIB_DIR` or `pkg-config`), the `jpeg` feature is ignored — your system libtiff must already have JPEG support.\n- Build-time dependency on `mozjpeg-sys` (requires a C compiler; NASM recommended for x86_64 SIMD performance).\n- On ARM targets, SIMD is compiled separately; the build script should handle this automatically.\n- Cross-compilation with the `jpeg` feature requires a cross C compiler that can target the desired architecture.\n\n## Cross-Compilation\n\nFor cross-compilation, prefer one of these approaches:\n\n- Use bundled mode with a target-compatible C compiler and CMake toolchain configuration.\n- Use `TIFF_LIB_DIR` and `TIFF_INCLUDE_DIR` pointing at a target-compatible `libtiff` install.\n- Use `pkg-config` only when it is configured for the target sysroot, not the host.\n\nUseful environment variables include:\n\n- `CC_\u003ctarget\u003e`: C compiler for the target, for example `CC_aarch64-unknown-linux-gnu=aarch64-linux-gnu-gcc`.\n- `CARGO_TARGET_\u003cTARGET\u003e_LINKER`: Rust linker for the target, for example `CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc`.\n- `CMAKE_TOOLCHAIN_FILE`: CMake toolchain file for non-trivial cross builds.\n- `PKG_CONFIG_SYSROOT_DIR`, `PKG_CONFIG_LIBDIR`, and `PKG_CONFIG_ALLOW_CROSS=1`: only when using target-aware `pkg-config`.\n\nDo not let `pkg-config` find host `libtiff` while compiling for another target. Disable it with `LIBTIFF_4_NO_PKG_CONFIG=1` or `LIBTIFF_NO_PKG_CONFIG=1` if in doubt.\n\n## Examples\n\nWrite a small 8-bit grayscale TIFF:\n\n```sh\ncargo run --example write_gray -- /tmp/example-gray.tif\n```\n\nRead basic image metadata:\n\n```sh\ncargo run --example read_info -- /tmp/example-gray.tif\n```\n\nA minimal write flow looks like this:\n\n```rust,no_run\nuse libc::c_void;\nuse libtiff_sys::*;\nuse std::ffi::CString;\n\nunsafe {\n    let path = CString::new(\"out.tif\").unwrap();\n    let mode = CString::new(\"w\").unwrap();\n    let tif = TIFFOpen(path.as_ptr(), mode.as_ptr());\n    assert!(!tif.is_null());\n\n    TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 1u32);\n    TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 1u32);\n    TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1u16 as u32);\n    TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8u16 as u32);\n    TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);\n    TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);\n    TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);\n\n    let pixel = [128u8];\n    TIFFWriteScanline(tif, pixel.as_ptr() as *mut c_void, 0, 0);\n    TIFFClose(tif);\n}\n```\n\n## Testing\n\nThe test suite writes and reads real TIFF files through libtiff:\n\n- library version/linking check\n- scanline write/read round trip\n- scanline copy into a second TIFF and readback\n- encoded strip reads\n- RGBA decoding\n- multi-directory TIFF traversal\n\nRun it with:\n\n```sh\ncargo test\n```\n\nThe GitHub Actions matrix also checks:\n\n- bundled static builds on Linux, macOS, and Windows\n- system `pkg-config` dynamic builds\n- system `pkg-config` static builds\n- examples that create and inspect real TIFF files\n- package tarball verification\n- building without the git submodule when an explicit system `libtiff` is available\n- representative cross-compilation targets\n\n## Troubleshooting\n\nIf `bindgen` cannot find libclang, install Clang/libclang and set `LIBCLANG_PATH` to the directory containing the libclang shared library.\n\nIf linking fails with missing symbols from codecs such as zlib, zstd, jpeg, or lzma, your system `libtiff` was built with optional dependencies that were not linked. Use the bundled mode, install the matching development packages, or fix the `libtiff.pc` metadata used by `pkg-config`.\n\nIf cross-compilation finds the wrong headers or libraries, disable `pkg-config` and either use bundled mode or set `TIFF_LIB_DIR` and `TIFF_INCLUDE_DIR` to target sysroot paths.\n\nIf dynamic binaries fail at runtime, verify the platform dynamic loader can find `libtiff` and any libraries it depends on.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasoa%2Flibtiff-sys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovasoa%2Flibtiff-sys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasoa%2Flibtiff-sys/lists"}