Skip to content

Fix BUILD_SHARED_LIBS=ON#690

Closed
simonmar wants to merge 1 commit into
facebook:mainfrom
simonmar:fix-shared-libs
Closed

Fix BUILD_SHARED_LIBS=ON#690
simonmar wants to merge 1 commit into
facebook:mainfrom
simonmar:fix-shared-libs

Conversation

@simonmar

Copy link
Copy Markdown
Contributor

Building with shared libs is broken, because there's a circular dependency between thrifttype and thriftanyrep.

The dependency of thrifttype on thriftanyrep is currently missing, which leads to link errors, but adding the dependency causes a Cmake error due to the circular dependency.

The patch makes 3 changes to fbthrift's thrift/lib/cpp2/CMakeLists.txt:

  1. Merges any_rep generated sources into thrifttype — adds ${any_rep-cpp2-SOURCES} and its bypass_source_check to the thrifttype library. This puts AnyStruct/SemiAnyStruct symbols directly in
    libthrifttype.so, resolving the undefined references.
  2. Replaces thriftanyrep with a thin stub — uses file(WRITE ...) to create an empty source file and builds thriftanyrep as a minimal shared library that links PUBLIC thrifttype. This preserves libthriftanyrep.so on disk so the Haskell FFI (thrift-cpp-channel.cabal links -lthriftanyrep) keeps working.
  3. Adds thriftanyrep to the set_target_properties VERSION list — so it gets a proper soname like the other libraries when BUILD_SHARED_LIBS=ON.
Building with shared libs is broken, because there's a circular
dependency between thrifttype and thriftanyrep.

The dependency of thrifttype on thriftanyrep is currently missing, which
leads to link errors, but adding the dependency causes a Cmake error due
to the circular dependency.

The patch makes 3 changes to fbthrift's thrift/lib/cpp2/CMakeLists.txt:

 1. Merges any_rep generated sources into thrifttype — adds ${any_rep-cpp2-SOURCES} and its
bypass_source_check to the thrifttype library. This puts AnyStruct/SemiAnyStruct symbols directly in
 libthrifttype.so, resolving the undefined references.
 2. Replaces thriftanyrep with a thin stub — uses file(WRITE ...) to create an empty source file and
 builds thriftanyrep as a minimal shared library that links PUBLIC thrifttype. This preserves
libthriftanyrep.so on disk so the Haskell FFI (thrift-cpp-channel.cabal links -lthriftanyrep) keeps
working.
 3. Adds thriftanyrep to the set_target_properties VERSION list — so it gets a proper soname like
the other libraries when BUILD_SHARED_LIBS=ON.
@meta-cla meta-cla Bot added the CLA Signed label Mar 12, 2026
@meta-codesync

meta-codesync Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

@iahs has imported this pull request. If you are a Meta employee, you can view this in D96487232.

@meta-codesync meta-codesync Bot closed this in 7543103 Mar 13, 2026
@meta-codesync

meta-codesync Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

@iahs merged this pull request in 7543103.

meta-codesync Bot pushed a commit to facebook/hhvm that referenced this pull request Mar 13, 2026
Summary:
Building with shared libs is broken, because there's a circular dependency between thrifttype and thriftanyrep.

The dependency of thrifttype on thriftanyrep is currently missing, which leads to link errors, but adding the dependency causes a Cmake error due to the circular dependency.

The patch makes 3 changes to fbthrift's thrift/lib/cpp2/CMakeLists.txt:

 1. Merges any_rep generated sources into thrifttype — adds ${any_rep-cpp2-SOURCES} and its bypass_source_check to the thrifttype library. This puts AnyStruct/SemiAnyStruct symbols directly in
 libthrifttype.so, resolving the undefined references.
 2. Replaces thriftanyrep with a thin stub — uses file(WRITE ...) to create an empty source file and builds thriftanyrep as a minimal shared library that links PUBLIC thrifttype. This preserves libthriftanyrep.so on disk so the Haskell FFI (thrift-cpp-channel.cabal links -lthriftanyrep) keeps working.
 3. Adds thriftanyrep to the set_target_properties VERSION list — so it gets a proper soname like the other libraries when BUILD_SHARED_LIBS=ON.

X-link: facebook/fbthrift#690

Reviewed By: Mizuchi

Differential Revision: D96487232

Pulled By: iahs

fbshipit-source-id: 88530afa568f227d5aea022fdf6ee133dcfc9906
meta-codesync Bot pushed a commit that referenced this pull request Mar 17, 2026
Summary:
Followup to #690, that PR inadvertently added a circular dependency between the thrifttype and thriftanyrep libraries, which means the `BUILD_SHARED_LIBS=ON` build still fails. This should fix it.

Tested with a PR on the hsthrift repo: facebookincubator/hsthrift#174

Pull Request resolved: #692

Reviewed By: Mizuchi

Differential Revision: D96944523

Pulled By: iahs

fbshipit-source-id: ecb75e972d7d074eff1f44c29ba0960ca8416970
meta-codesync Bot pushed a commit to facebook/hhvm that referenced this pull request Mar 17, 2026
Summary:
Followup to facebook/fbthrift#690, that PR inadvertently added a circular dependency between the thrifttype and thriftanyrep libraries, which means the `BUILD_SHARED_LIBS=ON` build still fails. This should fix it.

Tested with a PR on the hsthrift repo: facebookincubator/hsthrift#174

X-link: facebook/fbthrift#692

Reviewed By: Mizuchi

Differential Revision: D96944523

Pulled By: iahs

fbshipit-source-id: ecb75e972d7d074eff1f44c29ba0960ca8416970
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant