Copying config headers for new_http_archive

62 views
Skip to first unread message

par...@gmail.com

unread,
Sep 20, 2017, 11:09:53 PM9/20/17
to bazel-discuss
Hi,
Ares (https://github.com/c-ares/c-ares) generates few files using cmake (ares_build.h.cmake or ares_config.h.cmake). Its hard to generate these using bazel, so one of the tricks used is to pregenerate them (For example in grpc: https://github.com/grpc/grpc/tree/master/third_party/cares these files are checkedin).

I am using cares with following in WORKSPACE:

new_http_archive(
name = "com_github_cares_cares",
url = "https://github.com/c-ares/c-ares/archive/cares-1_13_0.tar.gz",
strip_prefix = "c-ares-cares-1_13_0",
build_file = "build/com_github_cares_cares.BUILD",
)

but am having hard time building since I can't figure out a way to generate these (ares_build.h and ares_config.h). I tied to copy these from one of the folders in my workspace using genrule, but unable to do it because of sandboxing.

Is there a better way to generate these without hardcoding these file into genrule in my BUILD files?

Thanks,
Param

Marcel Hlopko

unread,
Sep 21, 2017, 4:44:47 AM9/21/17
to par...@gmail.com, bazel-discuss
I'm sorry I didn't get everything. So you want to use cares. Cares uses cmake, and you need to run cmake to get ares_build.h.cmake, which is required to build cares. And you don't want to run cmake in genrule? Can you use pregenerated header declared in cc_library in build/com_github_cares_cares.BUILD together with precompiled .a or .so library?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/bdbb96ad-5a31-4082-8c31-7aa5e5401cc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Paul Johnston

unread,
Sep 21, 2017, 5:03:05 PM9/21/17
to bazel-discuss
I would consider writing a repository rule that downloads the cares repo and symlinks (or copies) your custom ares_build.h, _config.h files into place.  Something like (not tested):

def _cares_repository_impl(repository_ctx):
    repository_ctx.download_and_extract(cares_url)
    repository_ctx.symlink(repository_ctx.path(ctx.attr.build_h_file), "ares_build.h")
    ...
    repository_ctx.file("BUILD.bazel", """
cc_library(
   name = "cares"
   srcs = [...]
   ...
)
"""

cares_repository = repository_rule(
    implementation = _cares_repository_impl,
    attrs = {
        "build_h_file": attr.label(allow_files = True), 
        "config_h_file": attr.label(allow_files = True), 
Reply all
Reply to author
Forward
0 new messages