Skip to content

tests: allow packagers to provide their own gtest - #2064

Open
arntanguy wants to merge 1 commit into
react:mainfrom
arntanguy:find-gtest
Open

arntanguy wants to merge 1 commit into
react:mainfrom
arntanguy:find-gtest

Conversation

@arntanguy

Copy link
Copy Markdown

This PR allows packager (e.g Nix) to provide their own version of google-test. To not risk disturbing existing user's workflows, this is gated behing the new YOGA_DISABLE_FETCHCONTENT option, with default OFF.

@meta-cla

meta-cla Bot commented Nov 4, 2026

Copy link
Copy Markdown

Hi @arntanguy!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Nov 4, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Nov 4, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 4, 2026

@intergalacticspacehighway intergalacticspacehighway left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for upstreaming this! Two small requests:

  1. Could we name it YOGA_USE_SYSTEM_GTEST? googletest is the only thing we fetch, so a name that says what it does reads clearer than YOGA_DISABLE_FETCHCONTENT.
  2. Could the option() move to tests/CMakeLists.txt, next to where it's used? Our unit_tests script configures tests/ directly.

wdyt?

@intergalacticspacehighway
intergalacticspacehighway dismissed their stale review November 8, 2026 06:08

Withdrawn, see comment below.

@intergalacticspacehighway

Copy link
Copy Markdown
Collaborator

Actually, CMake already supports this without a new option: -DFETCHCONTENT_FULLY_DISCONNECTED=ON -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=<googletest source> builds the tests offline from a local googletest. I tried it and all tests pass. It also works with the current release tags. Would that work for the nixpkgs package (for example ${gtest.src})? If yes, I'd rather not add a flag. wdyt?

@arntanguy

Copy link
Copy Markdown
Author

Using -DFETCHCONTENT_FULLY_DISCONNECTED=ON works but isn't strictly equivalent:

  1. In the case of this PR using find_package(GTest) will use the version of gtest already compiled and present in nixpkgs, that is a pre-built version of gtest gets pulled in from a nixpkgs's binary cache.
  2. Using -DFETCHCONTENT_FULLY_DISCONNECTED=ON and -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest.src} also works, but:
  • Pulls in the source code of gtest from the release defined in ${gtest.src}
  • Uses cmake/fetchcontent to build it and make it available

In short, 1. is slightly more efficient than 2. in the context of nixpkgs (or conan and other build systems with binary caching). 1. is thus preferable, that being said gtest is a trivial dependency, so we can live with letting FetchContent build it (or trivially patch it in nixpkgs)

493490f has the requested naming updates.

The choice is yours.

@arntanguy

Copy link
Copy Markdown
Author

Btw, I also had to build with -DCMAKE_CXX_FLAGS=-Wno-error=array-bounds otherwise build fails with

yoga> In file included from /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/stl_tempbuf.h:61,
yoga>                  from /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/memory:68,
yoga>                  from /nix/store/8bqjd52zg4x20w20nmhpv04z8106lhmh-source/googletest/include/gtest/gtest.h:55,
yoga>                  from /build/source/tests/YGPersistenceTest.cpp:8:
yoga> In function 'constexpr _Tp* std::construct_at(_Tp*, _Args&& ...) [with _Tp = facebook::yoga::Node*; _Args = {facebook::yoga::Node*}]',
yoga>     inlined from 'static constexpr void std::allocator_traits<std::allocator<_Up> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = facebook::yoga::Node*; _Args = {facebook::yoga::Node*}; _Tp = facebook::yoga::Node*]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/alloc_traits.h:716:21,
yoga>     inlined from 'constexpr void std::vector<_Tp, _Alloc>::_M_insert_aux(iterator, _Arg&&) [with _Arg = facebook::yoga::Node*; _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/vector.tcc:434:31,
yoga>     inlined from 'constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::_M_insert_rval(const_iterator, value_type&&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/vector.tcc:381:17,
yoga>     inlined from 'constexpr std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/stl_vector.h:1519:30,
yoga>     inlined from 'virtual void YogaTest_mixed_shared_and_owned_children_Test::TestBody()' at /build/source/tests/YGPersistenceTest.cpp:278:18:
yoga> /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/stl_construct.h:110:16: error: array subscript -1 is outside array bounds of 'facebook::yoga::Node* [1152921504606846975]' [-Werror=array-bounds=]
yoga>   110 |         return ::new(__loc) _Tp(std::forward<_Args>(__args)...);
yoga>       |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
yoga> In file included from /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/x86_64-unknown-linux-gnu/bits/c++allocator.h:33,
yoga>                  from /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/allocator.h:46,
yoga>                  from /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/memory:67:
yoga> In member function 'constexpr _Tp* std::__new_allocator<_Tp>::allocate(size_type, const void*) [with _Tp = facebook::yoga::Node*]',
yoga>     inlined from 'constexpr _Tp* std::allocator< <template-parameter-1-1> >::allocate(std::size_t) [with _Tp = facebook::yoga::Node*]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/allocator.h:206:40,
yoga>     inlined from 'static constexpr _Tp* std::allocator_traits<std::allocator<_Up> >::allocate(allocator_type&, size_type) [with _Tp = facebook::yoga::Node*]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/alloc_traits.h:638:28,
yoga>     inlined from 'constexpr std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/stl_vector.h:389:33,
yoga>     inlined from 'constexpr void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/stl_vector.h:407:44,
yoga>     inlined from 'constexpr std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/stl_vector.h:341:26,
yoga>     inlined from 'constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = facebook::yoga::Node*; _Alloc = std::allocator<facebook::yoga::Node*>]' at /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/stl_vector.h:623:61,
yoga>     inlined from 'virtual void YogaTest_mixed_shared_and_owned_children_Test::TestBody()' at /build/source/tests/YGPersistenceTest.cpp:277:64:
yoga> /nix/store/xpaz3fi6ibqxb9sla4gjlp0c82v566y8-gcc-16.2.0/include/c++/16.2.0/bits/new_allocator.h:162:75: note: at offset -8 into object of size [0, 9223372036854775800] allocated by 'operator new'
yoga>   162 |           return static_cast<_Tp*>(_GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp)));
yoga>       |                                                                           ^

that is with

g++ --version
g++ (GCC) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I can open an issue if you wish.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants