1# This file will be copied into //third_party/externals/libpng via the new_local_repository 2# rule in WORKSPACE.bazel, so all files should be relative to that path. 3 4# We define this here because the emscripten toolchain calls the cpu wasm, whereas the 5# bazelbuild/platforms call it wasm32. https://github.com/emscripten-core/emsdk/issues/919 6config_setting( 7 name = "cpu_wasm", 8 values = { 9 "cpu": "wasm", 10 }, 11) 12 13LIBPNG_SRCS = [ 14 "png.c", 15 "pngconf.h", 16 "pngdebug.h", 17 "pngerror.c", 18 "pngget.c", 19 "pnginfo.h", 20 "pngmem.c", 21 "pngpread.c", 22 "pngpriv.h", 23 "pngread.c", 24 "pngrio.c", 25 "pngrtran.c", 26 "pngrutil.c", 27 "pngset.c", 28 "pngstruct.h", 29 "pngtrans.c", 30 "pngwio.c", 31 "pngwrite.c", 32 "pngwtran.c", 33 "pngwutil.c", 34 "pnglibconf.h", 35] + select({ 36 "@platforms//cpu:x86_64": [ 37 "intel/filter_sse2_intrinsics.c", 38 "intel/intel_init.c", 39 ], 40 "@platforms//cpu:arm64": [ 41 "arm/arm_init.c", 42 "arm/filter_neon_intrinsics.c", 43 "arm/palette_neon_intrinsics.c", 44 ], 45 # No SIMD support in wasm for now 46 ":cpu_wasm": [], 47 # The default is to avoid using SIMD 48 "//conditions:default": [], 49}) 50 51PNG_DEFINES = ["PNG_SET_OPTION_SUPPORTED"] + select({ 52 "@platforms//cpu:x86_64": ["PNG_INTEL_SSE"], 53 "//conditions:default": [], 54}) 55 56cc_library( 57 name = "libpng", 58 srcs = LIBPNG_SRCS, 59 hdrs = [ 60 "png.h", 61 "pngconf.h", 62 "pnglibconf.h", 63 ], 64 copts = [ 65 "-Wno-unused-but-set-variable", 66 "-Wno-macro-redefined", 67 ], 68 includes = [ 69 # This allows #include <png.h> to work 70 ".", 71 ], 72 local_defines = PNG_DEFINES, 73 # This is included by pnglibconf.h, but because it is not a .h 74 # file, we must tell Bazel to explicitly bring it in as an "includable". 75 textual_hdrs = ["scripts/pnglibconf.h.prebuilt"], 76 visibility = ["//visibility:public"], 77 deps = ["@zlib_skia//:zlib"], 78) 79 80# Creates a file called pnglibconf.h that includes the default png settings with one 81# modification, undefining PNG_READ_OPT_PLTE_SUPPORTED. 82genrule( 83 name = "create_skia_pnglibconf.h", 84 outs = ["pnglibconf.h"], 85 cmd = "echo '#include \"scripts/pnglibconf.h.prebuilt\"\n#undef PNG_READ_OPT_PLTE_SUPPORTED' > $@", 86 cmd_bat = "echo #include \"scripts/pnglibconf.h.prebuilt\" > $@ && echo #undef PNG_READ_OPT_PLTE_SUPPORTED >> $@", 87) 88