2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-28 08:43:26 +00:00
Build rules for interfacing with "foreign" (non-Bazel) build systems (CMake, configure-make, GNU Make, boost, ninja, Meson) https://bazel-contrib.github.io/rules_foreign_cc/
Find a file
irengrig 067d4be22e
use tools paths and flags from the toolchain (#7)
* take tools paths and flags from the toolchain

* correct toolchain data extraction, correct cmake flags and environment

* framework script: export variables intended to be used in config script

config script can create child processes which could use this variables

* cmake: prepend relative [to the execroot] paths with "$EXT_BUILD_ROOT/"

unfortunately, CMake does not understand relative paths
(sometimes it runs tests for the passed compiler and for that
concatenates the passed relative path to some tmp directory created for test)

we replace only paths starting with external/ and <top-package-name>/,
so we are quite fine to not make a mistake with replacing some not related to paths text;
the targets for replacement take very different form (judging by examining
toolchain definitions), for instance "-Lexternal/something"

* test data for cross compilation for android and with --crosstool_top

data files taken from bazel examples and bazel test data;

NB one of the interesting things is that we need to specify tools dependency on android sdk and ndk, so that cmake_external shell script have access to these tools

* remove cross compilation example with CROSSTOOL for now

* add very simple CMake library (test data)

* rename target to indicate it is not a test, but example

* adjust android example:

rename the target to indicate it is not a test but example,
add android ndk sources as additional tool for cmake target,
(otherwise it is not available in sandbox)
use more simple cmake-built library

* corrections to the framework & cmake:

- correct search for the root directory of the filegroup (when it is not under external)
- it was a mistake to specify shared library linker, specify CMAKE_AR instead
- unfortunately, I have not discovered how to modify CMake behaviour to pass the custom static flags (rcsD) before "-qc <target>" to the ar linker; option from documentation does not work. To be investigated. For now, do not pass the static cxx linker options, taken from Bazel toolchain.
2018-08-06 15:23:18 +02:00
.bazelci Add code and examples (#1) 2018-04-26 13:52:06 -04:00
cc_configure_make Add code and examples (#1) 2018-04-26 13:52:06 -04:00
examples/cc_configure_make Add code and examples (#1) 2018-04-26 13:52:06 -04:00
framework_example use tools paths and flags from the toolchain (#7) 2018-08-06 15:23:18 +02:00
tools/build_defs use tools paths and flags from the toolchain (#7) 2018-08-06 15:23:18 +02:00
AUTHORS Add code and examples (#1) 2018-04-26 13:52:06 -04:00
CONTRIBUTING.md Add code and examples (#1) 2018-04-26 13:52:06 -04:00
LICENSE Add code and examples (#1) 2018-04-26 13:52:06 -04:00
README.md Add code and examples (#1) 2018-04-26 13:52:06 -04:00
WORKSPACE use tools paths and flags from the toolchain (#7) 2018-08-06 15:23:18 +02:00

rules_foreign_cc

Rules for building projects using foreign build systems inside Bazel projects.

  • Experimental - API will most definitely change.
  • This is not an officially supported Google product (meaning, support and/or new releases may be limited.)

./configure && make

NOTE: this requires building Bazel from head after 060b1624e4

Example:

  • In WORKSPACE, we use a new_http_archive to download tarballs with the libraries we use.
  • In BUILD, we instantiate a cc_configure_make_library macro which behaves similarly to a cc_library, which can then be used in a C++ rule (cc_binary in this case).

In WORKSPACE, put

new_http_archive(
    name = "libevent",
    build_file_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])""",
    strip_prefix = "libevent-2.1.8-stable",
    urls = ["https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz"],
)

and in BUILD, put

cc_configure_make(
    name = "libevent",
    src = "@libevent//:all",
    configure_flags = [
        "--enable-shared=no",
        "--disable-libevent-regress",
        "--disable-openssl",
    ],
    out_lib_path = "lib/libevent.a",
)

cc_binary(
    name = "libevent_echosrv1",
    srcs = ["libevent_echosrv1.c"],
    deps = [":libevent"],
)

then build as usual:

$ devbazel build //:libevent_echosrv1