Skip to content

ARROW-5403: [C++] Use GTest shared libraries with BUNDLED build, always use BUNDLED with MSVC - #4380

Closed
wesm wants to merge 5 commits into
apache:masterfrom
wesm:gtest-windows-dll
Closed

wesm wants to merge 5 commits into
apache:masterfrom
wesm:gtest-windows-dll

Conversation

@wesm

@wesm wesm commented May 23, 2019 •

Copy link
Copy Markdown
Member

Without this change, failed assertions do not cause failed unit tests on Windows as Antoine had discovered today.

The conda-forge test package seems unusable in shared library form so I'm forcing BUNDLED builds on MSVC (if not otherwise specified) and removing the hacks in the docs and Appveyor to pass -DGTest_SOURCE=BUNDLED

After this change the static CRT Windows tests do not work anymore (because gtest.dll has its own copy of the static CRT, which leads to conflicts), so we will have to explore testing the static CRT build as follow up work. See ARROW-5426

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kou can you confirm if this is needed with MinGW also (so WIN32 instead of MSVC)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've confirmed. This isn't needed with MinGW.

...
[ RUN      ] TestAllocate.Bitmap
C:/Users/kou/work/arrow/arrow.kou/cpp/src/arrow/testing/gtest_util.cc:120: Failure
Value of: buffer.Equals(expected)
  Actual: false
Expected: true
[  FAILED  ] TestAllocate.Bitmap (0 ms)
...
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestAllocate.Bitmap

 1 FAILED TEST
...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The googletest DLLs have to be put in the same directory as the build artifacts otherwise they won't be found when you run ctest

@wesm

wesm commented May 23, 2019

Copy link
Copy Markdown
Member Author

Hm, this worked locally for me but evidently needs some more fiddling to get it to work in. @pitrou do you want to try to fix it from here? I've sunk multiple hours into this now

@pitrou

pitrou commented May 24, 2019

Copy link
Copy Markdown
Member

I could give it a try on Monday.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=${BUILD_OUTPUT_ROOT_DIRECTORY}/Debug")
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=${BUILD_OUTPUT_ROOT_DIRECTORY}/${CMAKE_BUILD_TYPE}")

or maybe BUILD_SUBDIR_NAME? This doesn't seem like it'd work with RelWithDebInfo, for example

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So MSVC adds these Release directories. Is it case sensitive?

@wesm

wesm commented May 24, 2019

Copy link
Copy Markdown
Member Author

@bkietz do you have access to a Windows environment to try to fix this?

@wesm

wesm commented May 24, 2019

Copy link
Copy Markdown
Member Author

I'm going to take a half hour to try a few more things

@wesm

wesm commented May 24, 2019

Copy link
Copy Markdown
Member Author

The normal MSVC builds passed but the static CRT build failed with

array-test.cc.obj : error LNK2001: unresolved external symbol "class testing::internal::Mutex testing::internal::g_linked_ptr_mutex" (?g_linked_ptr_mutex@internal@testing@@3VMutex@12@A)
debug\arrow-array-test.exe : fatal error LNK1120: 1 unresolved externals
[242/323] Linking CXX executable debug\arrow-file-to-stream.exe
[243/323] Linking CXX executable debug\arrow-stream-to-file.exe
ninja: build stopped: subcommand failed.
C:\projects\arrow\cpp\build-debug>goto scriptexit 

The BUNDLED build in Travis CI is the only one failing but I haven't been able to repro the issue yet locally

@wesm

wesm commented May 24, 2019

Copy link
Copy Markdown
Member Author

OK, the static CRT build links now, but fails at runtime.

I fear that the combination of dynamic linking and static CRT may be incompatible

@wesm

wesm commented May 25, 2019 •

Copy link
Copy Markdown
Member Author

I've been googling about this and it seems that there are potential issues with having different libraries or executable respectively using /MT to statically-link the CRT

https://docs.microsoft.com/en-us/cpp/c-runtime-library/potential-errors-passing-crt-objects-across-dll-boundaries?view=vs-2019

I would be inclined to either:

  • do a library-only static CRT build but not run the unit tests
  • disable the static CRT build altogether

To continue to support this build configuration given how few Windows developers we have seems an undue hardship

cc @Maxris @rip-nsk if you have any wisdom to offer about this situation

  • gtest.dll built with /MT
  • arrow_testing.dll built with /MT, linking dynamically to gtest.dll
  • arrow-something-test.exe also built with /MT, linking dynamically to arrow_testing.dll

@maxhora

maxhora commented May 25, 2019

Copy link
Copy Markdown
Contributor

Hey @wesm ,

From https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019

