libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

BUILD (8398B)


      1 # Copyright (c) the JPEG XL Project Authors. All rights reserved.
      2 #
      3 # Use of this source code is governed by a BSD-style
      4 # license that can be found in the LICENSE file.
      5 
      6 load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
      7 load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
      8 
      9 # Load sources/headers/tests lists.
     10 load(
     11     "jxl_lists.bzl",
     12     "libjxl_base_sources",
     13     "libjxl_cms_sources",
     14     "libjxl_codec_apng_sources",
     15     "libjxl_codec_exr_sources",
     16     "libjxl_codec_gif_sources",
     17     "libjxl_codec_jpegli_sources",
     18     "libjxl_codec_jpg_sources",
     19     "libjxl_codec_jxl_sources",
     20     "libjxl_codec_npy_sources",
     21     "libjxl_codec_pgx_sources",
     22     "libjxl_codec_pnm_sources",
     23     "libjxl_dec_box_sources",
     24     "libjxl_dec_jpeg_sources",
     25     "libjxl_dec_sources",
     26     "libjxl_enc_sources",
     27     "libjxl_extras_for_tools_sources",
     28     "libjxl_extras_sources",
     29     #'libjxl_gbench_sources',
     30     "libjxl_jpegli_lib_version",
     31     "libjxl_jpegli_libjpeg_helper_files",
     32     "libjxl_jpegli_sources",
     33     "libjxl_jpegli_testlib_files",
     34     "libjxl_jpegli_tests",
     35     "libjxl_major_version",
     36     "libjxl_minor_version",
     37     "libjxl_patch_version",
     38     "libjxl_public_headers",
     39     "libjxl_testlib_files",
     40     "libjxl_tests",
     41     "libjxl_threads_public_headers",
     42     "libjxl_threads_sources",
     43 )
     44 load(
     45     "jxl_vars.bzl",
     46     "libjxl_deps_brotli",
     47     "libjxl_deps_exr",
     48     "libjxl_deps_gif",
     49     "libjxl_deps_gtest",
     50     "libjxl_deps_hwy",
     51     "libjxl_deps_hwy_nanobenchmark",
     52     "libjxl_deps_hwy_test_util",
     53     "libjxl_deps_jpeg",
     54     "libjxl_deps_png",
     55     "libjxl_deps_runfiles",
     56     "libjxl_deps_skcms",
     57     "libjxl_deps_testdata",
     58     "libjxl_root_package",
     59     "libjxl_test_shards",
     60     "libjxl_test_timeouts",
     61 )
     62 
     63 DEFAULT_VISIBILITY = ["//:__subpackages__"]
     64 
     65 DEFAULT_COMPATIBILITY = []
     66 
     67 INCLUDES_DIR = "include"
     68 
     69 package(
     70     default_visibility = ["//:__subpackages__"],
     71 )
     72 
     73 licenses(["notice"])
     74 
     75 exports_files(["LICENSE"])
     76 
     77 EXPORT_TEMPLATE = """
     78 #ifndef @_EXPORT_H
     79 #define @_EXPORT_H
     80 
     81 #define @_EXPORT
     82 #define @_NO_EXPORT
     83 
     84 #ifndef @_DEPRECATED
     85 #  define @_DEPRECATED __attribute__ ((__deprecated__))
     86 #endif
     87 
     88 #endif
     89 """
     90 
     91 JXL_EXPORT_H = INCLUDES_DIR + "/jxl/jxl_export.h"
     92 
     93 genrule(
     94     name = "create_jxl_export",
     95     outs = [JXL_EXPORT_H],
     96     cmd = "echo '" + EXPORT_TEMPLATE.replace("@", "JXL") + "' > $@",
     97     compatible_with = DEFAULT_COMPATIBILITY,
     98 )
     99 
    100 JXL_CMS_EXPORT_H = INCLUDES_DIR + "/jxl/jxl_cms_export.h"
    101 
    102 genrule(
    103     name = "create_jxl_cms_export",
    104     outs = [JXL_CMS_EXPORT_H],
    105     cmd = "echo '" + EXPORT_TEMPLATE.replace("@", "JXL_CMS") + "' > $@",
    106     compatible_with = DEFAULT_COMPATIBILITY,
    107 )
    108 
    109 JXL_THREADS_EXPORT_H = INCLUDES_DIR + "/jxl/jxl_threads_export.h"
    110 
    111 genrule(
    112     name = "create_jxl_threads_export",
    113     outs = [JXL_THREADS_EXPORT_H],
    114     cmd = "echo '" + EXPORT_TEMPLATE.replace("@", "JXL_THREADS") + "' > $@",
    115     compatible_with = DEFAULT_COMPATIBILITY,
    116 )
    117 
    118 JXL_VERSION_H = INCLUDES_DIR + "/jxl/version.h"
    119 
    120 expand_template(
    121     name = "expand_jxl_version",
    122     out = JXL_VERSION_H,
    123     compatible_with = DEFAULT_COMPATIBILITY,
    124     substitutions = {
    125         "@JPEGXL_MAJOR_VERSION@": str(libjxl_major_version),
    126         "@JPEGXL_MINOR_VERSION@": str(libjxl_minor_version),
    127         "@JPEGXL_PATCH_VERSION@": str(libjxl_patch_version),
    128     },
    129     template = "jxl/version.h.in",
    130 )
    131 
    132 cc_library(
    133     name = "jxl_version",
    134     hdrs = [JXL_VERSION_H],
    135     compatible_with = DEFAULT_COMPATIBILITY,
    136     strip_include_prefix = INCLUDES_DIR,
    137 )
    138 
    139 JPEGLI_JCONFIG_H = INCLUDES_DIR + "/jpegli/jconfig.h"
    140 
    141 JPEGLI_JMORECFG_H = INCLUDES_DIR + "/jpegli/jmorecfg.h"
    142 
    143 JPEGLI_JPEGLIB_H = INCLUDES_DIR + "/jpegli/jpeglib.h"
    144 
    145 copy_file(
    146     name = "expand_jconfig",
    147     src = "@libjpeg_turbo//:jconfig.h",
    148     out = JPEGLI_JCONFIG_H,
    149     compatible_with = DEFAULT_COMPATIBILITY,
    150 )
    151 
    152 copy_file(
    153     name = "copy_jmorecfg",
    154     src = "@libjpeg_turbo//:jmorecfg.h",
    155     out = JPEGLI_JMORECFG_H,
    156     compatible_with = DEFAULT_COMPATIBILITY,
    157 )
    158 
    159 copy_file(
    160     name = "copy_jpeglib",
    161     src = "@libjpeg_turbo//:jpeglib.h",
    162     out = JPEGLI_JPEGLIB_H,
    163     compatible_with = DEFAULT_COMPATIBILITY,
    164 )
    165 
    166 cc_library(
    167     name = "includes",
    168     hdrs = libjxl_public_headers + [
    169         JXL_EXPORT_H,
    170         JXL_CMS_EXPORT_H,
    171     ],
    172     compatible_with = DEFAULT_COMPATIBILITY,
    173     strip_include_prefix = INCLUDES_DIR,
    174     deps = [":jxl_version"],
    175 )
    176 
    177 cc_library(
    178     name = "libjpeg_includes",
    179     hdrs = [
    180         JPEGLI_JCONFIG_H,
    181         JPEGLI_JMORECFG_H,
    182         JPEGLI_JPEGLIB_H,
    183     ],
    184     compatible_with = DEFAULT_COMPATIBILITY,
    185     strip_include_prefix = INCLUDES_DIR + "/jpegli",
    186 )
    187 
    188 cc_library(
    189     name = "base",
    190     srcs = [path for path in libjxl_base_sources if path.endswith(".cc")],
    191     hdrs = [path for path in libjxl_base_sources if path.endswith(".h")],
    192     compatible_with = DEFAULT_COMPATIBILITY,
    193     deps = [
    194         ":includes",
    195     ] + libjxl_deps_hwy,
    196 )
    197 
    198 cc_library(
    199     name = "jpegxl",
    200     srcs = libjxl_dec_sources + libjxl_dec_box_sources + libjxl_dec_jpeg_sources + libjxl_enc_sources + libjxl_cms_sources,
    201     compatible_with = DEFAULT_COMPATIBILITY,
    202     defines = [
    203         "JPEGXL_ENABLE_SKCMS=1",
    204     ],
    205     deps = [
    206         ":base",
    207         ":includes",
    208     ] + libjxl_deps_brotli + libjxl_deps_hwy + libjxl_deps_skcms,
    209 )
    210 
    211 cc_library(
    212     name = "jpegxl_private",
    213     hdrs = [
    214         path
    215         for path in libjxl_dec_sources + libjxl_dec_box_sources + libjxl_dec_jpeg_sources + libjxl_enc_sources + libjxl_cms_sources
    216         if path.endswith(".h") and not path.endswith("-inl.h")
    217     ],
    218     compatible_with = DEFAULT_COMPATIBILITY,
    219     deps = [":jpegxl"],
    220 )
    221 
    222 cc_library(
    223     name = "jpegxl_threads",
    224     srcs = libjxl_threads_sources,
    225     hdrs = libjxl_threads_public_headers + [JXL_THREADS_EXPORT_H],
    226     compatible_with = DEFAULT_COMPATIBILITY,
    227     strip_include_prefix = INCLUDES_DIR,
    228     deps = [
    229         ":base",
    230         ":includes",
    231     ],
    232 )
    233 
    234 CODEC_FILES = libjxl_codec_apng_sources + libjxl_codec_exr_sources + libjxl_codec_gif_sources + libjxl_codec_jpegli_sources + libjxl_codec_jpg_sources + libjxl_codec_jxl_sources + libjxl_codec_npy_sources + libjxl_codec_pgx_sources + libjxl_codec_pnm_sources
    235 
    236 CODEC_SRCS = [path for path in CODEC_FILES if path.endswith(".cc")]
    237 
    238 CODEC_HDRS = [path for path in CODEC_FILES if path.endswith(".h")]
    239 
    240 cc_library(
    241     name = "jpegli",
    242     srcs = libjxl_jpegli_sources,
    243     hdrs = [
    244         "jpegli/common_internal.h",  # TODO(eustas): should not be here
    245     ],
    246     compatible_with = DEFAULT_COMPATIBILITY,
    247     deps = [
    248         ":jpegxl_private",
    249         ":libjpeg_includes",
    250     ] + libjxl_deps_hwy,
    251 )
    252 
    253 # TODO(eustas): build codecs separately?
    254 cc_library(
    255     name = "jpegxl_extras",
    256     srcs = libjxl_extras_sources + libjxl_extras_for_tools_sources + CODEC_SRCS,
    257     hdrs = CODEC_HDRS,
    258     compatible_with = DEFAULT_COMPATIBILITY,
    259     defines = [
    260         "JPEGXL_ENABLE_APNG=1",
    261         "JPEGXL_ENABLE_EXR=1",
    262         "JPEGXL_ENABLE_GIF=1",
    263         "JPEGXL_ENABLE_JPEG=1",
    264         "JPEGXL_ENABLE_JPEGLI=1",
    265     ],
    266     deps = [
    267         ":jpegli",
    268         ":jpegxl_private",
    269         ":jpegxl_threads",
    270         ":jxl_version",
    271     ] + libjxl_deps_exr + libjxl_deps_gif + libjxl_deps_jpeg + libjxl_deps_png,
    272 )
    273 
    274 TESTLIB_FILES = libjxl_testlib_files + libjxl_jpegli_testlib_files + libjxl_jpegli_libjpeg_helper_files
    275 
    276 cc_library(
    277     name = "test_utils",
    278     testonly = 1,
    279     srcs = [path for path in TESTLIB_FILES if not path.endswith(".h")],
    280     hdrs = [path for path in TESTLIB_FILES if path.endswith(".h")],
    281     compatible_with = DEFAULT_COMPATIBILITY,
    282     defines = [
    283         'JPEGXL_ROOT_PACKAGE=\'"' + libjxl_root_package + '"\'',
    284     ],
    285     deps = [
    286         ":jpegli",
    287         ":jpegxl_extras",
    288         ":jpegxl_private",
    289     ] + libjxl_deps_runfiles,
    290 )
    291 
    292 TESTS = [path.partition(".")[0] for path in libjxl_tests + libjxl_jpegli_tests]
    293 
    294 [
    295     cc_test(
    296         name = test,
    297         timeout = libjxl_test_timeouts.get(test, "moderate"),
    298         srcs = [
    299             test + ".cc",
    300             "jpegli/testing.h",
    301             "jxl/testing.h",
    302         ],
    303         data = ["//:testdata"],
    304         shard_count = libjxl_test_shards.get(test, 1),
    305         deps = [
    306             ":jpegxl_extras",
    307             ":jpegxl_private",
    308             ":jpegxl_threads",
    309             ":test_utils",
    310         ] + libjxl_deps_gtest + libjxl_deps_hwy_test_util + libjxl_deps_hwy_nanobenchmark,
    311     )
    312     for test in TESTS
    313 ]