facebook / folly

An open-source C++ library developed and used at Facebook.
https://groups.google.com/forum/?fromgroups#!forum/facebook-folly
Apache License 2.0
28.41k stars 5.57k forks source link

Building with Buck2 #2247

Open rj-jesus opened 4 months ago

rj-jesus commented 4 months ago

As per the title, is it possible to build Folly with Buck2?

There are lots of BUCK files in the repository, and they seem up-to-date, so I would assume it's possible to do so. However, whenever I try I stumble upon errors such as:

$ buck2 targets //...
File changed: root//.git/index.lock
Error parsing root//folly/settings/test
Error evaluating build file: `root//folly/settings/test:BUCK`

Caused by:
    error: Variable `cpp_library` not found, did you mean `cxx_library`?
      --> folly/settings/test/BUCK:32:1
       |
    32 | cpp_library(
       | ^^^^^^^^^^^
       |

Failed to parse 1 package

I'm especially interested in this as a big portion of the benchmarks seem to be enabled only through Buck2 (please correct me if I'm wrong!).

Any help is greatly appreciated!

Orvid commented 4 months ago

While the BUCK files are present, they are not yet usable in open source, though I believe @namanahuja has been working on that.

Orvid commented 4 months ago

For the benchmarks, if there's one in particular you want to build via cmake, it should be possible to just add it to the existing CMakeLists.txt with a line similar to this: https://github.com/facebook/folly/blob/main/CMakeLists.txt#L660

The BUCK files are what we use to build Folly internally, so are the source of truth. That does mean that occasionally things don't get added to the CMakeLists.txt file when their added :(

Orvid commented 4 months ago

https://github.com/facebook/folly/pull/2241 should fix the specific issue you posted here, but the OSS buck build tests are still listed as skipped, so I don't know if there are other issues you'll run into.

rj-jesus commented 4 months ago

Hi @Orvid, thanks very much for your comments and the fix---it does work!

$ buck2 targets //... | grep benchmark
File changed: root//.git/index.lock
File changed: root//CLANG/include/cairo/cairo.h
File changed: root//CLANG/include/cairo/cairo-xlib.h
437 additional file change events
Build ID: af83b036-f888-402b-b809-5c33240b4dda
Jobs completed: 2. Time elapsed: 0.0s.
root//folly:benchmark
root//folly:benchmark_util
root//folly/compression/test:quotient_multiset_benchmark
root//folly/concurrency/test:cache_locality_benchmark
root//folly/debugging/exception_tracer/test:exception_tracer_benchmark_main
root//folly/experimental/io/test:io_benchmark
...

However, I only seem to be able to list benchmarks defined with cpp_binary such as those above. Those defined with cpp_benchmark don't seem to get listed (e.g. memset_benchmark and several others). Do you know why this might be?

Orvid commented 4 months ago

My blind guess (I've not looked into the details at all) would be that cpp_benchmark is probably not yet implemented for open source builds and is instead stubbed out to do nothing so work can continue on the rest of it.

Edit: Yep, looks like cpp_benchmark is currently stubbed out: https://github.com/facebook/folly/blob/main/shim/build_defs/cpp_benchmark.bzl#L8