Using the statically linked CRT implies that any state information saved by the C runtime library will be local to that instance of the CRT. For example, if you use strtok, _strtok_l, wcstok, _wcstok_l, _mbstok, _mbstok_l when using a statically linked CRT, the position of the strtok parser is unrelated to the strtok state used in code in the same process (but in a different DLL or EXE) that is linked to another instance of the static CRT. In contrast, the dynamically linked CRT shares state for all code within a process that is dynamically linked to the CRT. This concern does not apply if you use the new more secure versions of these functions; for example, strtok_s does not have this problem.

Because a DLL built by linking to a static CRT will have its own CRT state, it is not recommended to link statically to the CRT in a DLL unless the consequences of this are specifically desired and understood.

With above in mind, it sounds reasonable to not run unit tests, but to keep the build configuration just to verify that compilation passes without errors, so someone who will want to build their 3rd party application statically with static /MT linkage of runtime will get library compatibility out of the box.
The best solution (to avoid partially working builds), seems, is to have fully static build configured with /MT without any dlls linked, if possible.

Please correct me if I have understood something wrong, thanks

@pitrou

pitrou commented May 25, 2019

Copy link
Copy Markdown
Member

I would be inclined to either:
do a library-only static CRT build but not run the unit tests
disable the static CRT build altogether

Same here. If people are interested in fixing the CMake build chain to enable statically-linked tests on Windows, they can submit a PR.

@wesm

wesm commented May 27, 2019

Copy link
Copy Markdown
Member Author

@pitrou @Maxris OK, I will rebase this PR and set the static CRT build to not run the unit tests anymore. Honestly is it even worth building them?

@wesm

wesm commented May 27, 2019

Copy link
Copy Markdown
Member Author

There was already this comment in the build scripts:

  @rem Since we link the CRT statically, we should also disable building
  @rem the Arrow shared library to link the tests statically, otherwise
  @rem the Arrow DLL and the tests end up using a different instance of
  @rem the CRT, which wreaks havoc.

I'll continue to build the unit tests, but not run them

@pitrou

pitrou commented May 27, 2019

Copy link
Copy Markdown
Member

We don't need to build the tests if we don't run them.
(I think that comment was from me?)

@wesm

wesm commented May 27, 2019

Copy link
Copy Markdown
Member Author

Yeah I think you wrote it. Honestly I think we should just drop the static CRT build altogether for right now. The correct approach to actually test it is to build and link everything including Arrow and GTest statically. Are you OK with me disabling the static CRT Appveyor entry and opening a JIRA for someone else to work on it (if they care)?

@pitrou

pitrou commented May 27, 2019

Copy link
Copy Markdown
Member

No problem from me. I think @Maxris originally added it so perhaps he has a different opinion, though.

@maxhora

maxhora commented May 27, 2019

Copy link
Copy Markdown
Contributor

@pitrou @wesm disabling and opening Jira ticket sounds good

@wesm
wesm force-pushed the gtest-windows-dll branch from 7e90869 to 872434a Compare May 27, 2019 18:16
@wesm

wesm commented May 27, 2019

Copy link
Copy Markdown
Member Author

OK, opened ARROW-5426. This can be merged once the build passes. I'm about to get on an airplane so I can look at it later today

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we force that only if the user didn't pass GTest_SOURCE explicitly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, will fix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

@wesm

wesm commented May 29, 2019

Copy link
Copy Markdown
Member Author

Will address the outstanding issues on this tomorrow so we can get it merged

wesm added 5 commits May 30, 2019 12:34
Use gtest shared library, handle Windows-related quirks with EP build

Always build bundled gtest on MSVC

Fix up build on Linux

Passing GTest_SOURCE=BUNDLED no longer needed on MSVC

Try passing CMAKE_CXX_FLAGS as string in MSVC build

Try something else

ninja weirdness

Use different RUNTIME_OUTPUT_DIRECTORY for Ninja build generator

Fix up CMake args for googletest

Try slightly different incantation

cmake-format
@wesm
wesm force-pushed the gtest-windows-dll branch from 872434a to 515f75b Compare May 30, 2019 17:36
@wesm

wesm commented May 30, 2019

Copy link
Copy Markdown
Member Author

Rebased. I'll merge this as soon as the build passes

@wesm

wesm commented May 30, 2019

Copy link
Copy Markdown
Member Author

Hm, the Appveyor MinGW build is failed because of the NumPy issue. The MSVC builds look good though https://ci.appveyor.com/project/wesm/arrow/builds/24929805

@kou @pitrou @shiro615 are you OK with me merging this with the possible risk (low, since MinGW is more Linux-like) that there will be a subsequent issue?

@pitrou

pitrou commented May 30, 2019

Copy link
Copy Markdown
Member

@wesm Fine with me at least.

@wesm wesm closed this in c39db99 May 30, 2019
@wesm
wesm deleted the gtest-windows-dll branch May 30, 2019 23:56
@wesm

wesm commented May 30, 2019

Copy link
Copy Markdown
Member Author

Please ping me if any issues are encountered and I can try to help

@kou

kou commented May 31, 2019

Copy link
Copy Markdown
Member

No problem.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants