skia2/third_party/BUILD.bazel
Kevin Lubick 4d41304def [infra] Add hermetic toolchain for C/C++ using Clang+Musl
This can successfully build a C library:
   bazel build --config=clang //third_party:libpng

This can build and run a statically-linked executable:
   bazel test --config=clang //:bazel_test

For more verbose compile and linking output, add the
`--features diagnostic`
flag to a Bazel command (see _make_diagnostic_flags() in
toolchain/clang_toolchain_config.bzl. Similarly, a
`--features print_search_dirs` can be used to show where
clang is looking for libraries etc to link against.
These features are made available for easier debugging.

Suggested review order:
 - Read https://docs.bazel.build/versions/4.2.1/tutorial/cc-toolchain-config.html
   if unfamiliar with setting up C++ toolchains in Bazel
 - .bazelrc and WORKSPACE.bazel that configure use and download
   of the toolchain (Clang 13, musl 1.2.2)
 - toolchain/build_toolchain.bzl which downloads and assembles
   the toolchain (w/o installing anything on the host machine)
 - toolchain/BUILD.bazel and toolchain/*trampoline.sh to see
   the setup of the toolchain rules.
 - toolchain/clang_toolchain_config.bzl to see the configuration
   of the toolchain. Pay special attention to the various
   command line flags that are set.
 - See that tools/bazel_test.cc has made a new home in
   experimental/bazel_test/bazel_test.cpp, with a companion
   BUILD.bazel. Note the addition of some function calls
   that test use of the C++ standard library.
   The number being used to test the PNG library is the latest
   and greatest that verifies we are compiling the one brought
   in via DEPS (and not a local one).
 - third_party/* to see how png (and its dependent zlib) have
   been built. Pay special attention to the musl_compat hack
   to fix static linking (any idea what the real cause is?)
- //BUILD.bazel to see definition of the bazel_test executable.

Change-Id: I7b0922d0d45cb9be8df2fd5fa5a1f48492654d5f
Bug: skia:12541
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/461178
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
2021-10-21 12:43:49 +00:00

88 lines
2.8 KiB
Python

load("@rules_cc//cc:defs.bzl", "cc_library")
package(default_visibility = ["//:__subpackages__"])
cc_library(
name = "libpng",
srcs = [
"externals/libpng/png.c",
"externals/libpng/pngerror.c",
"externals/libpng/pngget.c",
"externals/libpng/pngmem.c",
"externals/libpng/pngpread.c",
"externals/libpng/pngread.c",
"externals/libpng/pngrio.c",
"externals/libpng/pngrtran.c",
"externals/libpng/pngrutil.c",
"externals/libpng/pngset.c",
"externals/libpng/pngtrans.c",
"externals/libpng/pngwio.c",
"externals/libpng/pngwrite.c",
"externals/libpng/pngwtran.c",
"externals/libpng/pngwutil.c",
# TODO(kjlubick) arm/x86 support
],
hdrs = ["libpng/pnglibconf.h"] + glob([
"externals/libpng/*.h",
]),
copts = [
"-Ithird_party/libpng/",
"-Wno-unused-but-set-variable",
],
includes = [
# This adds -isystem "third_party/externals/libpng" to any dependent
# compilation steps. This allows #include <png.h> to work
"externals/libpng",
# png.h attempts to #include "pnglibconf.h" , which we store in //third_party/libpng/
# This rule adds -isystem "third_party/externals/libpng" to any dependent
# rule on this, which avoids having to add "-Ithird_party/libpng/" to copts for
# those dependent rules.
"libpng",
],
textual_hdrs = ["externals/libpng/scripts/pnglibconf.h.prebuilt"],
deps = [":zlib"],
)
cc_library(
name = "zlib",
srcs = [
"externals/zlib/adler32.c",
"externals/zlib/compress.c",
"externals/zlib/cpu_features.c",
"externals/zlib/crc32.c",
"externals/zlib/deflate.c",
"externals/zlib/gzclose.c",
"externals/zlib/gzlib.c",
"externals/zlib/gzread.c",
"externals/zlib/gzwrite.c",
"externals/zlib/infback.c",
"externals/zlib/inffast.c",
"externals/zlib/inflate.c",
"externals/zlib/inftrees.c",
"externals/zlib/trees.c",
"externals/zlib/uncompr.c",
"externals/zlib/zutil.c",
] + glob([
"externals/zlib/**/*.h",
]),
hdrs = glob([
"externals/zlib/*.h",
]),
copts = [
"-Wno-unused-function",
],
strip_include_prefix = "externals/zlib/",
)
# This library is used to fix linking errors when trying to statically link in some symbols
# The symbols defined here:
# https://github.com/llvm/llvm-project/blob/main/libcxx/include/__support/musl/xlocale.h
# are defined to be inlined, however they are missing during the final linking of a static
# executable. By re-defining them in our own .a file, this makes the linker happy.
cc_library(
name = "musl_compat",
srcs = [
"musl_compat/locale.c",
],
)