Building c++ with buck. How do you export prebuilt header files?

459 views
Skip to first unread message

mal...@interana.com

unread,
Sep 28, 2016, 6:15:17 PM9/28/16
to Buck
I am trying to test how basic cxx_library and cxx_binary would work for me.
I need help on question
Question: How do you specify a header module file?
or is there a way a directory is specified.

I have following structure
$MAIN
      csv2json
      build_tools/headers/folly/*.h

In folly I have this:
prebuilt_cxx_library(
  name = 'folly',
  exported_headers = glob(['*.h']),
  #base_module='folly',
  visibility = [ 'PUBLIC' ],
  header_only = True,
)

While building a cxx_binary 
 csv2json/BUCK
cxx_binary(
  name = 'csv2json',
  srcs = [
      'csv2json1.cpp',
    ],
  deps = [
      '//rel:version',
      '//build_tools/headers/folly:folly',
    ],
)

cat tmp.h
#define xyzzzz 10

I have to use #include <build_tools/headers/folly/tmp.h>
instead of just <folly/tmp.h>
Question: How do you specify a header module file?

#include <iostream>
#include <folly/tmp.h>

int main() {

  std::cout << "Hello World of BUCK";
  return 0;

}

Shawn Wilsher

unread,
Sep 28, 2016, 6:17:51 PM9/28/16
to buck-...@googlegroups.com
You probably want to look at `subdir_glob` instead of `glob`:
https://buckbuild.com/function/subdir_glob.html

Cheers,

Shawn

Mallik Namburi

unread,
Sep 28, 2016, 6:27:58 PM9/28/16
to Shawn Wilsher, buck-...@googlegroups.com
Thanks Shawn,
I do find it throwing "too many values to unpack” error. So not sure if it is right.

2016-09-28 15:19:46.738][warn ][command:91c87b70-6e5a-454b-a985-8278c738972d][tid:25][com.facebook.buck.json.ProjectBuildFileParser] Fatal error raised by BUCK file parser for file /home/mallik/interana/backend/build_tools/folly/BUCK (parse): File "/home/mallik/interana/backend/buck-out/tmp/buck_run.Owichr/buck_python_program6394826828004609854/buck.py", line 1283, in process_with_diagnostics
diagnostics=diagnostics)
File "/home/mallik/interana/backend/buck-out/tmp/buck_run.Owichr/buck_python_program6394826828004609854/buck.py", line 1194, in process
implicit_includes=self._implicit_includes)
File "/home/mallik/interana/backend/buck-out/tmp/buck_run.Owichr/buck_python_program6394826828004609854/buck.py", line 1134, in _process_build_file
implicit_includes=implicit_includes)
File "/home/mallik/interana/backend/buck-out/tmp/buck_run.Owichr/buck_python_program6394826828004609854/buck.py", line 1057, in _process
exec(code, module.__dict__)
File "/home/mallik/interana/backend/build_tools/folly/BUCK", line 3, in <module>
exported_headers = subdir_glob(['folly/*.h']),
File "/home/mallik/interana/backend/buck-out/tmp/buck_run.Owichr/buck_python_program6394826828004609854/buck.py", line 139, in invoke
return self.func(*args, **updated_kwargs)
File "/home/mallik/interana/backend/buck-out/tmp/buck_run.Owichr/buck_python_program6394826828004609854/buck.py", line 361, in subdir_glob
for dirpath, glob_pattern in glob_specs:
ValueError: too many values to unpack

build_tools/folly$ cat BUCK

prebuilt_cxx_library(
name = 'folly',
exported_headers = subdir_glob(['folly/*.h']),
visibility = [ 'PUBLIC' ],
header_only = True,
)

binary is:

cxx_binary(
name = 'csv2json',
srcs = [
'csv2json1.cpp',
],
deps = [
'//rel:version',
'//build_tools/folly:folly',
],
)

source csv2json1.cpp is:
#include <iostream>
#include <folly/mallik.h>

int main() {

std::cout << "Hello World of BUCK";
return 0;

}

> --
> You received this message because you are subscribed to a topic in the Google Groups "Buck" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/buck-build/EgpDXRss_8s/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to buck-build+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Shawn Wilsher

unread,
Sep 29, 2016, 1:14:52 PM9/29/16
to buck-...@googlegroups.com, Mallik Namburi
On 9/28/2016 3:27 PM, Mallik Namburi wrote:
> prebuilt_cxx_library(
> name = 'folly',
> exported_headers = subdir_glob(['folly/*.h']),
> visibility = [ 'PUBLIC' ],
> header_only = True,
> )
That's not the right syntax. `subdir_glob` takes an array of tuples
which will generate the header map for you. The first entry of the
tuple is the sub directory that you want to strip from the include path
relative to your build file. The second is the glob pattern inside that
directory.

Cheers,

Shawn

Mallik Namburi

unread,
Sep 29, 2016, 5:08:56 PM9/29/16
to buck-...@googlegroups.com
Thanks Shawn.
Reply all
Reply to author
Forward
0 new messages