Skip to content

Commit

Permalink
Switch to embedding libdeflate into EXRCore (#1387)
Browse files Browse the repository at this point in the history
Switches to embedding upstream (MIT license) libdeflate vs linking
against external library, functions should be private / hidden by
default.

Like Imath, enables one to use a system version or force using an
internally embedded version (OPENEXR_FORCE_INTERNAL_DEFLATE).
Further, the repository used can be controlled with
OPENEXR_DEFLATE_REPO and OPENEXR_DEFLATE_TAG cmake variables.

This centralizes all IETF RFC 1950 (zlib) compression into
the EXRCore library. This implies that the main C++ library
depends on EXRCore.

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd authored Apr 25, 2023
1 parent faf1bc1 commit ef4b710
Show file tree
Hide file tree
Showing 34 changed files with 700 additions and 433 deletions.
107 changes: 103 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ expand_template(
"@OPENEXR_NAMESPACE_CUSTOM@": "3.2.0",
"@OPENEXR_PACKAGE_NAME@": "OpenEXR 3.2.0",
"@OPENEXR_VERSION_EXTRA@": "",
"@OPENEXR_VERSION_MAJOR@": "3",
"@OPENEXR_VERSION_MINOR@": "2",
"@OPENEXR_VERSION_PATCH@": "0",
"@OpenEXR_VERSION_MAJOR@": "3",
"@OpenEXR_VERSION_MINOR@": "2",
"@OpenEXR_VERSION_PATCH@": "0",
"@OPENEXR_VERSION@": "3.2.0",
"#cmakedefine OPENEXR_ENABLE_API_VISIBILITY": "#define OPENEXR_ENABLE_API_VISIBILITY",
"#cmakedefine OPENEXR_HAVE_LARGE_STACK 1": "/* #undef OPENEXR_HAVE_LARGE_STACK */",
Expand Down Expand Up @@ -141,6 +141,105 @@ cc_library(
deps = [":Iex"],
)

cc_library(
name = "OpenEXRCore",
srcs = [
"src/lib/OpenEXRCore/backward_compatibility.h",
"src/lib/OpenEXRCore/internal_attr.h",
"src/lib/OpenEXRCore/internal_channel_list.h",
"src/lib/OpenEXRCore/internal_coding.h",
"src/lib/OpenEXRCore/internal_constants.h",
"src/lib/OpenEXRCore/internal_compress.h",
"src/lib/OpenEXRCore/internal_decompress.h",
"src/lib/OpenEXRCore/internal_file.h",
"src/lib/OpenEXRCore/internal_float_vector.h",
"src/lib/OpenEXRCore/internal_huf.h",
"src/lib/OpenEXRCore/internal_memory.h",
"src/lib/OpenEXRCore/internal_opaque.h",
"src/lib/OpenEXRCore/internal_posix_file_impl.h",
"src/lib/OpenEXRCore/internal_win32_file_impl.h",
"src/lib/OpenEXRCore/internal_preview.h",
"src/lib/OpenEXRCore/internal_string.h",
"src/lib/OpenEXRCore/internal_string_vector.h",
"src/lib/OpenEXRCore/internal_structs.h",
"src/lib/OpenEXRCore/internal_util.h",
"src/lib/OpenEXRCore/internal_xdr.h",
"src/lib/OpenEXRCore/internal_rle.c",
"src/lib/OpenEXRCore/internal_zip.c",
"src/lib/OpenEXRCore/internal_pxr24.c",
"src/lib/OpenEXRCore/internal_b44.c",
"src/lib/OpenEXRCore/internal_b44_table.c",
"src/lib/OpenEXRCore/internal_piz.c",
"src/lib/OpenEXRCore/internal_dwa.c",
"src/lib/OpenEXRCore/internal_huf.c",
"src/lib/OpenEXRCore/attributes.c",
"src/lib/OpenEXRCore/string.c",
"src/lib/OpenEXRCore/string_vector.c",
"src/lib/OpenEXRCore/float_vector.c",
"src/lib/OpenEXRCore/channel_list.c",
"src/lib/OpenEXRCore/opaque.c",
"src/lib/OpenEXRCore/preview.c",
"src/lib/OpenEXRCore/base.c",
"src/lib/OpenEXRCore/context.c",
"src/lib/OpenEXRCore/memory.c",
"src/lib/OpenEXRCore/internal_structs.c",
"src/lib/OpenEXRCore/part.c",
"src/lib/OpenEXRCore/part_attr.c",
"src/lib/OpenEXRCore/std_attr.c",
"src/lib/OpenEXRCore/parse_header.c",
"src/lib/OpenEXRCore/write_header.c",
"src/lib/OpenEXRCore/chunk.c",
"src/lib/OpenEXRCore/coding.c",
"src/lib/OpenEXRCore/compression.c",
"src/lib/OpenEXRCore/decoding.c",
"src/lib/OpenEXRCore/encoding.c",
"src/lib/OpenEXRCore/pack.c",
"src/lib/OpenEXRCore/unpack.c",
"src/lib/OpenEXRCore/validation.c",
"src/lib/OpenEXRCore/debug.c",
"src/lib/OpenEXR/OpenEXRConfig.h",
"src/lib/IlmThread/IlmThreadConfig.h",
],
hdrs = [
"src/lib/OpenEXRCore/openexr.h",
"src/lib/OpenEXRCore/openexr_attr.h",
"src/lib/OpenEXRCore/openexr_base.h",
"src/lib/OpenEXRCore/openexr_chunkio.h",
"src/lib/OpenEXRCore/openexr_coding.h",
"src/lib/OpenEXRCore/openexr_compression.h",
"src/lib/OpenEXRCore/openexr_conf.h",
"src/lib/OpenEXRCore/openexr_context.h",
"src/lib/OpenEXRCore/openexr_decode.h",
"src/lib/OpenEXRCore/openexr_debug.h",
"src/lib/OpenEXRCore/openexr_encode.h",
"src/lib/OpenEXRCore/openexr_errors.h",
"src/lib/OpenEXRCore/openexr_part.h",
"src/lib/OpenEXRCore/openexr_std_attr.h",
],
copts = select({
":windows": [],
"//conditions:default": [
"-Wno-error",
],
}),
features = select({
":windows": ["windows_export_all_symbols"],
"//conditions:default": [],
}),
includes = ["src/lib/OpenEXRCore", "src/lib/OpenEXR", "src/lib/IlmThread"],
linkopts =
select({
":windows": [],
"//conditions:default": [
"-pthread",
],
}),
visibility = ["//visibility:public"],
deps = [
"@Imath", "@libdeflate",
],
)

cc_library(
name = "OpenEXR",
srcs = [
Expand Down Expand Up @@ -378,8 +477,8 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":IlmThread",
":OpenEXRCore",
"@Imath",
"@net_zlib_zlib//:zlib",
],
)

Expand Down
6 changes: 3 additions & 3 deletions bazel/third_party/Imath.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ expand_template(
"@IMATH_NAMESPACE_CUSTOM@": "0",
"@IMATH_NAMESPACE@": "Imath",
"@IMATH_PACKAGE_NAME@": "Imath 3.1.7",
"@IMATH_VERSION_MAJOR@": "3",
"@IMATH_VERSION_MINOR@": "1",
"@IMATH_VERSION_PATCH@": "7",
"@Imath_VERSION_MAJOR@": "3",
"@Imath_VERSION_MINOR@": "1",
"@Imath_VERSION_PATCH@": "7",
"@IMATH_VERSION@": "3.1.7",
"#cmakedefine IMATH_HALF_USE_LOOKUP_TABLE": "#define IMATH_HALF_USE_LOOKUP_TABLE",
"#cmakedefine IMATH_ENABLE_API_VISIBILITY": "#define IMATH_ENABLE_API_VISIBILITY",
Expand Down
58 changes: 58 additions & 0 deletions bazel/third_party/libdeflate.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Contributors to the OpenEXR Project.

load("@rules_cc//cc:defs.bzl", "cc_library")

licenses(["notice"])

exports_files(
glob(["lib/**"]) + ["common_defs.h"],
visibility = ["//visibility:public"],
)

cc_library(
name = "libdeflate",
srcs = [
"lib/arm/cpu_features.c",
"lib/x86/cpu_features.c",
"lib/utils.c",
"lib/deflate_compress.c",
"lib/deflate_decompress.c",
"lib/adler32.c",
"lib/zlib_compress.c",
"lib/zlib_decompress.c",
"lib/crc32.c",
"lib/gzip_compress.c",
"lib/gzip_decompress.c",
"lib/adler32_vec_template.h",
"lib/bt_matchfinder.h",
"lib/cpu_features_common.h",
"lib/crc32_multipliers.h",
"lib/crc32_tables.h",
"lib/decompress_template.h",
"lib/deflate_compress.h",
"lib/deflate_constants.h",
"lib/gzip_constants.h",
"lib/hc_matchfinder.h",
"lib/ht_matchfinder.h",
"lib/lib_common.h",
"lib/matchfinder_common.h",
"lib/zlib_constants.h",
"lib/arm/adler32_impl.h",
"lib/arm/cpu_features.h",
"lib/arm/crc32_impl.h",
"lib/arm/crc32_pmull_helpers.h",
"lib/arm/crc32_pmull_wide.h",
"lib/arm/matchfinder_impl.h",
"lib/x86/adler32_impl.h",
"lib/x86/cpu_features.h",
"lib/x86/crc32_impl.h",
"lib/x86/crc32_pclmul_template.h",
"lib/x86/decompress_impl.h",
"lib/x86/matchfinder_impl.h",
"common_defs.h",
],
hdrs = ["libdeflate.h"],
includes = ["."],
visibility = ["//visibility:public"],
)
13 changes: 5 additions & 8 deletions bazel/third_party/openexr_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ def openexr_deps():

maybe(
http_archive,
name = "net_zlib_zlib",
build_file = "@com_openexr//:bazel/third_party/zlib.BUILD",
sha256 = "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30",
strip_prefix = "zlib-1.2.13",
urls = [
"https://mirror.bazel.build/zlib.net/zlib-1.2.13.tar.gz",
"https://zlib.net/zlib-1.2.13.tar.gz",
],
name = "libdeflate",
build_file = "@com_openexr//:bazel/third_party/libdeflate.BUILD",
sha256 = "225d982bcaf553221c76726358d2ea139bb34913180b20823c782cede060affd",
strip_prefix = "libdeflate-1.18",
urls = ["https://github.com/ebiggers/libdeflate/archive/refs/tags/v1.18.tar.gz"],
)

maybe(
Expand Down
98 changes: 0 additions & 98 deletions bazel/third_party/zlib.BUILD

This file was deleted.

3 changes: 0 additions & 3 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ if(OPENEXR_INSTALL_PKG_CONFIG)
endif()
set(exr_pthread_libs ${CMAKE_THREAD_LIBS_INIT})
endif()
if(NOT zlib_INTERNAL_DIR)
set(zlib_link "-lz")
endif()
string(REPLACE ".in" "" pcout ${pcinfile})
configure_file(${pcinfile} ${CMAKE_CURRENT_BINARY_DIR}/${pcout} @ONLY)
install(
Expand Down
3 changes: 3 additions & 0 deletions cmake/LibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function(OPENEXR_DEFINE_LIBRARY libname)
PRIVATE cxx_std_${OPENEXR_CXX_STANDARD}
INTERFACE cxx_std_11 )

# we are embedding libdeflate
target_include_directories(${objlib} PRIVATE ${EXR_DEFLATE_INCLUDE_DIR})

if(OPENEXR_CURLIB_PRIV_EXPORT AND BUILD_SHARED_LIBS)
target_compile_definitions(${objlib} PRIVATE ${OPENEXR_CURLIB_PRIV_EXPORT})
if(WIN32)
Expand Down
2 changes: 1 addition & 1 deletion cmake/OpenEXR.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Version: @OPENEXR_VERSION@
Libs: @exr_pthread_libs@ -L${libdir} -lOpenEXR${libsuffix} -lOpenEXRUtil${libsuffix} -lOpenEXRCore${libsuffix} -lIex${libsuffix} -lIlmThread${libsuffix}
Cflags: -I${includedir} -I${OpenEXR_includedir} @exr_pthread_cflags@
Requires: Imath
Libs.private: @zlib_link@

Loading

0 comments on commit ef4b710

Please sign in to comment.