blob: 8b2221a0dce78178dbcd867a24c03a0c2762c77e [file] [log] [blame]
# Copyright 2019 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("$zx_build/public/gn/migrated_targets.gni")
import("$zx_build_config/levels.gni")
# Note this leads to "$root_out_dir/obj/ABS_PATH/..." files in the build.
zstd = "$zx/third_party/zstd"
config("zstd-config") {
visibility = [ ":*" ]
include_dirs = [
"$zstd/contrib/seekable_format",
"$zstd/lib",
"$zstd/lib/common",
"$zstd/lib/compress",
"$zstd/lib/dictBuilder",
]
configs = [ "$zx_build_config:visibility_hidden" ]
defines = [
"XXH_NAMESPACE=ZSTD_",
"ZDICTLIB_VISIBILITY=",
"ZSTDERRORLIB_VISIBILITY=",
"ZSTDLIB_VISIBILITY=",
]
if (is_host) {
defines += [ "ZSTD_MULTITHREAD" ]
}
if (is_gcc && toolchain.environment == "kernel.phys32") {
# Work around bad assumption that uint32_t == unsigned int.
cflags = [ "-Wno-incompatible-pointer-types" ]
}
configs += [ "$zx_build_config:Wno-conversion" ]
# TODO(41757): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
configs += [ "$zx_build_config:temporarily_disable_ubsan_do_not_use" ]
}
zstd_common_sources = [
"$zstd/lib/common/debug.c",
"$zstd/lib/common/entropy_common.c",
"$zstd/lib/common/error_private.c",
"$zstd/lib/common/fse_decompress.c",
"$zstd/lib/common/pool.c",
"$zstd/lib/common/threading.c",
"$zstd/lib/common/xxhash.c",
]
zstd_compress_sources = [
"$zstd/lib/compress/fse_compress.c",
"$zstd/lib/compress/hist.c",
"$zstd/lib/compress/huf_compress.c",
"$zstd/lib/compress/zstd_compress.c",
"$zstd/lib/compress/zstd_compress_literals.c",
"$zstd/lib/compress/zstd_compress_sequences.c",
"$zstd/lib/compress/zstd_double_fast.c",
"$zstd/lib/compress/zstd_fast.c",
"$zstd/lib/compress/zstd_lazy.c",
"$zstd/lib/compress/zstd_ldm.c",
"$zstd/lib/compress/zstd_opt.c",
"$zstd/lib/compress/zstdmt_compress.c",
"$zstd/lib/dictBuilder/cover.c",
"$zstd/lib/dictBuilder/divsufsort.c",
"$zstd/lib/dictBuilder/fastcover.c",
"$zstd/lib/dictBuilder/zdict.c",
]
zstd_decompress_sources = [
"$zstd/lib/decompress/huf_decompress.c",
"$zstd/lib/decompress/zstd_ddict.c",
"$zstd/lib/decompress/zstd_decompress.c",
"$zstd/lib/decompress/zstd_decompress_block.c",
]
# The Zircon build, and zircon toolchains in the Fuchsia build
# add warn-implicit-fallthrough as a default config, which needs to
# be removed from several targets below. This variable helps.
warn_implicit_fallthrough_configs = []
if (zx == "/" || zircon_toolchain != false) {
warn_implicit_fallthrough_configs =
[ "$zx_build_config:warn-implicit-fallthrough" ]
}
zx_library("zstd") {
host = true
static = true
kernel = true
# Exported as a static library as the config above cannot be conveyed via the
# exporting mechanism but is absolutely necessary in order to properly compile
# this library.
sdk = "static"
sdk_headers = [ "zstd/zstd.h" ]
sdk_migrated = true
sources = zstd_common_sources + zstd_compress_sources +
zstd_decompress_sources + [ "$zstd/lib/common/zstd_common.c" ]
configs += [ ":zstd-config" ]
# This code doesn't use the annotation attribute.
configs -= warn_implicit_fallthrough_configs
if (zx == "/") {
# host tools (specifically blobfs) used during build use zstd to compress blobs. zstd is
# slow when compiled with optimize=none or optimize=debug (-O0 currently); enable default
# optimizations for just this library to speed up builds.
# See fxbug.dev/55297
configs -= [ "$zx_build_config:default_optimize" ]
configs += [ "$zx_build_config:optimize_speed" ]
}
# TODO(fxb/58162): delete the below and fix compiler warnings
configs += [ "$zx_build_config:Wno-conversion" ]
}
# 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.
zx_library("zstd-decompress-standalone") {
kernel = true
static = true
host = true
sdk = "static"
sdk_headers = [ "zstd/zstd.h" ]
sdk_migrated = true
sources = zstd_common_sources + zstd_decompress_sources +
[ "zstd_common_standalone.c" ]
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.
"ZSTDLIB_STANDALONE",
]
configs += [ ":zstd-config" ]
# This code doesn't use the annotation attribute.
configs -= warn_implicit_fallthrough_configs
if (is_kernel) {
deps = [ "$zx/kernel/lib/libc" ]
}
}
config("zstd-seekable-config") {
visibility = [ ":*" ]
# TODO(markdittmer): Upstream fixes to uninitialized variables in zstd.
if (is_gcc) {
cflags = [ "-Wno-maybe-uninitialized" ]
} else {
cflags = [ "-Wno-sometimes-uninitialized" ]
}
}
config("zstd-seekable-public-config") {
visibility = [ ":*" ]
# Seekable library expects
# #include "zstd.h"
# to load zstd's lib/zstd.h.
include_dirs = [ "$zstd/lib" ]
}
zx_library("zstdseek") {
host = true
static = true
kernel = true
sdk = "static"
sdk_headers = []
sdk_migrated = true
sources = [
"$zstd/contrib/seekable_format/zstdseek_compress.c",
"$zstd/contrib/seekable_format/zstdseek_decompress.c",
]
public_deps = [ ":zstd" ]
# Compilation units loading seekable must incorporate its config's include_dirs.
public_configs = [ ":zstd-seekable-public-config" ]
configs += [
":zstd-config",
":zstd-seekable-config",
]
# This code doesn't use the annotation attribute.
configs -= warn_implicit_fallthrough_configs
}
if (!is_kernel) {
if (zx != "/") {
import("//build/host.gni")
install_host_tools("host-tools") {
deps = [ ":zstdcli" ]
outputs = [ "zstd" ]
}
}
zx_host_tool("zstdcli") {
output_name = "zstd"
sources = [
"$zstd/programs/benchfn.c",
"$zstd/programs/benchzstd.c",
"$zstd/programs/datagen.c",
"$zstd/programs/dibio.c",
"$zstd/programs/fileio.c",
"$zstd/programs/timefn.c",
"$zstd/programs/util.c",
"$zstd/programs/zstdcli.c",
]
sdk_migrated = true
deps = [ ":zstd" ]
configs += [ ":zstd-config" ]
}
}