From 84dcdc352cf047a6eab869a8b4b223b5ccc7e680 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 14 Nov 2024 03:07:56 +0000 Subject: [PATCH] fbthrift: split outputs (cherry picked from commit 7699884b844f330209eccd18906f90e1b95405e8) --- pkgs/by-name/fb/fbthrift/package.nix | 33 +++++++++++++++++++ .../fbthrift/remove-cmake-install-rpath.patch | 12 +++++++ 2 files changed, 45 insertions(+) create mode 100644 pkgs/by-name/fb/fbthrift/remove-cmake-install-rpath.patch diff --git a/pkgs/by-name/fb/fbthrift/package.nix b/pkgs/by-name/fb/fbthrift/package.nix index ebc8f5c688cd..bbebf9b1c207 100644 --- a/pkgs/by-name/fb/fbthrift/package.nix +++ b/pkgs/by-name/fb/fbthrift/package.nix @@ -6,6 +6,7 @@ cmake, ninja, + removeReferencesTo, openssl, gflags, @@ -27,6 +28,14 @@ stdenv.mkDerivation (finalAttrs: { pname = "fbthrift"; version = "2024.11.18.00"; + outputs = [ + # Trying to split this up further into `bin`, `out`, and `dev` + # causes issues with circular references due to the installed CMake + # files referencing the path to the compiler. + "out" + "lib" + ]; + src = fetchFromGitHub { owner = "facebook"; repo = "fbthrift"; @@ -34,9 +43,16 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-dJf4vaIcat24WiKLFNEqeCnJYiO+c5YkuFu+hrS6cPE="; }; + patches = [ + # Remove a line that breaks the build due to the CMake classic of + # incorrect path concatenation. + ./remove-cmake-install-rpath.patch + ]; + nativeBuildInputs = [ cmake ninja + removeReferencesTo ]; buildInputs = @@ -69,6 +85,11 @@ stdenv.mkDerivation (finalAttrs: { # TODO: Can’t figure out where the C++ tests are wired up in the # CMake build, if anywhere, and this requires Python. #(lib.cmakeBool "enable_tests" finalAttrs.finalPackage.doCheck) + + (lib.cmakeFeature "BIN_INSTALL_DIR" "${placeholder "out"}/bin") + (lib.cmakeFeature "INCLUDE_INSTALL_DIR" "${placeholder "out"}/include") + (lib.cmakeFeature "LIB_INSTALL_DIR" "${placeholder "lib"}/lib") + (lib.cmakeFeature "CMAKE_INSTALL_DIR" "${placeholder "out"}/lib/cmake/fbthrift") ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ # Homebrew sets this, and the shared library build fails without @@ -76,6 +97,18 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeFeature "CMAKE_SHARED_LINKER_FLAGS" "-Wl,-undefined,dynamic_lookup") ]; + postFixup = '' + # Sanitize header paths to avoid runtime dependencies leaking in + # through `__FILE__`. + ( + shopt -s globstar + for header in "$out/include"/**/*.h; do + sed -i "1i#line 1 \"$header\"" "$header" + remove-references-to -t "$out" "$header" + done + ) + ''; + meta = { description = "Facebook's branch of Apache Thrift"; mainProgram = "thrift1"; diff --git a/pkgs/by-name/fb/fbthrift/remove-cmake-install-rpath.patch b/pkgs/by-name/fb/fbthrift/remove-cmake-install-rpath.patch new file mode 100644 index 000000000000..84271ca24697 --- /dev/null +++ b/pkgs/by-name/fb/fbthrift/remove-cmake-install-rpath.patch @@ -0,0 +1,12 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c6b2b2a810..497dcd3d94 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -39,7 +39,6 @@ + set(CMAKE_INSTALL_DIR lib/cmake/fbthrift CACHE STRING + "The subdirectory where CMake package config files should be installed") + +-set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + + # Add root dir so qualified includes work, e.g. #include "thrift/compiler/*.h".