Skip to content

Commit

Permalink
Optimize Bazel external dependencies
Browse files Browse the repository at this point in the history
This change does the following:

- Always use {,new_}http_archive rather than git_repository
- Make liberal use of strip_prefix
- Clarify licenses() in BUILD files
- On POSIX include headers like a normal C/C++ program

This change accomplishes the following:

- Reduce download size >100MB: The biggest culprit is grpc which has
  tens of thousands of commits in its GitHub repository.

- Reduce disk size >200MB: On disk, grpc takes up 250MB when cloned even
  though the tarball of the git repo is 3.2MB. By never using git
  externals, we save on network.

- Consume less cpu: Cloning git repositories is much slower than
  downloading and extracting a tarball.
Change: 133895791
  • Loading branch information
jart authored and tensorflower-gardener committed Sep 22, 2016
1 parent e16dd87 commit 65038b0
Show file tree
Hide file tree
Showing 25 changed files with 484 additions and 418 deletions.
14 changes: 6 additions & 8 deletions avro.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

prefix_dir = "avro-cpp-1.8.0"

cc_library(
name = "avrocpp",
srcs = glob(
[
prefix_dir + "/impl/**/*.cc",
prefix_dir + "/impl/**/*.hh",
"impl/**/*.cc",
"impl/**/*.hh",
],
exclude = [
prefix_dir + "/impl/avrogencpp.cc",
"impl/avrogencpp.cc",
],
),
hdrs = glob([prefix_dir + "/api/**/*.hh"]),
includes = [prefix_dir + "/api"],
hdrs = glob(["api/**/*.hh"]),
includes = ["api"],
deps = [
"@boost_archive//:boost",
"@boost_archive//:filesystem",
Expand All @@ -27,7 +25,7 @@ cc_library(

cc_binary(
name = "avrogencpp",
srcs = [prefix_dir + "/impl/avrogencpp.cc"],
srcs = ["impl/avrogencpp.cc"],
deps = [
":avrocpp",
"@boost_archive//:program_options",
Expand Down
26 changes: 10 additions & 16 deletions boost.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ package(default_visibility = ["@avro_archive//:__subpackages__"])

licenses(["notice"]) # Boost software license

prefix_dir = "boost_1_61_0"

cc_library(
name = "boost",
hdrs = glob([
prefix_dir + "/boost/**/*.hpp",
prefix_dir + "/boost/**/*.h",
prefix_dir + "/boost/**/*.ipp",
"boost/**/*.hpp",
"boost/**/*.h",
"boost/**/*.ipp",
]),
includes = [prefix_dir],
includes = ["."],
)

cc_library(
name = "filesystem",
srcs = glob([prefix_dir + "/libs/filesystem/src/*.cpp"]),
srcs = glob(["libs/filesystem/src/*.cpp"]),
deps = [
":boost",
":system",
Expand All @@ -33,7 +31,7 @@ cc_library(

cc_library(
name = "iostreams",
srcs = glob([prefix_dir + "/libs/iostreams/src/*.cpp"]),
srcs = glob(["libs/iostreams/src/*.cpp"]),
deps = [
":boost",
"@bzip2_archive//:bz2lib",
Expand All @@ -43,16 +41,12 @@ cc_library(

cc_library(
name = "program_options",
srcs = glob([prefix_dir + "/libs/program_options/src/*.cpp"]),
deps = [
":boost",
],
srcs = glob(["libs/program_options/src/*.cpp"]),
deps = [":boost"],
)

cc_library(
name = "system",
srcs = glob([prefix_dir + "/libs/system/src/*.cpp"]),
deps = [
":boost",
],
srcs = glob(["libs/system/src/*.cpp"]),
deps = [":boost"],
)
42 changes: 17 additions & 25 deletions bzip2.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,27 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # BSD derivative

prefix_dir = "bzip2-1.0.6"

BZ2LIB_SRCS = [
# these are in the same order as their corresponding .o files are in OBJS in
# Makefile (rather than lexicographic order) for easy comparison (that they
# are identical).
"blocksort.c",
"huffman.c",
"crctable.c",
"randtable.c",
"compress.c",
"decompress.c",
"bzlib.c",
]

cc_library(
name = "bz2lib",
srcs = [prefix_dir + "/" + source for source in BZ2LIB_SRCS] +
[prefix_dir + "/bzlib_private.h"],
hdrs = [prefix_dir + "/bzlib.h"],
includes = [prefix_dir],
srcs = [
# These are in the same order as their corresponding .o files are in
# OBJS in Makefile (rather than lexicographic order) for easy
# comparison (that they are identical.)
"blocksort.c",
"huffman.c",
"crctable.c",
"randtable.c",
"compress.c",
"decompress.c",
"bzlib.c",
"bzlib_private.h",
],
hdrs = ["bzlib.h"],
includes = ["."],
)

cc_binary(
name = "bzip2",
srcs = [
"bzip2.c",
],
deps = [
":bz2lib",
],
srcs = ["bzip2.c"],
deps = [":bz2lib"],
)
68 changes: 65 additions & 3 deletions eigen.BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,70 @@
package(default_visibility = ["//visibility:public"])
# Description:
# Eigen is a C++ template library for linear algebra: vectors,
# matrices, and related algorithms.

licenses([
# Note: Eigen is an MPL2 library that includes GPL v3 and LGPL v2.1+ code.
# We've taken special care to not reference any restricted code.
"reciprocal", # MPL2
"notice", # Portions BSD
])

# License-restricted (i.e. not reciprocal or notice) files inside Eigen/...
EIGEN_RESTRICTED_FILES = [
"Eigen/src/OrderingMethods/Amd.h",
"Eigen/src/SparseCholesky/**",
]

# Notable transitive dependencies of restricted files inside Eigen/...
EIGEN_RESTRICTED_DEPS = [
"Eigen/Eigen",
"Eigen/IterativeLinearSolvers",
"Eigen/MetisSupport",
"Eigen/Sparse",
"Eigen/SparseCholesky",
"Eigen/SparseLU",
]

# Note: unsupported/Eigen is unsupported and might go away at any time.
EIGEN_FILES = [
"Eigen/**",
"unsupported/Eigen/CXX11/**",
"unsupported/Eigen/FFT",
"unsupported/Eigen/KroneckerProduct",
"unsupported/Eigen/src/FFT/**",
"unsupported/Eigen/src/KroneckerProduct/**",
"unsupported/Eigen/MatrixFunctions",
"unsupported/Eigen/SpecialFunctions",
"unsupported/Eigen/src/SpecialFunctions/**",
]

# List of files picked up by glob but actually part of another target.
EIGEN_EXCLUDE_FILES = [
"Eigen/src/Core/arch/AVX/PacketMathGoogleTest.cc",
]

# Files known to be under MPL2 license.
EIGEN_MPL2_HEADER_FILES = glob(
EIGEN_FILES,
exclude = EIGEN_EXCLUDE_FILES +
EIGEN_RESTRICTED_FILES +
EIGEN_RESTRICTED_DEPS + [
# Guarantees any file missed by excludes above will not compile.
"Eigen/src/Core/util/NonMPL2.h",
"Eigen/**/CMakeLists.txt",
],
)

cc_library(
name = "eigen",
hdrs = glob(["**/*.h", "unsupported/Eigen/*", "unsupported/Eigen/CXX11/*", "Eigen/*"]),
includes = [ '.' ],
hdrs = EIGEN_MPL2_HEADER_FILES,
defines = [
# This define (mostly) guarantees we don't link any problematic
# code. We use it, but we do not rely on it, as evidenced above.
"EIGEN_MPL2_ONLY",
# TODO(jart): Use EIGEN_USE_NONBLOCKING_THREAD_POOL but first add an
# eigen_initialize.cc file and alwayslink=1.
],
includes = ["."],
visibility = ["//visibility:public"],
)
22 changes: 5 additions & 17 deletions farmhash.BUILD
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
package(default_visibility = ["//visibility:public"])

prefix_dir = "farmhash-34c13ddfab0e35422f4c3979f360635a8c050260"

genrule(
name = "configure",
srcs = glob(
["**/*"],
exclude = [prefix_dir + "/config.h"],
),
outs = [prefix_dir + "/config.h"],
cmd = "pushd external/farmhash_archive/%s; workdir=$$(mktemp -d -t tmp.XXXXXXXXXX); cp -a * $$workdir; pushd $$workdir; ./configure; popd; popd; cp $$workdir/config.h $(@D); rm -rf $$workdir;" % prefix_dir,
)
licenses(["notice"]) # MIT

cc_library(
name = "farmhash",
srcs = [prefix_dir + "/src/farmhash.cc"],
hdrs = [prefix_dir + "/src/farmhash.h"] + [":configure"],
includes = [prefix_dir],
visibility = ["//visibility:public"]
srcs = ["farmhash.cc"],
hdrs = ["farmhash.h"],
includes = ["."],
visibility = ["//visibility:public"],
)
89 changes: 34 additions & 55 deletions gif.BUILD
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
SOURCES = [
"dgif_lib.c",
"egif_lib.c",
"gif_font.c",
"gif_hash.c",
"gifalloc.c",
"openbsd-reallocarray.c",
"gif_err.c",
"quantize.c",
]
# Description:
# A library for decoding and encoding GIF images

HEADERS = [
"gif_hash.h",
"gif_lib.h",
"gif_lib_private.h",
]
licenses(["notice"]) # MIT

config_setting(
name = "windows",
values = {
"cpu": "x64_windows_msvc",
},
visibility = ["//visibility:public"],
cc_library(
name = "gif",
srcs = [
"dgif_lib.c",
"egif_lib.c",
"gif_err.c",
"gif_font.c",
"gif_hash.c",
"gif_hash.h",
"gif_lib_private.h",
"gifalloc.c",
"openbsd-reallocarray.c",
"quantize.c",
],
hdrs = ["gif_lib.h"],
includes = ["."],
visibility = ["//visibility:public"],
deps = select({
":windows": [":windows_polyfill"],
"//conditions:default": [],
}),
)

prefix_dir = "giflib-5.1.4/lib"
prefix_dir_windows = "windows/giflib-5.1.4/lib"

genrule(
name = "srcs_without_unistd",
srcs = [prefix_dir + "/" + source for source in SOURCES],
outs = [prefix_dir_windows + "/" + source for source in SOURCES],
cmd = "for f in $(SRCS); do " +
" sed 's/#include <unistd.h>//g' $$f > $(@D)/%s/$$(basename $$f);" % prefix_dir_windows +
"done",
cc_library(
name = "windows_polyfill",
hdrs = ["windows/unistd.h"],
includes = ["windows"],
)

genrule(
name = "hdrs_without_unistd",
srcs = [prefix_dir + "/" + hdrs for hdrs in HEADERS],
outs = [prefix_dir_windows + "/" + hdrs for hdrs in HEADERS],
cmd = "for f in $(SRCS); do " +
" sed 's/#include <unistd.h>//g' $$f > $(@D)/%s/$$(basename $$f);" % prefix_dir_windows +
"done",
name = "windows_unistd_h",
outs = ["windows/unistd.h"],
cmd = "touch $@",
)

cc_library(
name = "gif",
srcs = select({
"//conditions:default" : [prefix_dir + "/" + source for source in SOURCES],
":windows" : [":srcs_without_unistd"],
}),
hdrs = select({
"//conditions:default" : [prefix_dir + "/" + hdrs for hdrs in HEADERS],
":windows" : [":hdrs_without_unistd"],
}),
includes = select({
"//conditions:default" : [prefix_dir],
":windows" : [prefix_dir_windows],
}),
defines = [
"HAVE_CONFIG_H",
],
visibility = ["//visibility:public"],
config_setting(
name = "windows",
values = {"cpu": "x64_windows_msvc"},
)
26 changes: 16 additions & 10 deletions gmock.BUILD
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# Description:
# Google C++ Mocking Framework, a library for creating and using C++
# mock classes.

licenses(["notice"]) # 3-clause BSD

cc_library(
name = "gtest",
srcs = [
"gmock-1.7.0/gtest/src/gtest-all.cc",
"gmock-1.7.0/src/gmock-all.cc",
"gtest/src/gtest-all.cc",
"src/gmock-all.cc",
],
hdrs = glob([
"gmock-1.7.0/**/*.h",
"gmock-1.7.0/gtest/src/*.cc",
"gmock-1.7.0/src/*.cc",
"**/*.h",
"gtest/src/*.cc",
"src/*.cc",
]),
includes = [
"gmock-1.7.0",
"gmock-1.7.0/gtest",
"gmock-1.7.0/gtest/include",
"gmock-1.7.0/include",
".",
"gtest",
"gtest/include",
"include",
],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
)

cc_library(
name = "gtest_main",
srcs = ["gmock-1.7.0/src/gmock_main.cc"],
srcs = ["src/gmock_main.cc"],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
deps = [":gtest"],
Expand Down
Loading

0 comments on commit 65038b0

Please sign in to comment.