bazel baby steps

A few first steps toward a Bazel build.

To try it out, I think just

    $ bazel test ...

I added third_party to .bazelignore to prevent Bazel from looking there.
It can handle external dependencies itself, so no need to poke into what
we sync from DEPS.  Some of those have Bazel configs and we don't want
to be building them yet.

I've started by with libpng using new_git_repository(), mostly because
it's small, with a mildly complex build, and needs dependencies of its
own, zlib.  Mysteriously zlib is built-in to Bazel, so that was easy.

Next up is probably a dependency that does support Bazel, using
git_repository().  That should make sure we can handle the full mix.

Change-Id: I5775a1b254d341b9a90630aa1cc433a24167f2fd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316636
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
This commit is contained in:
Mike Klein 2020-09-11 11:11:33 -05:00 committed by Skia Commit-Bot
parent d836f84ab8
commit c1cc1d85ab
7 changed files with 69 additions and 0 deletions

1
.bazelignore Normal file
View File

@ -0,0 +1 @@
third_party

2
.gitignore vendored
View File

@ -45,3 +45,5 @@ bin/clang-format.exe
node_modules
tools/lottiecap/filmstrip.png
bazel-*

8
BUILD.bazel Normal file
View File

@ -0,0 +1,8 @@
cc_test(
name = "bazel_test",
srcs = [
"tools/bazel_test.cc",
],
deps = ["@libpng//:libpng"],
size = "small",
)

10
WORKSPACE.bazel Normal file
View File

@ -0,0 +1,10 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
new_git_repository(
name = "libpng",
remote = "https://skia.googlesource.com/third_party/libpng",
#tag = "v1.6.37",
commit = "a40189cf881e9f0db80511c382292a5604c3c3d1",
shallow_since = "1555265432 -0400",
build_file = "//bazel:libpng.bazel",
)

2
bazel/BUILD.bazel Normal file
View File

@ -0,0 +1,2 @@
# This empty BUILD.bazel file allows WORKSPACE.bazel to use
# the various foo.bazel files for third-party dependencies.

38
bazel/libpng.bazel Normal file
View File

@ -0,0 +1,38 @@
genrule(
name = "prebuilt_pnglibconf",
srcs = ["scripts/pnglibconf.h.prebuilt"],
outs = ["pnglibconf.h"],
cmd = "cp $< $@",
)
cc_library(
name = "libpng",
hdrs = ["png.h"],
includes = ["."],
srcs = [
"png.c",
"pngerror.c",
"pngget.c",
"pngmem.c",
"pngpread.c",
"pngread.c",
"pngrio.c",
"pngrtran.c",
"pngrutil.c",
"pngset.c",
"pngtrans.c",
"pngwio.c",
"pngwrite.c",
"pngwtran.c",
"pngwutil.c",
] + [
":prebuilt_pnglibconf",
"pngconf.h",
"pngdebug.h",
"pnginfo.h",
"pngpriv.h",
"pngstruct.h",
], # TODO(mtklein): SSE/NEON srcs?
deps = ["@bazel_tools//third_party/zlib"],
visibility = ["//visibility:public"],
)

8
tools/bazel_test.cc Normal file
View File

@ -0,0 +1,8 @@
// Copyright 2020 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include <png.h>
int main(int argc, char** argv) {
return png_access_version_number() == 10637
? 0 : 1;
}