2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-30 16:42:07 +00:00
rules_foreign_cc/examples/configure_gnuplot/BUILD
irengrig e36f3cee8c
Fix using Bazel-built libraries by cmake_external and configure_make (#249)
Fix #232 - enable usage of Bazel-built libraries as dependencies of cmake_external and configure_make.

- fix logic of reading library data described by C/C++ Bazel interface (as CcInfo.linking_context appeared)
- symlink transitive include directories under $EXT_BUILD_DEPS
- gather all possible transitive include directories to pass to CMake, pass transitive include directories to CMAKE_PREFIX_PATH so that the transitive include directories were scanned by CMake
- fix logic of passing transitive libraries into CPPFLAGS (configure_make)
- add test with the chain: Bazel lib -> CMake lib -> Bazel cc_test
- add synthetic configure-make test with the chain: Bazel lib -> configure_make lib -> Bazel cc_test
- also notice, that passed include directories from Bazel C/C++ Sandwich interface are not always existing; for now, make symlinking code resistant to that

see https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Preset-Output-Variables.html
2019-05-09 10:35:00 +02:00

111 lines
2.3 KiB
Python

load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make")
load("@bazel_tools//tools/build_rules:test_rules.bzl", "file_test")
configure_make(
name = "libz",
lib_source = "@zlib//:all",
)
configure_make(
name = "libpng",
configure_options = [
"--with-zlib=\"$$EXT_BUILD_DEPS$$/libz\"",
],
lib_source = "@libpng//:all",
out_include_dir = "include/libpng16",
static_libraries = ["libpng16.a"],
deps = [":libz"],
)
configure_make(
name = "freetype",
configure_options = [
"--with-png=\"$$EXT_BUILD_DEPS$$/libpng\"",
"--with-zlib=\"$$EXT_BUILD_DEPS$$/libz\"",
],
lib_source = "@freetype//:all",
out_include_dir = "include/freetype2",
static_libraries = ["libfreetype.a"],
deps = [
":libpng",
":libz",
],
)
libgd_name = select({
"@bazel_tools//src/conditions:windows": ["libgd.lib"],
"//conditions:default": ["libgd.a"],
})
configure_make(
name = "libgd",
binaries = [
"webpng",
"gdtopng",
],
configure_options = [
"--disable-shared",
"--with-png=\"$$EXT_BUILD_DEPS$$/libpng\"",
"--with-freetype=\"$$EXT_BUILD_DEPS$$/freetype\"",
"--with-zlib=\"$$EXT_BUILD_DEPS$$/libz\"",
],
lib_source = "@libgd//:all",
static_libraries = libgd_name,
deps = [
":freetype",
":libpng",
":libz",
],
)
filegroup(
name = "gdtopng_fg",
srcs = [":libgd"],
output_group = "gdtopng",
)
genrule(
name = "invoke_gdtopng",
srcs = [],
outs = ["out.txt"],
cmd = "./$(location gdtopng_fg) > $(location out.txt) 2>&1 || true",
tools = [":gdtopng_fg"],
)
file_test(
name = "test_gdtopng",
content = "Usage: gdtopng filename.gd filename.png\n",
file = ":invoke_gdtopng",
)
cc_test(
name = "test_zlib",
srcs = ["zlib-example.cpp"],
deps = [":libz"],
)
cc_test(
name = "test_libpng",
srcs = ["libpng_usage_example.cpp"],
args = ["$(location bazel-icon-transparent.png) out.png"],
data = ["bazel-icon-transparent.png"],
deps = [
":libpng",
],
)
cc_test(
name = "test_libgd",
srcs = ["arc.c"],
deps = [":libgd"],
)
test_suite(
name = "configure_libgd_tests",
tests = [
":test_libgd",
":test_libpng",
":test_zlib",
],
)