Help adding a dependency

95 views
Skip to first unread message

Andy John

unread,
Jul 7, 2021, 6:17:25 AM7/7/21
to bazel-discuss
Hi there,
  I am trying to add libcbor as a dependency.
This is a C++ project that uses cmake, It lives here:

I see I can include a BUILD_libcbor file, which will be overlaid on the downloaded
code. But there is a cmake step that creates a .h file, based on what platform
you are running on. After that, I think it's a straightforward c library.

Can I include additional files to overlay, and just include the .h file I would end up with?
Can Bazel run cmake? Should I just pre-compile the library and include the .so?
Should I try to get a Bazel BUILD file included into the project?

Thanks for any help,
Andy

Gregg Reynolds

unread,
Jul 7, 2021, 10:45:02 AM7/7/21
to Andy John, bazel-discuss

Gregg

--
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/eaffb512-e843-473e-ae4e-2b65f84e846en%40googlegroups.com.

Gregg Reynolds

unread,
Jul 7, 2021, 5:49:18 PM7/7/21
to Andy John, bazel-discuss


On Wed, Jul 7, 2021 at 4:00 PM Andy John <an...@google.com> wrote:
Thanks!
I have it running both cmake and make.

But, the cmake step builds the makefiles. Then I need the make step to run INSIDE the cmake's output.
It's running on its own copy of the code, so no makefiles are present.

Is there a way to have the cmake step export the entire tree as output, and have make use that as it's source?
I see there are lib-out, header-out etc... options....

Dunno off the top of my head, I'd have to see the code.  Is it online somewhere?v  In general, there's always a way, but some ways are more painful than others, heh.

Can you use `exports_files` and/or filegroups? 

Andy John

unread,
Jul 7, 2021, 6:24:15 PM7/7/21
to bazel-discuss
The library I am trying to include is "libcbor", it's here:

Here are the manual steps that I want to re-create in Bazel:

unzip v0.8.0.zip
cd libcbor-0.8.0
cmake -DCMAKE_BUILD_TYPE=Release -DCBOR_CUSTOM_ALLOC=ON
make

output I care about is:
  src/libcor.a
  src/libcor.h
  src/cbor/*.h

I know everything up to the cmake step is OK.
I *think* the cmake step is OK.
The make step is failing - no Makefiles.

Here's my make rule:

make(
    name = "cbor",
    targets = ["all"],  # Don't need this? all is default?
    lib_source = ":cbor_cmake", # This is the cbor rule, to see it's files?
    out_include_dir = "src",
    out_static_libs = ["src/libcbor.a"],
    deps = [":cbor_cmake"],  # Make sure cmake runs first.
    visibility = ["//visibility:public"],
)

Thanks,
Andy

Andy John

unread,
Jul 7, 2021, 6:24:21 PM7/7/21
to bazel-discuss
Thanks, 
  I got cmake and make working.
But I need the make command to run inside the modified source tree that cmake created (where it wrote the Makefiles).
Is there a way to do this?
Or is there a way to tell the cmake rule to kick off a make step after?

The cmake step is only generating 3 Makefiles - if I copy just those 3 files over to a fresh tree
it builds with Make. Can I just do this via Bazel?

Thanks again,
Andy

Andy John

unread,
Jul 7, 2021, 6:24:29 PM7/7/21
to Gregg Reynolds, bazel-discuss
Thanks!
I have it running both cmake and make.

But, the cmake step builds the makefiles. Then I need the make step to run INSIDE the cmake's output.
It's running on its own copy of the code, so no makefiles are present.

Is there a way to have the cmake step export the entire tree as output, and have make use that as it's source?
I see there are lib-out, header-out etc... options....

Thanks again,
Andy

--
Andrew John, Google Fonts

Alex Garcia

unread,
Jul 8, 2021, 2:31:50 AM7/8/21
to Gregg Reynolds, Andy John, bazel-discuss
That was added recently, look at the python build example on master, it exposes a full dir as the output.

Alexandre Garcia Mayans

Andy John

unread,
Jul 8, 2021, 5:13:48 AM7/8/21
to bazel-discuss
I tried, and the cmake rule does not allow exports_files.

On Wednesday, July 7, 2021 at 2:49:18 PM UTC-7 d...@mobileink.com wrote:

Andy John

unread,
Jul 8, 2021, 5:13:51 AM7/8/21
to Alex Garcia, Gregg Reynolds, bazel-discuss
Thanks! 
I sent a PR for a minor fix.
I think this will do exactly what I need.
Andy

Andy John

unread,
Jul 8, 2021, 5:13:55 AM7/8/21
to Alex Garcia, Gregg Reynolds, bazel-discuss
When you specify out_data_dirs using a glob(**), does it run the glob after running cmake, or before?
I need it to be after.
The next step is not seeing the generated files.
Andy

Andy John

unread,
Jul 8, 2021, 5:22:50 AM7/8/21
to Alex Garcia, Gregg Reynolds, bazel-discuss
Or maybe I'm using the output incorrectly?
My cmake rule is called "cbor_cmake".
In my make rule, I am using:
      lib_source = ":cbor_cmake",
Is that all I need to do?
Andy

Andy John

unread,
Jul 8, 2021, 7:42:00 PM7/8/21
to bazel-discuss
I've been told that the cmake rule actually does 3 steps, cmake, build and install.
So it should be running the make step for me.
I have tested this on the command line, and it does work.

Here's my cmake rule, can anyone help me figure out why it's not doing the build step?

filegroup(
    name = "srcs",
    srcs = glob(["**"]),
    visibility = ["//visibility:private"],
)

cmake(
    name = "cbor",
    cache_entries = {
        "CMAKE_MACOSX_RPATH": "True",
        "CMAKE_BUILD_TYPE": "Release",
        "CBOR_CUSTOM_ALLOC": "ON",
    },
    lib_source = ":srcs",
    out_lib_dir = "src",
    out_static_libs = ["libcbor.a"],
    visibility = ["//visibility:public"],


Gregg Reynolds

unread,
Jul 8, 2021, 8:19:28 PM7/8/21
to Andy John, bazel-discuss
On Thu, Jul 8, 2021 at 6:42 PM 'Andy John' via bazel-discuss <bazel-...@googlegroups.com> wrote:
I've been told that the cmake rule actually does 3 steps, cmake, build and install.
So it should be running the make step for me.
I have tested this on the command line, and it does work.

Here's my cmake rule, can anyone help me figure out why it's not doing the build step?

filegroup(
    name = "srcs",
    srcs = glob(["**"]),
    visibility = ["//visibility:private"],
)

cmake(
    name = "cbor",
    cache_entries = {
        "CMAKE_MACOSX_RPATH": "True",
        "CMAKE_BUILD_TYPE": "Release",
        "CBOR_CUSTOM_ALLOC": "ON",
    },
    lib_source = ":srcs",
    out_lib_dir = "src",
    out_static_libs = ["libcbor.a"],
    visibility = ["//visibility:public"],

Try it with just the defaults for out_lib_src and out_static_libs, and no cache_entries?  In the past I've sometimes found that setting such attribs messes things up. 
Reply all
Reply to author
Forward
0 new messages