libz-sys-1.1.20/.cargo_vcs_info.json0000644000000001360000000000100126710ustar { "git": { "sha1": "38087fcfacc76d85f7360db549438ff490b3efe5" }, "path_in_vcs": "" }libz-sys-1.1.20/Cargo.toml0000644000000043730000000000100106760ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "libz-sys" version = "1.1.20" authors = [ "Alex Crichton ", "Josh Triplett ", "Sebastian Thiel ", ] build = "build.rs" links = "z" include = [ "LICENSE*", "/README.md", "build.rs", "zng/cc.rs", "zng/cmake.rs", "src/*.rs", "src/*.c", "src/zlib/*.[ch]", "src/zlib/*.pc.in", "src/zlib-ng/**.[ch]", "src/zlib-ng/arch/arm/**.[ch]", "src/zlib-ng/arch/generic/**.[ch]", "src/zlib-ng/arch/power/**.[ch]", "src/zlib-ng/arch/riscv/**.[ch]", "src/zlib-ng/arch/s390/**.[ch]", "src/zlib-ng/arch/x86/**.[ch]", "src/zlib-ng/*.[ch].in", "src/zlib-ng/*.pc.in", "src/zlib-ng/zlib_name_mangling.h.empty", "src/zlib-ng/CMakeLists.txt", "src/zlib-ng/zlib.pc.cmakein", "src/zlib-ng/cmake", ] autobins = false autoexamples = false autotests = false autobenches = false description = "Low-level bindings to the system libz library (also known as zlib)." readme = "README.md" keywords = [ "zlib", "zlib-ng", ] categories = [ "compression", "external-ffi-bindings", ] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/libz-sys" [lib] name = "libz_sys" path = "src/lib.rs" [dependencies.libc] version = "0.2.43" optional = true [build-dependencies.cc] version = "1.0.98" [build-dependencies.cmake] version = "0.1.50" optional = true [build-dependencies.pkg-config] version = "0.3.9" [build-dependencies.vcpkg] version = "0.2.11" [features] asm = [] default = [ "libc", "stock-zlib", ] static = [] stock-zlib = [] zlib-ng = [ "libc", "cmake", ] zlib-ng-no-cmake-experimental-community-maintained = ["libc"] [lints.rust.unexpected_cfgs] level = "warn" priority = 0 check-cfg = ["cfg(zng)"] libz-sys-1.1.20/Cargo.toml.orig0000644000000065670000000000100116440ustar [package] name = "libz-sys" version = "1.1.20" authors = [ "Alex Crichton ", "Josh Triplett ", "Sebastian Thiel ", ] links = "z" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/libz-sys" description = "Low-level bindings to the system libz library (also known as zlib)." categories = ["compression", "external-ffi-bindings"] keywords = ["zlib", "zlib-ng"] edition = "2018" include = [ "LICENSE*", "/README.md", "build.rs", "zng/cc.rs", "zng/cmake.rs", "src/*.rs", "src/*.c", "src/zlib/*.[ch]", "src/zlib/*.pc.in", # zlib-ng "src/zlib-ng/**.[ch]", "src/zlib-ng/arch/arm/**.[ch]", "src/zlib-ng/arch/generic/**.[ch]", "src/zlib-ng/arch/power/**.[ch]", "src/zlib-ng/arch/riscv/**.[ch]", "src/zlib-ng/arch/s390/**.[ch]", "src/zlib-ng/arch/x86/**.[ch]", "src/zlib-ng/*.[ch].in", "src/zlib-ng/*.pc.in", "src/zlib-ng/zlib_name_mangling.h.empty", # zlib-ng cmake "src/zlib-ng/CMakeLists.txt", "src/zlib-ng/zlib.pc.cmakein", "src/zlib-ng/cmake", ] [workspace] members = ["systest"] [dependencies] # When this feature is disabled, zlib will be built in Z_SOLO mode which # removes dependency on any external libraries like libc at the cost of # eliminating some high-level functions like gz*, compress* and # uncompress, and requiring embedder to provide memory allocation # routines to deflate and inflate. libc = { version = "0.2.43", optional = true } [build-dependencies] pkg-config = "0.3.9" cc = "1.0.98" cmake = { version = "0.1.50", optional = true } vcpkg = "0.2.11" [features] default = ["libc", "stock-zlib"] # By default, libz-sys uses stock zlib. If you set default-features=false, # enable the zlib-ng feature, and don't enable the stock-zlib feature, libz-sys # will instead supply the high-performance zlib-ng, in zlib-compat mode. Any # application or library designed for zlib should work with zlib-ng in # zlib-compat mode, as long as it doesn't make assumptions about the exact size # or output of the deflated data (e.g. "compressing this data produces exactly # this many bytes"), and as long as you don't also dynamically pull in a copy # of stock zlib (which will produce conflicting symbols). If a single crate in # the dependency graph requests stock-zlib (or doesn't disable default # features), you'll get stock zlib. # # Library crates should use: # libz-sys = { version = "1.1.0", default-features = false, features = ["libc"] } # (Omit the libc feature if you don't require the corresponding functions.) # # This allows higher-level crates depending on your library to opt into zlib-ng # if desired. zlib-ng = ["libc", "cmake"] # Builds zlib-ng from source using cc instead of cmake with all target features # enabled, meaning compilation may not work depending on your target and host # toolchain (eg very old compilers won't have some flags) # # This feature is not maintained by the repo maintainers and can break at any time # or be completely removed in the future zlib-ng-no-cmake-experimental-community-maintained = ["libc"] stock-zlib = [] # Deprecated: the assembly routines are outdated, and either reduce performance # or cause segfaults. asm = [] # Enable this feature if you want to have a statically linked libz static = [] [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zng)'] } libz-sys-1.1.20/Cargo.toml.orig000064400000000000000000000065671046102023000143660ustar 00000000000000[package] name = "libz-sys" version = "1.1.20" authors = [ "Alex Crichton ", "Josh Triplett ", "Sebastian Thiel ", ] links = "z" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/libz-sys" description = "Low-level bindings to the system libz library (also known as zlib)." categories = ["compression", "external-ffi-bindings"] keywords = ["zlib", "zlib-ng"] edition = "2018" include = [ "LICENSE*", "/README.md", "build.rs", "zng/cc.rs", "zng/cmake.rs", "src/*.rs", "src/*.c", "src/zlib/*.[ch]", "src/zlib/*.pc.in", # zlib-ng "src/zlib-ng/**.[ch]", "src/zlib-ng/arch/arm/**.[ch]", "src/zlib-ng/arch/generic/**.[ch]", "src/zlib-ng/arch/power/**.[ch]", "src/zlib-ng/arch/riscv/**.[ch]", "src/zlib-ng/arch/s390/**.[ch]", "src/zlib-ng/arch/x86/**.[ch]", "src/zlib-ng/*.[ch].in", "src/zlib-ng/*.pc.in", "src/zlib-ng/zlib_name_mangling.h.empty", # zlib-ng cmake "src/zlib-ng/CMakeLists.txt", "src/zlib-ng/zlib.pc.cmakein", "src/zlib-ng/cmake", ] [workspace] members = ["systest"] [dependencies] # When this feature is disabled, zlib will be built in Z_SOLO mode which # removes dependency on any external libraries like libc at the cost of # eliminating some high-level functions like gz*, compress* and # uncompress, and requiring embedder to provide memory allocation # routines to deflate and inflate. libc = { version = "0.2.43", optional = true } [build-dependencies] pkg-config = "0.3.9" cc = "1.0.98" cmake = { version = "0.1.50", optional = true } vcpkg = "0.2.11" [features] default = ["libc", "stock-zlib"] # By default, libz-sys uses stock zlib. If you set default-features=false, # enable the zlib-ng feature, and don't enable the stock-zlib feature, libz-sys # will instead supply the high-performance zlib-ng, in zlib-compat mode. Any # application or library designed for zlib should work with zlib-ng in # zlib-compat mode, as long as it doesn't make assumptions about the exact size # or output of the deflated data (e.g. "compressing this data produces exactly # this many bytes"), and as long as you don't also dynamically pull in a copy # of stock zlib (which will produce conflicting symbols). If a single crate in # the dependency graph requests stock-zlib (or doesn't disable default # features), you'll get stock zlib. # # Library crates should use: # libz-sys = { version = "1.1.0", default-features = false, features = ["libc"] } # (Omit the libc feature if you don't require the corresponding functions.) # # This allows higher-level crates depending on your library to opt into zlib-ng # if desired. zlib-ng = ["libc", "cmake"] # Builds zlib-ng from source using cc instead of cmake with all target features # enabled, meaning compilation may not work depending on your target and host # toolchain (eg very old compilers won't have some flags) # # This feature is not maintained by the repo maintainers and can break at any time # or be completely removed in the future zlib-ng-no-cmake-experimental-community-maintained = ["libc"] stock-zlib = [] # Deprecated: the assembly routines are outdated, and either reduce performance # or cause segfaults. asm = [] # Enable this feature if you want to have a statically linked libz static = [] [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zng)'] } libz-sys-1.1.20/LICENSE-APACHE000064400000000000000000000251371046102023000134150ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. libz-sys-1.1.20/LICENSE-MIT000064400000000000000000000021021046102023000131100ustar 00000000000000Copyright (c) 2014 Alex Crichton Copyright (c) 2020 Josh Triplett Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libz-sys-1.1.20/README.md000064400000000000000000000062141046102023000127430ustar 00000000000000# libz-sys A common library for linking `libz` to Rust programs (also known as zlib). [Documentation](https://docs.rs/libz-sys) This also serves as the source for the `libz-ng-sys` crate, which builds zlib-ng natively (not in zlib-compat mode). See [`README-zng.md`](README-zng.md) for details. # High-level API This crate provides bindings to the raw low-level C API. For a higher-level safe API to work with DEFLATE, zlib, or gzip streams, see [`flate2`](https://docs.rs/flate2). `flate2` also supports alternative implementations, including slower but pure Rust implementations. # zlib-ng This crate supports building either the high-performance zlib-ng (in zlib-compat mode), or the widely available stock zlib. By default, `libz-sys` uses stock zlib, primarily because doing so allows the use of a shared system zlib library if available. Any application or library designed for zlib should work with zlib-ng in zlib-compat mode, as long as it doesn't make assumptions about the exact size or output of the deflated data (e.g. "compressing this data produces exactly this many bytes"), and as long as you don't also dynamically pull in a copy of stock zlib (which will produce conflicting symbols). Nonetheless, for maximum compatibility, every library crate in a build must opt into allowing zlib-ng; if any library crate in your dependency graph wants stock zlib, `libz-sys` will use stock zlib. Library crates depending on `libz-sys` should use: ```toml libz-sys = { version = "1.1", default-features = false, features = ["libc"] } ``` (Omit the `libc` feature if you don't require the corresponding functions.) This allows higher-level crates depending on your library to opt into zlib-ng if desired. Building zlib-ng requires `cmake` unless the `zlib-ng-no-cmake-experimental-community-maintained` feature is enabled, in which case `cc` is used instead. Note that this option enables _all_ compiler features that are supported for the given target, which may not compile on older compilers or targets without certain headers. Crates that don't require compatibility with the zlib C API, and use zlib exclusively from Rust or support the zlib-ng native C API (prefixed with `zng_`) can use [`libz-ng-sys`](https://crates.io/crates/libz-ng-sys) instead, which allows zlib and zlib-ng to coexist in the same program. See [README-zng.md](README-zng.md) for details. # Minimum Supported Rust Version (MSRV) Policy This crate uses the same MSRV policy as the [`flate2`](https://crates.io/crates/flate2) crate: This crate supports the current and previous stable versions of Rust. Older versions of Rust may work, but we don't guarantee these will continue to work. # License This project is licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `libz-sys` by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. libz-sys-1.1.20/build.rs000064400000000000000000000171641046102023000131370ustar 00000000000000use std::env; use std::fs; use std::path::PathBuf; fn main() { println!("cargo:rerun-if-env-changed=LIBZ_SYS_STATIC"); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=zng/cmake.rs"); println!("cargo:rerun-if-changed=zng/cc.rs"); let host = env::var("HOST").unwrap(); let target = env::var("TARGET").unwrap(); let host_and_target_contain = |s| host.contains(s) && target.contains(s); let want_ng = cfg!(any( feature = "zlib-ng", feature = "zlib-ng-no-cmake-experimental-community-maintained" )) && !cfg!(feature = "stock-zlib"); if want_ng && target != "wasm32-unknown-unknown" { return build_zlib_ng(&target, true); } // All android compilers should come with libz by default, so let's just use // the one already there. Likewise, Haiku always ships with libz, so we can // link to it even when cross-compiling. if target.contains("android") || target.contains("haiku") { println!("cargo:rustc-link-lib=z"); return; } // Don't run pkg-config if we're linking statically (we'll build below) and // also don't run pkg-config on FreeBSD/DragonFly. That'll end up printing // `-L /usr/lib` which wreaks havoc with linking to an OpenSSL in /usr/local/lib // (Ports, etc.) let want_static = cfg!(feature = "static") || env::var("LIBZ_SYS_STATIC").unwrap_or(String::new()) == "1"; if !want_static && !target.contains("msvc") && // pkg-config just never works here !(host_and_target_contain("freebsd") || host_and_target_contain("dragonfly")) { // Don't print system lib dirs to cargo since this interferes with other // packages adding non-system search paths to link against libraries // that are also found in a system-wide lib dir. let zlib = pkg_config::Config::new() .cargo_metadata(true) .print_system_libs(false) .probe("zlib"); match zlib { Ok(zlib) => { if !zlib.include_paths.is_empty() { let paths = zlib .include_paths .iter() .map(|s| s.display().to_string()) .collect::>(); println!("cargo:include={}", paths.join(",")); } } Err(e) => { println!("cargo-warning={}", e.to_string()) } } } if target.contains("windows") { if try_vcpkg() { return; } } let mut cfg = cc::Build::new(); // Situations where we build unconditionally. // // MSVC basically never has it preinstalled, MinGW picks up a bunch of weird // paths we don't like, `want_static` may force us, and cross compiling almost // never has a prebuilt version. // // Apple platforms have libz.1.dylib, and it's usually available even when // cross compiling (via fat binary or in the target's Xcode SDK) let cross_compiling = target != host; if target.contains("msvc") || target.contains("pc-windows-gnu") || want_static || (cross_compiling && !target.contains("-apple-")) { return build_zlib(&mut cfg, &target); } // If we've gotten this far we're probably a pretty standard platform. // Almost all platforms here ship libz by default, but some don't have // pkg-config files that we would find above. // // In any case test if zlib is actually installed and if so we link to it, // otherwise continue below to build things. if zlib_installed(&mut cfg) { println!("cargo:rustc-link-lib=z"); return; } build_zlib(&mut cfg, &target) } fn build_zlib(cfg: &mut cc::Build, target: &str) { let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap()); let lib = dst.join("lib"); cfg.warnings(false).out_dir(&lib).include("src/zlib"); cfg.file("src/zlib/adler32.c") .file("src/zlib/compress.c") .file("src/zlib/crc32.c") .file("src/zlib/deflate.c") .file("src/zlib/infback.c") .file("src/zlib/inffast.c") .file("src/zlib/inflate.c") .file("src/zlib/inftrees.c") .file("src/zlib/trees.c") .file("src/zlib/uncompr.c") .file("src/zlib/zutil.c"); if !cfg!(feature = "libc") || target.starts_with("wasm32") { cfg.define("Z_SOLO", None); } else { cfg.file("src/zlib/gzclose.c") .file("src/zlib/gzlib.c") .file("src/zlib/gzread.c") .file("src/zlib/gzwrite.c"); } if !target.contains("windows") { cfg.define("STDC", None); cfg.define("_LARGEFILE64_SOURCE", None); cfg.define("_POSIX_SOURCE", None); cfg.flag("-fvisibility=hidden"); } if target.contains("apple") { cfg.define("_C99_SOURCE", None); } if target.contains("solaris") { cfg.define("_XOPEN_SOURCE", "700"); } cfg.compile("z"); fs::create_dir_all(dst.join("include")).unwrap(); fs::copy("src/zlib/zlib.h", dst.join("include/zlib.h")).unwrap(); fs::copy("src/zlib/zconf.h", dst.join("include/zconf.h")).unwrap(); fs::create_dir_all(lib.join("pkgconfig")).unwrap(); let zlib_h = fs::read_to_string(dst.join("include/zlib.h")).unwrap(); let version = zlib_h .lines() .find(|l| l.contains("ZLIB_VERSION")) .unwrap() .split("\"") .nth(1) .unwrap(); fs::write( lib.join("pkgconfig/zlib.pc"), fs::read_to_string("src/zlib/zlib.pc.in") .unwrap() .replace("@prefix@", dst.to_str().unwrap()) .replace("@includedir@", "${prefix}/include") .replace("@libdir@", "${prefix}/lib") .replace("@VERSION@", version), ) .unwrap(); println!("cargo:root={}", dst.to_str().unwrap()); println!("cargo:rustc-link-search=native={}", lib.to_str().unwrap()); println!("cargo:include={}/include", dst.to_str().unwrap()); } #[cfg(any( feature = "zlib-ng", feature = "zlib-ng-no-cmake-experimental-community-maintained" ))] mod zng { #[cfg_attr(feature = "zlib-ng", path = "cmake.rs")] #[cfg_attr( all( feature = "zlib-ng-no-cmake-experimental-community-maintained", not(feature = "zlib-ng") ), path = "cc.rs" )] mod build_zng; pub(super) use build_zng::build_zlib_ng; } fn build_zlib_ng(_target: &str, _compat: bool) { #[cfg(any( feature = "zlib-ng", feature = "zlib-ng-no-cmake-experimental-community-maintained" ))] zng::build_zlib_ng(_target, _compat); } fn try_vcpkg() -> bool { // see if there is a vcpkg tree with zlib installed match vcpkg::Config::new() .emit_includes(true) .find_package("zlib") { Ok(zlib) => { if !zlib.include_paths.is_empty() { let paths = zlib .include_paths .iter() .map(|s| s.display().to_string()) .collect::>(); println!("cargo:include={}", paths.join(",")); } true } Err(e) => { println!("note, vcpkg did not find zlib: {}", e); false } } } fn zlib_installed(cfg: &mut cc::Build) -> bool { let mut cmd = cfg.get_compiler().to_command(); cmd.arg("src/smoke.c") .arg("-g0") .arg("-o") .arg("/dev/null") .arg("-lz"); println!("running {:?}", cmd); if let Ok(status) = cmd.status() { if status.success() { return true; } } false } libz-sys-1.1.20/src/lib.rs000064400000000000000000000327201046102023000133700ustar 00000000000000#![allow(non_camel_case_types)] #![allow(non_snake_case)] use std::os::raw::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void}; // Macro for variances between zlib-ng in native mode and either zlib or zlib-ng in zlib compat // mode. Note in particular that zlib-ng in compat mode does *not* use the zng case. #[cfg(not(zng))] macro_rules! if_zng { ($_zng:tt, $not_zng:tt) => { $not_zng }; } #[cfg(zng)] macro_rules! if_zng { ($zng:tt, $_not_zng:tt) => { $zng }; } // zlib uses unsigned long for various sizes; zlib-ng uses size_t. type z_size = if_zng!(usize, c_ulong); // zlib stores Adler-32 and CRC-32 checksums in unsigned long; zlib-ng uses uint32_t. type z_checksum = if_zng!(u32, c_ulong); pub type alloc_func = unsafe extern "C" fn(voidpf, uInt, uInt) -> voidpf; pub type Bytef = u8; pub type free_func = unsafe extern "C" fn(voidpf, voidpf); #[cfg(any(zng, feature = "libc"))] pub type gzFile = *mut gzFile_s; pub type in_func = unsafe extern "C" fn(*mut c_void, *mut *const c_uchar) -> c_uint; pub type out_func = unsafe extern "C" fn(*mut c_void, *mut c_uchar, c_uint) -> c_int; pub type uInt = c_uint; pub type uLong = c_ulong; pub type uLongf = c_ulong; pub type voidp = *mut c_void; pub type voidpc = *const c_void; pub type voidpf = *mut c_void; #[cfg(any(zng, feature = "libc"))] pub enum gzFile_s {} pub enum internal_state {} #[cfg(all( not(zng), feature = "libc", not(all(target_family = "wasm", target_os = "unknown")) ))] pub type z_off_t = libc::off_t; #[cfg(all( not(zng), feature = "libc", all(target_family = "wasm", target_os = "unknown") ))] pub type z_off_t = c_long; #[cfg(all(zng, windows, not(target_env = "gnu")))] pub type z_off_t = i64; #[cfg(all(zng, not(all(windows, not(target_env = "gnu")))))] pub type z_off_t = libc::off_t; #[repr(C)] #[derive(Copy, Clone)] pub struct gz_header { pub text: c_int, pub time: uLong, pub xflags: c_int, pub os: c_int, pub extra: *mut Bytef, pub extra_len: uInt, pub extra_max: uInt, pub name: *mut Bytef, pub name_max: uInt, pub comment: *mut Bytef, pub comm_max: uInt, pub hcrc: c_int, pub done: c_int, } pub type gz_headerp = *mut gz_header; #[repr(C)] #[derive(Copy, Clone)] pub struct z_stream { pub next_in: *mut Bytef, pub avail_in: uInt, pub total_in: z_size, pub next_out: *mut Bytef, pub avail_out: uInt, pub total_out: z_size, pub msg: *mut c_char, pub state: *mut internal_state, pub zalloc: alloc_func, pub zfree: free_func, pub opaque: voidpf, pub data_type: c_int, pub adler: z_checksum, pub reserved: uLong, } pub type z_streamp = *mut z_stream; // Ideally, this should instead use a macro that parses the whole block of externs, and generates // the appropriate link_name attributes, without duplicating the function names. However, ctest2 // can't parse that. #[cfg(not(zng))] macro_rules! zng_prefix { ($name:expr) => { stringify!($name) }; } #[cfg(zng)] macro_rules! zng_prefix { ($name:expr) => { concat!("zng_", stringify!($name)) }; } extern "C" { #[link_name = zng_prefix!(adler32)] pub fn adler32(adler: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum; #[link_name = zng_prefix!(crc32)] pub fn crc32(crc: z_checksum, buf: *const Bytef, len: uInt) -> z_checksum; #[link_name = zng_prefix!(deflate)] pub fn deflate(strm: z_streamp, flush: c_int) -> c_int; #[link_name = zng_prefix!(deflateBound)] pub fn deflateBound(strm: z_streamp, sourceLen: uLong) -> uLong; #[link_name = zng_prefix!(deflateCopy)] pub fn deflateCopy(dest: z_streamp, source: z_streamp) -> c_int; #[link_name = zng_prefix!(deflateEnd)] pub fn deflateEnd(strm: z_streamp) -> c_int; #[link_name = zng_prefix!(deflateParams)] pub fn deflateParams(strm: z_streamp, level: c_int, strategy: c_int) -> c_int; #[link_name = zng_prefix!(deflatePrime)] pub fn deflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int; #[link_name = zng_prefix!(deflateReset)] pub fn deflateReset(strm: z_streamp) -> c_int; #[link_name = zng_prefix!(deflateSetDictionary)] pub fn deflateSetDictionary( strm: z_streamp, dictionary: *const Bytef, dictLength: uInt, ) -> c_int; #[link_name = zng_prefix!(deflateSetHeader)] pub fn deflateSetHeader(strm: z_streamp, head: gz_headerp) -> c_int; #[link_name = zng_prefix!(deflateTune)] pub fn deflateTune( strm: z_streamp, good_length: c_int, max_lazy: c_int, nice_length: c_int, max_chain: c_int, ) -> c_int; #[link_name = zng_prefix!(inflate)] pub fn inflate(strm: z_streamp, flush: c_int) -> c_int; #[link_name = zng_prefix!(inflateBack)] pub fn inflateBack( strm: z_streamp, _in: in_func, in_desc: *mut c_void, out: out_func, out_desc: *mut c_void, ) -> c_int; #[link_name = zng_prefix!(inflateBackEnd)] pub fn inflateBackEnd(strm: z_streamp) -> c_int; #[link_name = zng_prefix!(inflateCopy)] pub fn inflateCopy(dest: z_streamp, source: z_streamp) -> c_int; #[link_name = zng_prefix!(inflateEnd)] pub fn inflateEnd(strm: z_streamp) -> c_int; #[link_name = zng_prefix!(inflateGetHeader)] pub fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int; #[link_name = zng_prefix!(inflateMark)] pub fn inflateMark(strm: z_streamp) -> c_long; #[link_name = zng_prefix!(inflatePrime)] pub fn inflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int; #[link_name = zng_prefix!(inflateReset)] pub fn inflateReset(strm: z_streamp) -> c_int; #[link_name = zng_prefix!(inflateReset2)] pub fn inflateReset2(strm: z_streamp, windowBits: c_int) -> c_int; #[link_name = zng_prefix!(inflateSetDictionary)] pub fn inflateSetDictionary( strm: z_streamp, dictionary: *const Bytef, dictLength: uInt, ) -> c_int; #[link_name = zng_prefix!(inflateSync)] pub fn inflateSync(strm: z_streamp) -> c_int; #[link_name = zng_prefix!(zlibCompileFlags)] pub fn zlibCompileFlags() -> uLong; // The above set of functions currently target 1.2.3.4 (what's present on Ubuntu // 12.04, but there's some other APIs that were added later. Should figure out // how to expose them... // // Added in 1.2.5.1 // // pub fn deflatePending(strm: z_streamp, // pending: *mut c_uint, // bits: *mut c_int) -> c_int; // // Addedin 1.2.7.1 // pub fn inflateGetDictionary(strm: z_streamp, // dictionary: *mut Bytef, // dictLength: *mut uInt) -> c_int; // // Added in 1.2.3.5 // pub fn gzbuffer(file: gzFile, size: c_uint) -> c_int; // pub fn gzclose_r(file: gzFile) -> c_int; // pub fn gzclose_w(file: gzFile) -> c_int; // pub fn gzoffset(file: gzFile) -> z_off_t; } extern "C" { #[link_name = if_zng!("zlibng_version", "zlibVersion")] pub fn zlibVersion() -> *const c_char; } #[cfg(not(zng))] extern "C" { pub fn deflateInit_( strm: z_streamp, level: c_int, version: *const c_char, stream_size: c_int, ) -> c_int; pub fn deflateInit2_( strm: z_streamp, level: c_int, method: c_int, windowBits: c_int, memLevel: c_int, strategy: c_int, version: *const c_char, stream_size: c_int, ) -> c_int; pub fn inflateBackInit_( strm: z_streamp, windowBits: c_int, window: *mut c_uchar, version: *const c_char, stream_size: c_int, ) -> c_int; pub fn inflateInit_(strm: z_streamp, version: *const c_char, stream_size: c_int) -> c_int; pub fn inflateInit2_( strm: z_streamp, windowBits: c_int, version: *const c_char, stream_size: c_int, ) -> c_int; } #[cfg(zng)] extern "C" { pub fn zng_deflateInit(strm: z_streamp, level: c_int) -> c_int; pub fn zng_deflateInit2( strm: z_streamp, level: c_int, method: c_int, windowBits: c_int, memLevel: c_int, strategy: c_int, ) -> c_int; pub fn zng_inflateBackInit(strm: z_streamp, windowBits: c_int, window: *mut c_uchar) -> c_int; pub fn zng_inflateInit(strm: z_streamp) -> c_int; pub fn zng_inflateInit2(strm: z_streamp, windowBits: c_int) -> c_int; } // These methods are required to keep BC with original zlib API since zlib-ng 2.1 that changed API #[cfg(zng)] #[inline(always)] pub unsafe fn inflateInit2_( strm: z_streamp, windowBits: c_int, _version: *const c_char, _stream_size: c_int, ) -> c_int { zng_inflateInit2(strm, windowBits) } #[cfg(zng)] #[inline(always)] pub unsafe fn inflateInit_(strm: z_streamp, _version: *const c_char, _stream_size: c_int) -> c_int { zng_inflateInit(strm) } #[cfg(zng)] #[inline(always)] pub unsafe fn inflateBackInit_( strm: z_streamp, windowBits: c_int, window: *mut c_uchar, _version: *const c_char, _stream_size: c_int, ) -> c_int { zng_inflateBackInit(strm, windowBits, window) } #[cfg(zng)] #[inline(always)] pub unsafe fn deflateInit2_( strm: z_streamp, level: c_int, method: c_int, windowBits: c_int, memLevel: c_int, strategy: c_int, _version: *const c_char, _stream_size: c_int, ) -> c_int { zng_deflateInit2(strm, level, method, windowBits, memLevel, strategy) } #[cfg(zng)] #[inline] pub unsafe fn deflateInit_( strm: z_streamp, level: c_int, _version: *const c_char, _stream_size: c_int, ) -> c_int { zng_deflateInit(strm, level) } #[cfg(any(zng, feature = "libc"))] extern "C" { #[link_name = zng_prefix!(adler32_combine)] pub fn adler32_combine(adler1: z_checksum, adler2: z_checksum, len2: z_off_t) -> z_checksum; #[link_name = zng_prefix!(compress)] pub fn compress( dest: *mut Bytef, destLen: *mut z_size, source: *const Bytef, sourceLen: z_size, ) -> c_int; #[link_name = zng_prefix!(compress2)] pub fn compress2( dest: *mut Bytef, destLen: *mut z_size, source: *const Bytef, sourceLen: z_size, level: c_int, ) -> c_int; #[link_name = zng_prefix!(compressBound)] pub fn compressBound(sourceLen: z_size) -> z_size; #[link_name = zng_prefix!(crc32_combine)] pub fn crc32_combine(crc1: z_checksum, crc2: z_checksum, len2: z_off_t) -> z_checksum; #[link_name = zng_prefix!(gzdirect)] pub fn gzdirect(file: gzFile) -> c_int; #[link_name = zng_prefix!(gzdopen)] pub fn gzdopen(fd: c_int, mode: *const c_char) -> gzFile; #[link_name = zng_prefix!(gzclearerr)] pub fn gzclearerr(file: gzFile); #[link_name = zng_prefix!(gzclose)] pub fn gzclose(file: gzFile) -> c_int; #[link_name = zng_prefix!(gzeof)] pub fn gzeof(file: gzFile) -> c_int; #[link_name = zng_prefix!(gzerror)] pub fn gzerror(file: gzFile, errnum: *mut c_int) -> *const c_char; #[link_name = zng_prefix!(gzflush)] pub fn gzflush(file: gzFile, flush: c_int) -> c_int; #[link_name = zng_prefix!(gzgetc)] pub fn gzgetc(file: gzFile) -> c_int; #[link_name = zng_prefix!(gzgets)] pub fn gzgets(file: gzFile, buf: *mut c_char, len: c_int) -> *mut c_char; #[link_name = zng_prefix!(gzopen)] pub fn gzopen(path: *const c_char, mode: *const c_char) -> gzFile; #[link_name = zng_prefix!(gzputc)] pub fn gzputc(file: gzFile, c: c_int) -> c_int; #[link_name = zng_prefix!(gzputs)] pub fn gzputs(file: gzFile, s: *const c_char) -> c_int; #[link_name = zng_prefix!(gzread)] pub fn gzread(file: gzFile, buf: voidp, len: c_uint) -> c_int; #[link_name = zng_prefix!(gzrewind)] pub fn gzrewind(file: gzFile) -> c_int; #[link_name = zng_prefix!(gzseek)] pub fn gzseek(file: gzFile, offset: z_off_t, whence: c_int) -> z_off_t; #[link_name = zng_prefix!(gzsetparams)] pub fn gzsetparams(file: gzFile, level: c_int, strategy: c_int) -> c_int; #[link_name = zng_prefix!(gztell)] pub fn gztell(file: gzFile) -> z_off_t; #[link_name = zng_prefix!(gzungetc)] pub fn gzungetc(c: c_int, file: gzFile) -> c_int; #[link_name = zng_prefix!(gzwrite)] pub fn gzwrite(file: gzFile, buf: voidpc, len: c_uint) -> c_int; #[link_name = zng_prefix!(uncompress)] pub fn uncompress( dest: *mut Bytef, destLen: *mut z_size, source: *const Bytef, sourceLen: z_size, ) -> c_int; } pub const Z_NO_FLUSH: c_int = 0; pub const Z_PARTIAL_FLUSH: c_int = 1; pub const Z_SYNC_FLUSH: c_int = 2; pub const Z_FULL_FLUSH: c_int = 3; pub const Z_FINISH: c_int = 4; pub const Z_BLOCK: c_int = 5; pub const Z_TREES: c_int = 6; pub const Z_OK: c_int = 0; pub const Z_STREAM_END: c_int = 1; pub const Z_NEED_DICT: c_int = 2; pub const Z_ERRNO: c_int = -1; pub const Z_STREAM_ERROR: c_int = -2; pub const Z_DATA_ERROR: c_int = -3; pub const Z_MEM_ERROR: c_int = -4; pub const Z_BUF_ERROR: c_int = -5; pub const Z_VERSION_ERROR: c_int = -6; pub const Z_NO_COMPRESSION: c_int = 0; pub const Z_BEST_SPEED: c_int = 1; pub const Z_BEST_COMPRESSION: c_int = 9; pub const Z_DEFAULT_COMPRESSION: c_int = -1; pub const Z_FILTERED: c_int = 1; pub const Z_HUFFMAN_ONLY: c_int = 2; pub const Z_RLE: c_int = 3; pub const Z_FIXED: c_int = 4; pub const Z_DEFAULT_STRATEGY: c_int = 0; pub const Z_BINARY: c_int = 0; pub const Z_TEXT: c_int = 1; pub const Z_ASCII: c_int = Z_TEXT; pub const Z_UNKNOWN: c_int = 2; pub const Z_DEFLATED: c_int = 8; libz-sys-1.1.20/src/smoke.c000064400000000000000000000000721046102023000135310ustar 00000000000000#include int main() { return (int) adler32; } libz-sys-1.1.20/zng/cc.rs000064400000000000000000000351471046102023000132240ustar 00000000000000use std::{ env, fs, io::Write as _, path::{Path, PathBuf}, }; struct Build { cfg: cc::Build, is_msvc: bool, } impl Build { fn new(cfg: cc::Build) -> Self { let is_msvc = cfg.try_get_compiler().unwrap().is_like_msvc(); Self { cfg, is_msvc } } fn append(&mut self, root: Option<&str>, files: &[&str]) { let root = root.map_or(String::new(), |s| { assert!(!s.ends_with('/'), "remove trailing slash"); format!("{s}/") }); self.cfg.files( files .into_iter() .map(|fname| format!("src/zlib-ng/{root}{fname}.c")), ); } fn mflag( &mut self, non_msvc: impl Into>, msvc: impl Into>, ) { let Some(flag) = (if self.is_msvc { msvc.into() } else { non_msvc.into() }) else { return; }; self.cfg.flag(flag); } } impl std::ops::Deref for Build { type Target = cc::Build; fn deref(&self) -> &Self::Target { &self.cfg } } impl std::ops::DerefMut for Build { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.cfg } } /// Replicate the behavior of cmake/make/configure of stripping out the /// @ZLIB_SYMBOL_PREFIX@ since we don't want or need it fn strip_symbol_prefix(input: &Path, output: &Path, get_version: bool) -> String { let contents = fs::read_to_string(input) .map_err(|err| format!("failed to read {input:?}: {err}")) .unwrap(); let mut h = std::io::BufWriter::new(fs::File::create(output).expect("failed to create zlib include")); use std::io::IoSlice; let mut write = |bufs: &[IoSlice]| { // write_all_vectored is unstable for buf in bufs { h.write_all(&buf).unwrap(); } }; let mut version = None; for line in contents.lines() { if let Some((begin, end)) = line.split_once("@ZLIB_SYMBOL_PREFIX@") { write(&[ IoSlice::new(begin.as_bytes()), IoSlice::new(end.as_bytes()), IoSlice::new(b"\n"), ]); } else { write(&[IoSlice::new(line.as_bytes()), IoSlice::new(b"\n")]); } if get_version { if line.contains("ZLIBNG_VERSION") && line.contains("#define") { version = Some(line.split('"').nth(1).unwrap().to_owned()); } } } if get_version { version.expect("failed to detect ZLIBNG_VERSION") } else { String::new() } } pub fn build_zlib_ng(target: &str, compat: bool) { let mut cfg = cc::Build::new(); let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap()); let lib = dst.join("lib"); cfg.warnings(false).out_dir(&lib); let mut cfg = Build::new(cfg); cfg.append( None, &[ "adler32", "adler32_fold", "chunkset", "compare256", "compress", "cpu_features", "crc32_braid", "crc32_braid_comb", "crc32_fold", "deflate", "deflate_fast", "deflate_huff", "deflate_medium", "deflate_quick", "deflate_rle", "deflate_slow", "deflate_stored", "functable", // GZFILEOP "gzlib", "gzwrite", "infback", "inflate", "inftrees", "insert_string", "insert_string_roll", "slide_hash", "trees", "uncompr", "zutil", ], ); if compat { cfg.define("ZLIB_COMPAT", None); } cfg.define("WITH_GZFILEOP", None); { let mut build = dst.join("build"); fs::create_dir_all(&build).unwrap(); build.push("gzread.c"); strip_symbol_prefix(Path::new("src/zlib-ng/gzread.c.in"), &build, false); cfg.file(build); } let msvc = target.ends_with("pc-windows-msvc"); cfg.std("c11"); // This can be made configurable if it is an issue but most of these would // only fail if the user was on a decade old+ libc impl if !msvc { cfg.define("HAVE_ALIGNED_ALLOC", None) .define("HAVE_ATTRIBUTE_ALIGNED", None) .define("HAVE_BUILTIN_CTZ", None) .define("HAVE_BUILTIN_CTZLL", None) .define("HAVE_THREAD_LOCAL", None) .define("HAVE_VISIBILITY_HIDDEN", None) .define("HAVE_VISIBILITY_INTERNAL", None) .define("_LARGEFILE64_SOURCE", "1") .define("__USE_LARGEFILE64", None); // Turn implicit functions into errors, this would indicate eg. a // define is not set cfg.flag("-Werror-implicit-function-declaration"); } if !target.contains("windows") { cfg.define("STDC", None) .define("_POSIX_SOURCE", None) .define("HAVE_POSIX_MEMALIGN", None) .flag("-fvisibility=hidden"); } if target.contains("apple") { cfg.define("_C99_SOURCE", None); } else if target.contains("solaris") { cfg.define("_XOPEN_SOURCE", "700"); } let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("failed to retrieve target arch"); let features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap(); let is_linux_or_android = matches!(target_os.as_str(), "linux" | "android"); if is_linux_or_android { cfg.define("HAVE_SYS_AUXV_H", None); } match arch.as_str() { "x86_64" | "i686" => { cfg.define("X86_FEATURES", None); cfg.file("src/zlib-ng/arch/x86/x86_features.c"); let is_64 = arch.as_str() == "x86_64"; // AVX2 cfg.define("X86_AVX2", None); cfg.append( Some("arch/x86"), &[ "chunkset_avx2", "compare256_avx2", "adler32_avx2", "slide_hash_avx2", ], ); cfg.mflag("-mavx2", "/arch:AVX2"); // SSE2 cfg.define("X86_SSE2", None); cfg.append( Some("arch/x86"), &["chunkset_sse2", "compare256_sse2", "slide_hash_sse2"], ); cfg.mflag("-msse2", (!is_64).then_some("/arch:SSE2")); // SSE3 cfg.define("X86_SSSE3", None); cfg.append(Some("arch/x86"), &["adler32_ssse3", "chunkset_ssse3"]); cfg.mflag("-msse3", "/arch:SSE3"); // SSE4.2 cfg.define("X86_SSE42", None); cfg.append(Some("arch/x86"), &["adler32_sse42", "insert_string_sse42"]); cfg.mflag("-msse4.2", "/arch:SSE4.2"); // AVX-512 { for def in &[ "X86_AVX512", "X86_MASK_INTRIN", "X86_AVX512VNNI", "X86_VPCLMULQDQ_CRC", ] { cfg.define(def, None); } cfg.append( Some("arch/x86"), &["adler32_avx512", "adler32_avx512_vnni", "crc32_vpclmulqdq"], ); if cfg.is_msvc { cfg.flag("/arch:AVX512"); } else { // The zlib-ng cmake scripts to check target features claim that GCC doesn't // generate good code unless mtune is set, not sure if this is still the // case, but we faithfully replicate it just in case for flag in &[ "-mavx512f", "-mavx512dq", "-mavx512bw", "-mavx512vl", "-mavx512vnni", "-mvpclmulqdq", "-mtune=cascadelake", ] { cfg.flag(flag); } } } // Misc cfg.define("X86_PCLMULQDQ_CRC", None); cfg.append(Some("arch/x86"), &["crc32_pclmulqdq"]); cfg.mflag("-mpclmul", None); cfg.mflag("-mxsave", None); } "aarch64" | "arm" => { let is_aarch64 = arch == "aarch64"; cfg.define("ARM_FEATURES", None); cfg.file("src/zlib-ng/arch/arm/arm_features.c"); // Support runtime detection on linux/android if is_linux_or_android { cfg.define("ARM_AUXV_HAS_CRC32", None); if !is_aarch64 { cfg.define("ARM_AUXV_HAS_NEON", None); } } // According to the cmake macro, MSVC is missing the crc32 intrinsic // for arm, don't know if that is still true though if !cfg.is_msvc || is_aarch64 { cfg.define("ARM_ACLE", None).define("HAVE_ARM_ACLE_H", None); cfg.append(Some("arch/arm"), &["crc32_acle", "insert_string_acle"]); // When targeting aarch64 we already need to specify +simd, so // we do that once later in this block if !is_aarch64 { cfg.mflag("-march=armv8-a+crc", None); cfg.define("ARM_ASM_HWCAP", None); } } // neon // Fix armv7-unknown-linux-musleabi and arm-unknown-linux-musleabi by only // passing in ARM_NEON if that target is enabled. if features.split(",").any(|name| name == "neon") { cfg.define("ARM_NEON", None); } // NOTE: These intrinsics were only added in gcc 9.4, which is _relatively_ // recent, and if the define is not set zlib-ng just provides its // own implements, so maybe in a couple of years this can be toggled on // if building with cc is merged it makes sense to put compiler intrinsic/header // probing in a separate crate that can then be used here to enable // those intrinsics if the compiler supports them // * vld1q_u16_x4 // * vld1q_u8_x4 // * vst1q_u16_x4 // cfg.define("ARM_NEON_HASLD4", None) if cfg.is_msvc { cfg.define("__ARM_NEON__", None); } cfg.append( Some("arch/arm"), &[ "adler32_neon", "chunkset_neon", "compare256_neon", "slide_hash_neon", ], ); cfg.mflag( if is_aarch64 { "-march=armv8-a+crc+simd" } else { "-mfpu=neon" }, None, ); } "s390x" => { for def in &[ "S390_FEATURES", "S390_DFLTCC_DEFLATE", "S390_DFLTCC_INFLATE", "S390_CRC32_VX", ] { cfg.define(def, None); } cfg.flag("-DDFLTCC_LEVEL_MASK=0x7e"); cfg.append( Some("arch/s390"), &[ "crc32-vx", "dfltcc_common", "dfltcc_deflate", "dfltcc_inflate", "s390_features", ], ); } _ => { // NOTE: PowerPC and Riscv // zlib-ng can use intrinsics for both of these targets, however neither // of them are currently checked in CI, they will still work without // using the intrinsics, they will just be slower // PowerPC - // Riscv - } } let include = dst.join("include"); fs::create_dir_all(&include).unwrap(); let (zconf_h, zlib_h, mangle) = if compat { ("zconf.h", "zlib.h", "zlib_name_mangling.h") } else { fs::copy("src/zlib-ng/zconf-ng.h.in", include.join("zconf-ng.h")).unwrap(); ("zconf-ng.h", "zlib-ng.h", "zlib_name_mangling-ng.h") }; if msvc { fs::copy(format!("src/zlib-ng/{zconf_h}.in"), include.join(zconf_h)).unwrap(); } else { // If we don't do this then _some_ 32-bit targets will have an incorrect // size for off_t if they don't _also_ define `HAVE_UNISTD_H`, so we // copy configure/cmake here let new_zconf = fs::read_to_string(format!("src/zlib-ng/{zconf_h}.in")) .expect("failed to read zconf.h.in") .replace( "#ifdef HAVE_UNISTD_H /* may be set to #if 1 by configure/cmake/etc */", &format!( "#if 1 /* was set to #if 1 by {}:{}:{} */", file!(), line!(), column!() ), ); fs::write(include.join(zconf_h), new_zconf).unwrap(); } fs::copy( "src/zlib-ng/zlib_name_mangling.h.empty", include.join(mangle), ) .unwrap(); let version = strip_symbol_prefix( Path::new(&format!("src/zlib-ng/{zlib_h}.in")), &include.join(zlib_h), true, ); cfg.include(&include).include("src/zlib-ng"); if let Err(err) = cfg.try_compile("z") { let version = if !cfg.is_msvc { match std::process::Command::new(cfg.get_compiler().path()) .arg("--version") .output() { Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(), Err(_err) => "unknown".into(), } } else { "msvc".into() }; eprintln!("{err}"); panic!( "failed to compile zlib-ng with cc: detected compiler version as \n---\n{}---", version ); } fs::create_dir_all(lib.join("pkgconfig")).unwrap(); fs::write( lib.join("pkgconfig/zlib.pc"), fs::read_to_string("src/zlib-ng/zlib.pc.in") .unwrap() .replace("@prefix@", dst.to_str().unwrap()) .replace("@includedir@", "${prefix}/include") .replace("@libdir@", "${prefix}/lib") .replace("@VERSION@", &version), ) .unwrap(); println!("cargo:root={}", dst.display()); println!("cargo:rustc-link-search=native={}", lib.display()); println!("cargo:include={}", include.display()); if !compat { println!("cargo:rustc-cfg=zng"); } } #[allow(dead_code)] fn main() { let target = env::var("TARGET").unwrap(); build_zlib_ng(&target, false); } libz-sys-1.1.20/zng/cmake.rs000064400000000000000000000033451046102023000137120ustar 00000000000000use std::env; pub fn build_zlib_ng(target: &str, compat: bool) { let mut cmake = cmake::Config::new("src/zlib-ng"); cmake .define("BUILD_SHARED_LIBS", "OFF") .define("ZLIB_COMPAT", if compat { "ON" } else { "OFF" }) .define("ZLIB_ENABLE_TESTS", "OFF") .define("WITH_GZFILEOP", "ON"); if target.contains("s390x") { // Enable hardware compression on s390x. cmake .define("WITH_DFLTCC_DEFLATE", "1") .define("WITH_DFLTCC_INFLATE", "1") .cflag("-DDFLTCC_LEVEL_MASK=0x7e"); } if target == "i686-pc-windows-msvc" { cmake.define("CMAKE_GENERATOR_PLATFORM", "Win32"); } let install_dir = cmake.build(); let includedir = install_dir.join("include"); let libdir = install_dir.join("lib"); let libdir64 = install_dir.join("lib64"); println!( "cargo:rustc-link-search=native={}", libdir.to_str().unwrap() ); println!( "cargo:rustc-link-search=native={}", libdir64.to_str().unwrap() ); let mut debug_suffix = ""; let libname = if target.contains("windows") && target.contains("msvc") { if env::var("OPT_LEVEL").unwrap() == "0" { debug_suffix = "d"; } "zlibstatic" } else { "z" }; println!( "cargo:rustc-link-lib=static={}{}{}", libname, if compat { "" } else { "-ng" }, debug_suffix, ); println!("cargo:root={}", install_dir.to_str().unwrap()); println!("cargo:include={}", includedir.to_str().unwrap()); if !compat { println!("cargo:rustc-cfg=zng"); } } #[allow(dead_code)] fn main() { let target = env::var("TARGET").unwrap(); build_zlib_ng(&target, false); }