[bazel] Move zlib and libpng out of //third_party/BUILD.bazel

I had to copy some config_settings out of //bazel/common_config_settings
because these are now treated as separate entities and cannot
see that file.

For libpng, note that we use a genrule to create the
pnglibconf.h instead of pointing to one somewhere else.
This ended up being easier than other things I tried.

Another approach would be to not depend on the version
in third_party/externals, but to clone it via
new_git_repository [1] and apply a patch that creates
the configuration file.

[1] https://bazel.build/rules/lib/repo/git#new_git_repository

Bug: skia:12541
Change-Id: I9a284775dc0f2bdabb145518d5f0803c74fb99fa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/545368
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Kevin Lubick 2022-05-31 16:22:31 -04:00
parent b217400869
commit 97caefd055
7 changed files with 285 additions and 130 deletions

View File

@ -204,16 +204,16 @@ local_repository(
###############################################################################
# https://bazel.build/reference/be/workspace#new_local_repository
new_local_repository(
name = "vulkanmemoryallocator",
build_file = "bazel/external/vulkanmemoryallocator/BUILD.bazel",
path = "third_party/externals/vulkanmemoryallocator",
name = "dawn",
build_file = "bazel/external/dawn/BUILD.bazel",
path = "third_party/externals/dawn",
workspace_file_content = "",
)
new_local_repository(
name = "dawn",
build_file = "bazel/external/dawn/BUILD.bazel",
path = "third_party/externals/dawn",
name = "libpng",
build_file = "bazel/external/libpng/BUILD.bazel",
path = "third_party/externals/libpng",
workspace_file_content = "",
)
@ -230,3 +230,18 @@ new_local_repository(
path = "third_party/externals/vulkan-tools",
workspace_file_content = "",
)
new_local_repository(
name = "vulkanmemoryallocator",
build_file = "bazel/external/vulkanmemoryallocator/BUILD.bazel",
path = "third_party/externals/vulkanmemoryallocator",
workspace_file_content = "",
)
new_local_repository(
# Some other dependency downloads zlib but with their own rules
name = "zlib_skia",
build_file = "bazel/external/zlib/BUILD.bazel",
path = "third_party/externals/zlib",
workspace_file_content = "",
)

84
bazel/external/libpng/BUILD.bazel vendored Normal file
View File

@ -0,0 +1,84 @@
# 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:arm": [
"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' > $@",
)

175
bazel/external/zlib/BUILD.bazel vendored Normal file
View File

