facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.58k stars 221 forks source link

how do i setup gtest for c++ builds? #293

Open cartazio opened 1 year ago

cartazio commented 1 year ago

Hello, i'm having difficulty setting up the googletest dep for cxx_test commands, is there an example that works out there? The core problem seems to be that the old buck1 example for setting up googletest as a vendored library, requires the subdir_glob() command, which isn't implemented. I do see that gtest is definitely referenced by the buck2 cxx_test command

cartazio commented 1 year ago

this is what i've hacked together that seems to work, but its from looking at gtests build.bzl rather than buck examples


cxx_library(
  name = 'gtest',
srcs=glob(
        include = [
            "googletest/src/*.cc",
            # "googletest/src/*.h",
            # "googletest/include/gtest/**/*.h",
            "googlemock/src/*.cc",
            # "googlemock/include/gmock/**/*.h",
        ],
        exclude = [
            "googletest/src/gtest-all.cc",
            "googletest/src/gtest_main.cc",
            "googlemock/src/gmock-all.cc",
            "googlemock/src/gmock_main.cc",
        ],
  ),
  header_namespace = '',
  exported_headers = glob([
    ('googletest/googletest/include/gtest/*.h'),
    ('googletest/googlemock/include/gmock/*.h'),
  ]),
  include_directories= [   ('googletest/include/'),
    ('googlemock/include/'),
    'googletest/']
  ,
  headers = glob([
    ('googletest/src/*.cc'),
    ('googletest/src/*.h'),
    ('googlemock/src/*.cc'),
    ('googlemock/src/*.h'),
    ('googletest/include/gtest/*.h'),
    ('googlemock/include/gmock/*.h'),
    ('googlemock/include/gmock/internal/*.h'),
    ('googletest/include/gtest/internal/*.h')
  ]),
  # platform_linker_flags = [
  #   ('android', []),
  #   ('', ['-lpthread']),
  # ],
     visibility = ["PUBLIC"],

  # visibility = [
  #   '//test/...',
  # ],
)