skia2/bazel/external/libpng/BUILD.bazel
Kevin Lubick cc91f7d709 [bazel] Fix toolchains on M1 Mac
These changes are necessary to use the toolchain on both the
M1 Mac and Intel Macs.

This adds a way to detect the host platform and choose different
compile options in the toolchain.

We cannot statically link in libc++.a from the clang zip because
it appears to be x64 only.

Finally, this fixes copts not being passed to objective c libraries.

Known issue:
 - Intel Mac building has an error about the default CC toolchain.

Change-Id: Ie8e5e83dc41513563ac684e70a8a6947b36df445
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/552472
Reviewed-by: Jorge Betancourt <jmbetancourt@google.com>
2022-06-27 14:02:49 +00:00

85 lines
2.2 KiB
Python

# This file will be copied into //third_party/externals/libpng via the new_local_repository
# rule in WORKSPACE.bazel, so all files should be relative to that path.
# We define this here because the emscripten toolchain calls the cpu wasm, whereas the
# bazelbuild/platforms call it wasm32. https://github.com/emscripten-core/emsdk/issues/919
config_setting(
name = "cpu_wasm",
values = {
"cpu": "wasm",
},
)
LIBPNG_SRCS = [
"png.c",
"pngconf.h",
"pngdebug.h",
"pngerror.c",
"pngget.c",
"pnginfo.h",
"pngmem.c",
"pngpread.c",
"pngpriv.h",
"pngread.c",
"pngrio.c",
"pngrtran.c",
"pngrutil.c",
"pngset.c",
"pngstruct.h",
"pngtrans.c",
"pngwio.c",
"pngwrite.c",
"pngwtran.c",
"pngwutil.c",
"pnglibconf.h",
] + select({
"@platforms//cpu:x86_64": [
"intel/filter_sse2_intrinsics.c",
"intel/intel_init.c",
],
"@platforms//cpu:arm64": [
"arm/arm_init.c",
"arm/filter_neon_intrinsics.c",
"arm/palette_neon_intrinsics.c",
],
# No SIMD support in wasm for now
":cpu_wasm": [],
# The default is to avoid using SIMD
"//conditions:default": [],
})
PNG_DEFINES = ["PNG_SET_OPTION_SUPPORTED"] + select({
"@platforms//cpu:x86_64": ["PNG_INTEL_SSE"],
"//conditions:default": [],
})
cc_library(
name = "libpng",
srcs = LIBPNG_SRCS,
hdrs = [
"png.h",
],
copts = [
"-Wno-unused-but-set-variable",
"-Wno-macro-redefined",
],
includes = [
# This allows #include <png.h> to work
".",
],
local_defines = PNG_DEFINES,
# This is included by pnglibconf.h, but because it is not a .h
# file, we must tell Bazel to explicitly bring it in as an "includable".
textual_hdrs = ["scripts/pnglibconf.h.prebuilt"],
visibility = ["//visibility:public"],
deps = ["@zlib_skia//:zlib"],
)
# Creates a file called pnglibconf.h that includes the default png settings with one
# modification, undefining PNG_READ_OPT_PLTE_SUPPORTED.
genrule(
name = "create_skia_pnglibconf.h",
outs = ["pnglibconf.h"],
cmd = "echo '#include \"scripts/pnglibconf.h.prebuilt\"\n#undef PNG_READ_OPT_PLTE_SUPPORTED' > $@",
)