@ -0,0 +1,175 @@
# This file will be copied into //third_party/externals/zlib 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",
},
)
constraint_value(
name = "fuchsia",
constraint_setting = "@platforms//os:os",
)
config_setting(
name = "fuchsia_arm64",
constraint_values = [
"@platforms//cpu:arm64",
":fuchsia",
],
)
config_setting(
name = "linux_x64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)
config_setting(
name = "linux_arm64",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:linux",
],
)
config_setting(
name = "mac_x64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
)
config_setting(
name = "windows_x64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
],
)
ZLIB_SRCS = [
"adler32.c",
"compress.c",
"contrib/optimizations/insert_string.h",
"cpu_features.c",
"cpu_features.h",
"crc32.h",
"crc32.c",
"deflate.c",
"deflate.h",
"gzclose.c",
"gzguts.h",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inffast.h",
"inflate.h",
"inftrees.c",
"inftrees.h",
"trees.c",
"trees.h",
"uncompr.c",
"inffixed.h",
"zutil.c",
"zutil.h",
] + select({
"@platforms//cpu:x86_64": [
"adler32_simd.h",
"adler32_simd.c",
"contrib/optimizations/chunkcopy.h",
"contrib/optimizations/inffast_chunk.h",
"contrib/optimizations/inffast_chunk.c",
"contrib/optimizations/inflate.c",
"crc32_simd.h",
"crc32_simd.c",
"crc_folding.c",
"fill_window_sse.c",
],
"@platforms//cpu:arm": [
"adler32_simd.h",
"adler32_simd.c",
"contrib/optimizations/chunkcopy.h",
"contrib/optimizations/inffast_chunk.h",
"contrib/optimizations/inffast_chunk.c",
"contrib/optimizations/inflate.c",
"crc32_simd.h",
"crc32_simd.c",
],
# No SIMD support in wasm for now
":cpu_wasm": ["inflate.c"],
# The default is to avoid using SIMD
"//conditions:default": ["inflate.c"],
})
ZLIB_DEFINES = ["ZLIB_IMPLEMENTATION"] + select({
"@platforms//cpu:x86_64": [
"ADLER32_SIMD_SSSE3",
"CRC32_SIMD_SSE42_PCLMUL",
"INFLATE_CHUNK_READ_64LE",
"INFLATE_CHUNK_SIMD_SSE2",
"DEFLATE_FILL_WINDOW_SSE2",
],
"@platforms//cpu:arm": [
"ADLER32_SIMD_NEON",
"INFLATE_CHUNK_SIMD_NEON",
],
":cpu_wasm": ["CPU_NO_SIMD"],
"//conditions:default": ["CPU_NO_SIMD"],
}) + select({
":windows_x64": ["X86_WINDOWS"],
":linux_x64": ["X86_NOT_WINDOWS"],
":fuchsia_arm64": [
"X86_NOT_WINDOWS",
"ARMV8_OS_FUCHSIA",
],
# TODO(kjlubick) other arm flavors
"//conditions:default": ["X86_NOT_WINDOWS"],
})
ZLIB_COPTS = [
"-Wno-unused-function",
"-Wno-deprecated-non-prototype",
# no-deprecated-non-prototype was added in Clang 14+, used in emscripten for CanvasKit, but
# it is not in Clang 13, currently used for Skia.
"-Wno-unknown-warning-option",
# Make the headers in contrib available, without exposing them in hdrs.
"-isystem third_party/",
] + select({
":linux_x64": [
"-mssse3",
"-msse4.2",
"-mpclmul",
],
":mac_x64": [
"-mpclmul",
],
"@platforms//cpu:arm": ["-march=armv8-a+crc"],
# If empty list isn't set for wasm, select picks linux_x64
":cpu_wasm": [],
"//conditions:default": [],
})
cc_library(
name = "zlib",
srcs = ZLIB_SRCS,
hdrs = [
"chromeconf.h",
"zconf.h",
"zlib.h",
],
copts = ZLIB_COPTS,
local_defines = ZLIB_DEFINES,
# This allows users of zlib to just do #include "zlib.h"
strip_include_prefix = "",
visibility = ["//visibility:public"],
)

View File

@ -13,7 +13,7 @@ cc_binary(
],
deps = [
"//:skia_core",
"//third_party:libpng",
"@libpng",
],
)

View File

