diff --git a/pkgs/by-name/nb/nbytes/package.nix b/pkgs/by-name/nb/nbytes/package.nix new file mode 100644 index 000000000000..5cb94ca957e8 --- /dev/null +++ b/pkgs/by-name/nb/nbytes/package.nix @@ -0,0 +1,64 @@ +{ + lib, + cmake, + fetchFromGitHub, + fetchpatch2, + gtest, + nix-update-script, + stdenv, + testers, + validatePkgConfig, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "nbytes"; + version = "0.1.2"; + + src = fetchFromGitHub { + owner = "nodejs"; + repo = "nbytes"; + tag = "v${finalAttrs.version}"; + hash = "sha256-lsd1Qrv1HEz/5ry10s7Pq7unoh3y9ZmwCaT+6nTlxkc="; + }; + + patches = [ + # Use `gtest` from Nixpkgs to allow an offline build + ./use-nix-googletest.patch + # Add support for pkgconfig for use as a shared lib + # TODO: remove when included in the next release + (fetchpatch2 { + url = "https://github.com/nodejs/nbytes/commit/00f48a0620cef800054d4aab061f09d89990a1b9.patch?full_index=1"; + hash = "sha256-uOPEI70Dq446K56BSFHVyxDHNaYY5OASu3QeWGCLQmI="; + }) + ]; + + outputs = [ + "out" + ]; + + nativeBuildInputs = [ + cmake + validatePkgConfig + ]; + buildInputs = [ + gtest + ]; + + passthru = { + updateScript = nix-update-script { }; + + tests.pkg-config = testers.hasPkgConfigModules { + package = finalAttrs.finalPackage; + }; + }; + + meta = { + description = "Library of byte handling functions extracted from Node.js core"; + homepage = "https://github.com/nodejs/nbytes"; + changelog = "https://github.com/nodejs/nbytes/releases/tag/v${finalAttrs.version}"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ aduh95 ]; + platforms = lib.platforms.all; + pkgConfigModules = [ "nbytes" ]; + }; +}) diff --git a/pkgs/by-name/nb/nbytes/use-nix-googletest.patch b/pkgs/by-name/nb/nbytes/use-nix-googletest.patch new file mode 100644 index 000000000000..859aa81603bd --- /dev/null +++ b/pkgs/by-name/nb/nbytes/use-nix-googletest.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f2efa3c..3f363dd 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -11,15 +11,9 @@ endif() + option(NBYTES_DEVELOPMENT_CHECKS "Enable development checks" OFF) + + include(GNUInstallDirs) +-include(FetchContent) + +-FetchContent_Declare( +- googletest +- URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +-) +-# For Windows: Prevent overriding the parent project's compiler/linker settings +-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +-FetchContent_MakeAvailable(googletest) ++# Use find_package to use the gtest package provided by Nix ++find_package(GTest REQUIRED) + + add_subdirectory(src) + enable_testing()