| # Copyright 2021 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//build/host.gni") |
| import("//build/zircon/migrated_targets.gni") |
| |
| # *NOTE*: This check is used to ensure that the Rust zstd bindings we use in |
| # //third_party/rust_crates/forks/zstd-sys stays in sync with the pinned version of zstd. |
| # To update our pinned version of zstd: |
| # |
| # 1. Determine if there are any incompatible API or ABI changes in the new version that |
| # are incompatible with the Rust crate in //third_party/rust_crates/forks/zstd-sys. |
| # If so, update the crate accordingly. |
| # 2. Disable the check below, adding a TODO comment referencing a bug tracking the zstd |
| # update, and indicate that the check will be re-enabled once the crate is updated. |
| # 3. Update the pinned version of zstd in //integration/third_party/flower |
| # 4. Run third_party/rust_crates/forks/zstd-sys/bindgen.sh to update the Rust bindings |
| # and re-enable the check below. |
| verify_rust_zstd_sys_crate_binding_version = true |
| |
| if (verify_rust_zstd_sys_crate_binding_version) { |
| # zstd.h Header Version Information |
| # Format: `#define ZSTD_VERSION_MAJOR 1` |
| zstd_version_line_no = 106 |
| zstd_version_index = 2 |
| zstd_header_path = "src/lib/zstd.h" |
| |
| # zstd-sys Crate Binding Version Information |
| # Format: `pub const ZSTD_VERSION_MAJOR: u32 = 1;` |
| zstd_sys_version_line_no = 6 |
| zstd_sys_version_idx = 5 |
| zstd_sys_path = "../rust_crates/forks/zstd-sys/src/bindings_zstd_std.rs" |
| |
| # Read the zstd header and create a version string of the form (maj.min.rel). |
| lines = read_file(zstd_header_path, "list lines") |
| lib_version_maj = string_split(lines[zstd_version_line_no]) |
| assert(lib_version_maj[1] == "ZSTD_VERSION_MAJOR", |
| "location of version constant was moved, update zstd_version_line_no") |
| lib_version_min = string_split(lines[zstd_version_line_no + 1]) |
| lib_version_rel = string_split(lines[zstd_version_line_no + 2]) |
| lib_version = string_join(".", |
| [ |
| lib_version_maj[zstd_version_index], |
| lib_version_min[zstd_version_index], |
| lib_version_rel[zstd_version_index], |
| ]) |
| |
| # Do the same for our fork of the zstd-sys crate. |
| lines = [] |
| lines = read_file(zstd_sys_path, "list lines") |
| rust_version_maj = string_split(lines[zstd_sys_version_line_no]) |
| assert( |
| rust_version_maj[2] == "ZSTD_VERSION_MAJOR:", |
| "location of version constant was moved, update zstd_sys_version_line_no") |
| rust_version_min = string_split(lines[zstd_sys_version_line_no + 1]) |
| rust_version_rel = string_split(lines[zstd_sys_version_line_no + 2]) |
| crate_version = string_join( |
| ".", |
| [ |
| string_replace(rust_version_maj[zstd_sys_version_idx], ";", ""), |
| string_replace(rust_version_min[zstd_sys_version_idx], ";", ""), |
| string_replace(rust_version_rel[zstd_sys_version_idx], ";", ""), |
| ]) |
| |
| # Make sure the versions match, and if not, provide details on how to update them. |
| assert( |
| lib_version == crate_version, |
| string_join( |
| " ", |
| [ |
| "library version ($lib_version) does not match Rust bindings ($crate_version).", |
| "See the top of this build file for information on updating the Rust bindings.", |
| ])) |
| } |
| |
| zstd_common_sources = [ |
| "src/lib/common/bitstream.h", |
| "src/lib/common/compiler.h", |
| "src/lib/common/cpu.h", |
| "src/lib/common/debug.c", |
| "src/lib/common/debug.h", |
| "src/lib/common/entropy_common.c", |
| "src/lib/common/error_private.c", |
| "src/lib/common/error_private.h", |
| "src/lib/common/fse.h", |
| "src/lib/common/fse_decompress.c", |
| "src/lib/common/huf.h", |
| "src/lib/common/mem.h", |
| "src/lib/common/pool.c", |
| "src/lib/common/pool.h", |
| "src/lib/common/threading.c", |
| "src/lib/common/threading.h", |
| "src/lib/common/xxhash.c", |
| "src/lib/common/xxhash.h", |
| "src/lib/common/zstd_common.c", |
| "src/lib/common/zstd_deps.h", |
| "src/lib/common/zstd_errors.h", |
| "src/lib/common/zstd_internal.h", |
| "src/lib/zstd.h", |
| ] |
| |
| zstd_compress_sources = [ |
| "src/lib/compress/fse_compress.c", |
| "src/lib/compress/hist.c", |
| "src/lib/compress/hist.h", |
| "src/lib/compress/huf_compress.c", |
| "src/lib/compress/zstd_compress.c", |
| "src/lib/compress/zstd_compress_internal.h", |
| "src/lib/compress/zstd_compress_literals.c", |
| "src/lib/compress/zstd_compress_literals.h", |
| "src/lib/compress/zstd_compress_sequences.c", |
| "src/lib/compress/zstd_compress_sequences.h", |
| "src/lib/compress/zstd_compress_superblock.c", |
| "src/lib/compress/zstd_compress_superblock.h", |
| "src/lib/compress/zstd_cwksp.h", |
| "src/lib/compress/zstd_double_fast.c", |
| "src/lib/compress/zstd_double_fast.h", |
| "src/lib/compress/zstd_fast.c", |
| "src/lib/compress/zstd_fast.h", |
| "src/lib/compress/zstd_lazy.c", |
| "src/lib/compress/zstd_lazy.h", |
| "src/lib/compress/zstd_ldm.c", |
| "src/lib/compress/zstd_ldm.h", |
| "src/lib/compress/zstd_opt.c", |
| "src/lib/compress/zstd_opt.h", |
| "src/lib/compress/zstdmt_compress.c", |
| "src/lib/compress/zstdmt_compress.h", |
| "src/lib/dictBuilder/cover.c", |
| "src/lib/dictBuilder/cover.h", |
| "src/lib/dictBuilder/divsufsort.c", |
| "src/lib/dictBuilder/divsufsort.h", |
| "src/lib/dictBuilder/fastcover.c", |
| "src/lib/dictBuilder/zdict.c", |
| "src/lib/dictBuilder/zdict.h", |
| ] |
| |
| zstd_decompress_sources = [ |
| "src/lib/decompress/huf_decompress.c", |
| "src/lib/decompress/huf_decompress_amd64.S", |
| "src/lib/decompress/zstd_ddict.c", |
| "src/lib/decompress/zstd_ddict.h", |
| "src/lib/decompress/zstd_decompress.c", |
| "src/lib/decompress/zstd_decompress_block.c", |
| "src/lib/decompress/zstd_decompress_block.h", |
| "src/lib/decompress/zstd_decompress_internal.h", |
| ] |
| |
| static_library("zstd") { |
| public_configs = [ ":public.config" ] |
| |
| public = [ |
| "include/zstd.h", |
| "include/zstd_errors.h", |
| ] |
| |
| sources = |
| zstd_common_sources + zstd_compress_sources + zstd_decompress_sources |
| |
| configs += [ ":internal.config" ] |
| |
| if (!is_fuchsia) { |
| libs = [ "pthread" ] |
| } |
| |
| # zstd is slow when compiled with optimize=none or optimize=debug (-O0 |
| # currently); enable default optimizations for just this library on both host |
| # and target. |
| # |
| # On the host blobfs uses zstd to compress blobs during build, which we want |
| # to be fast (https://fxbug.dev/42132910). On the target blobfs uses zstd to |
| # compress blobs during package resolution which is often in the critical |
| # path of engineers running tests, which we also want to be fast |
| # (https://fxbug.dev/42144717). |
| configs -= [ "//build/config:default_optimize" ] |
| configs += [ "//build/config:optimize_speed" ] |
| } |
| |
| config("public.config") { |
| visibility = [ ":*" ] |
| |
| include_dirs = [ "include" ] |
| } |
| |
| config("internal.config") { |
| visibility = [ ":*" ] |
| |
| include_dirs = [ |
| "src/lib", |
| "src/lib/common", |
| "src/lib/compress", |
| "src/lib/dictBuilder", |
| ] |
| |
| defines = [ |
| "XXH_NAMESPACE=ZSTD_", |
| "ZDICTLIB_VISIBILITY=", |
| "ZSTDERRORLIB_VISIBILITY=", |
| "ZSTDLIB_HIDDEN=", |
| "ZSTDLIB_VISIBILITY=", |
| "ZSTDLIB_VISIBLE=", |
| ] |
| |
| if (is_fuchsia) { |
| defines += [ |
| "PLATFORM_POSIX_VERSION=200112L", |
| "ZSTD_SETPRIORITY_SUPPORT=0", |
| ] |
| } else if (!is_kernel) { |
| defines += [ "ZSTD_MULTITHREAD" ] |
| } |
| |
| if (is_kernel) { |
| # This avoids references to malloc and free. |
| defines += [ "XXH_NO_STDLIB" ] |
| } |
| |
| # Suppress warnings the zstd code doesn't comply with. |
| configs = [ |
| "//build/config:Wno-conversion", |
| "//build/config:Wno-unused-but-set-variable", |
| "//build/config:Wno-bitwise-instead-of-logical", |
| ] |
| |
| cflags = [ "-Wno-implicit-fallthrough" ] |
| if (is_gcc) { |
| cflags += [ "-Wno-incompatible-pointer-types" ] |
| } |
| } |
| |
| # The standalone varaint of this library supports only decompression and does |
| # not depend malloc or free so it is suitable for use in userboot and physboot. |
| static_library("zstd-decompress-standalone") { |
| public_configs = [ ":public.config" ] |
| |
| sources = zstd_common_sources + zstd_decompress_sources |
| |
| configs += [ ":internal.config" ] |
| |
| defines = [ |
| # The dynamic dispatch between the two implementations creates writable |
| # data, which is incompatible with being linked into userboot or physboot. |
| "HUF_FORCE_DECOMPRESS_X2", |
| |
| # Removes some dead code that was causing the library to attempt to link |
| # against malloc and free. |
| "ZSTD_DEPS_MALLOC", |
| "ZSTD_malloc(s)=((void)(s),NULL)", |
| "ZSTD_calloc(n,s)=((void)((n)*(s)),NULL)", |
| "ZSTD_free(p)=(void)(p)", |
| |
| # Avoids some weak symbol references that require GOT slots. |
| "ZSTD_NO_TRACE", |
| ] |
| |
| if (is_kernel) { |
| deps = [ "//zircon/kernel/lib/libc" ] |
| } |
| } |
| |
| # This provides a superset of the zstd API with additional features. |
| static_library("zstdseek") { |
| public_deps = [ ":zstd" ] |
| public_configs = [ ":zstdseek.config" ] |
| |
| public = [ "include/zstd/zstd_seekable.h" ] |
| sources = [ |
| "src/contrib/seekable_format/zstdseek_compress.c", |
| "src/contrib/seekable_format/zstdseek_decompress.c", |
| "src/contrib/seekable_format/zstdseek_seekable.h", |
| ] |
| |
| configs += [ ":zstdseek.internal.config" ] |
| } |
| |
| config("zstdseek.internal.config") { |
| visibility = [ ":*" ] |
| configs = [ ":internal.config" ] |
| |
| # TODO(markdittmer): Upstream fixes to uninitialized variables in zstd. |
| if (is_gcc) { |
| cflags = [ "-Wno-maybe-uninitialized" ] |
| } else { |
| cflags = [ "-Wno-sometimes-uninitialized" ] |
| } |
| } |
| |
| config("zstdseek.config") { |
| # The public <zstd/zstd_seekable.h> header does `#include "zstd.h"`. |
| include_dirs = [ "include/zstd" ] |
| } |
| |
| if (!is_kernel) { |
| if (current_toolchain == host_toolchain) { |
| install_host_tools("host-tools") { |
| deps = [ ":zstdcli" ] |
| outputs = [ "zstd" ] |
| } |
| } |
| |
| executable("zstdcli") { |
| output_name = "zstd" |
| sources = [ |
| "src/programs/benchfn.c", |
| "src/programs/benchfn.h", |
| "src/programs/benchzstd.c", |
| "src/programs/benchzstd.h", |
| "src/programs/datagen.c", |
| "src/programs/datagen.h", |
| "src/programs/dibio.c", |
| "src/programs/dibio.h", |
| "src/programs/fileio.c", |
| "src/programs/fileio.h", |
| "src/programs/fileio_asyncio.c", |
| "src/programs/fileio_asyncio.h", |
| "src/programs/lorem.c", |
| "src/programs/lorem.h", |
| "src/programs/platform.h", |
| "src/programs/timefn.c", |
| "src/programs/timefn.h", |
| "src/programs/util.c", |
| "src/programs/util.h", |
| "src/programs/zstdcli.c", |
| "src/programs/zstdcli_trace.c", |
| "src/programs/zstdcli_trace.h", |
| ] |
| |
| configs += [ |
| ":internal.config", |
| "//build/config:Wno-strict-prototypes", |
| ] |
| deps = [ ":zstd" ] |
| } |
| } |