@ -165,7 +165,7 @@ cc_library(
{
"//bazel/common_config_settings:gif_decode_codec": ["//third_party:wuffs"],
":needs_jpeg": ["//third_party:libjpeg_turbo"],
"//bazel/common_config_settings:png_decode_codec": ["//third_party:libpng"],
"//bazel/common_config_settings:png_decode_codec": ["@libpng"],
"//bazel/common_config_settings:raw_decode_codec": [
"//third_party:dng_sdk",
"//third_party:piex",

View File

@ -36,7 +36,7 @@ cc_library(
deps = select_multi(
{
"//bazel/common_config_settings:jpeg_encode_codec": ["//third_party:libjpeg_turbo"],
"//bazel/common_config_settings:png_encode_codec": ["//third_party:libpng"],
"//bazel/common_config_settings:png_encode_codec": ["@libpng"],
"//bazel/common_config_settings:webp_encode_codec": ["//third_party:libwebp"],
},
default = [],

View File

@ -72,126 +72,7 @@ cc_library(
# file, we must tell Bazel to explicitly bring it in as an "includable".
textual_hdrs = ["externals/libpng/scripts/pnglibconf.h.prebuilt"],
visibility = ["//:__subpackages__"],
deps = [":zlib"],
)
ZLIB_SRCS = [
"externals/zlib/adler32.c",
"externals/zlib/compress.c",
"externals/zlib/contrib/optimizations/insert_string.h",
"externals/zlib/cpu_features.c",
"externals/zlib/cpu_features.h",
"externals/zlib/crc32.h",
"externals/zlib/crc32.c",
"externals/zlib/deflate.c",
"externals/zlib/deflate.h",
"externals/zlib/gzclose.c",
"externals/zlib/gzguts.h",
"externals/zlib/gzlib.c",
"externals/zlib/gzread.c",
"externals/zlib/gzwrite.c",
"externals/zlib/infback.c",
"externals/zlib/inffast.c",
"externals/zlib/inffast.h",
"externals/zlib/inflate.h",
"externals/zlib/inftrees.c",
"externals/zlib/inftrees.h",
"externals/zlib/trees.c",
"externals/zlib/trees.h",
"externals/zlib/uncompr.c",
"externals/zlib/inffixed.h",
"externals/zlib/zutil.c",
"externals/zlib/zutil.h",
] + select({
"@platforms//cpu:x86_64": [
"externals/zlib/adler32_simd.h",
"externals/zlib/adler32_simd.c",
"externals/zlib/contrib/optimizations/chunkcopy.h",
"externals/zlib/contrib/optimizations/inffast_chunk.h",
"externals/zlib/contrib/optimizations/inffast_chunk.c",
"externals/zlib/contrib/optimizations/inflate.c",
"externals/zlib/crc32_simd.h",
"externals/zlib/crc32_simd.c",
"externals/zlib/crc_folding.c",
"externals/zlib/fill_window_sse.c",
],
"@platforms//cpu:arm": [
"externals/zlib/adler32_simd.h",
"externals/zlib/adler32_simd.c",
"externals/zlib/contrib/optimizations/chunkcopy.h",
"externals/zlib/contrib/optimizations/inffast_chunk.h",
"externals/zlib/contrib/optimizations/inffast_chunk.c",
"externals/zlib/contrib/optimizations/inflate.c",
"externals/zlib/crc32_simd.h",
"externals/zlib/crc32_simd.c",
],
# No SIMD support in wasm for now
"//bazel/common_config_settings:cpu_wasm": ["externals/zlib/inflate.c"],
# The default is to avoid using SIMD
"//conditions:default": ["externals/zlib/inflate.c"],
})
ZLIB_DEFINES = ["ZLIB_IMPLEMENTATION"] + select({
"@platforms//cpu:x86_64": [
"ADLER32_SIMD_SSSE3",
"CRC32_SIMD_SSE42_PCLMUL",
"INFLATE_CHUNK_READ_64LE",
"INFLATE_CHUNK_SIMD_SSE2",
"DEFLATE_FILL_WINDOW_SSE2",
],
"@platforms//cpu:arm": [
"ADLER32_SIMD_NEON",
"INFLATE_CHUNK_SIMD_NEON",
],
"//bazel/common_config_settings:cpu_wasm": ["CPU_NO_SIMD"],
"//conditions:default": ["CPU_NO_SIMD"],
}) + select({
"//bazel/common_config_settings:windows_x64": ["X86_WINDOWS"],
"//bazel/common_config_settings:linux_x64": ["X86_NOT_WINDOWS"],
"//bazel/common_config_settings:fuchsia_arm64": [
"X86_NOT_WINDOWS",
"ARMV8_OS_FUCHSIA",
],
# TODO(kjlubick) other arm flavors
"//conditions:default": ["X86_NOT_WINDOWS"],
})
ZLIB_COPTS = [
"-Wno-unused-function",
"-Wno-deprecated-non-prototype",
# no-deprecated-non-prototype was added in Clang 14+, used in emscripten for CanvasKit, but
# it is not in Clang 13, currently used for Skia.
"-Wno-unknown-warning-option",
# Make the headers in contrib available, without exposing them in hdrs.
"-isystem third_party/externals/zlib/",
] + select({
"//bazel/common_config_settings:linux_x64": [
"-mssse3",
"-msse4.2",
"-mpclmul",
],
"//bazel/common_config_settings:mac_x64": [
"-mpclmul",
],
"@platforms//cpu:arm": ["-march=armv8-a+crc"],
# If empty list isn't set for wasm, select picks linux_x64
"//bazel/common_config_settings:cpu_wasm": [],
"//conditions:default": [],
})
cc_library(
name = "zlib",
srcs = ZLIB_SRCS,
hdrs = [
"externals/zlib/chromeconf.h",
"externals/zlib/zconf.h",
"externals/zlib/zlib.h",
],
copts = ZLIB_COPTS,
local_defines = ZLIB_DEFINES,
# This allows users of zlib to just do #include "zlib.h"
strip_include_prefix = "externals/zlib/",
visibility = ["//:__subpackages__"],
deps = ["@zlib_skia//:zlib"],
)
JPEGTURBO_SRCS = [
@ -768,7 +649,7 @@ cc_library(
visibility = ["//:__subpackages__"],
deps = [
":libjpeg_turbo",
":zlib",
"@zlib_skia//:zlib",
],
)