1{ stdenv, lib, fetchFromGitHub, cmake, gflags, gtest, perl }:
2
3stdenv.mkDerivation rec {
4 pname = "glog";
5 version = "0.6.0";
6
7 src = fetchFromGitHub {
8 owner = "google";
9 repo = "glog";
10 rev = "v${version}";
11 sha256 = "sha256-xqRp9vaauBkKz2CXbh/Z4TWqhaUtqfbsSlbYZR/kW9s=";
12 };
13
14 nativeBuildInputs = [ cmake ];
15
16 buildInputs = [ gtest ];
17
18 propagatedBuildInputs = [ gflags ];
19
20 cmakeFlags = [
21 "-DBUILD_SHARED_LIBS=ON"
22 # glog's custom FindUnwind.cmake module detects LLVM's unwind in case
23 # stdenv.cc is clang. But the module doesn't get installed, causing
24 # consumers of the CMake config file to fail at the configuration step.
25 # Explicitly disabling unwind support sidesteps the issue.
26 "-DWITH_UNWIND=OFF"
27 ];
28
29 doCheck = true;
30
31 # There are some non-thread safe tests that can fail
32 enableParallelChecking = false;
33 nativeCheckInputs = [ perl ];
34
35 env.GTEST_FILTER =
36 let
37 filteredTests = lib.optionals stdenv.hostPlatform.isMusl [
38 "Symbolize.SymbolizeStackConsumption"
39 "Symbolize.SymbolizeWithDemanglingStackConsumption"
40 ] ++ lib.optionals stdenv.hostPlatform.isStatic [
41 "LogBacktraceAt.DoesBacktraceAtRightLineWhenEnabled"
42 ] ++ lib.optionals stdenv.cc.isClang [
43 # Clang optimizes an expected allocation away.
44 # See https://github.com/google/glog/issues/937
45 "DeathNoAllocNewHook.logging"
46 ] ++ lib.optionals stdenv.isDarwin [
47 "LogBacktraceAt.DoesBacktraceAtRightLineWhenEnabled"
48 ];
49 in
50 "-${builtins.concatStringsSep ":" filteredTests}";
51
52 checkPhase =
53 let
54 excludedTests = lib.optionals stdenv.isDarwin [
55 "mock-log"
56 ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
57 "logging" # works around segfaults on aarch64-darwin for now
58 ];
59 excludedTestsRegex = lib.optionalString (excludedTests != [ ]) "(${lib.concatStringsSep "|" excludedTests})";
60 in
61 ''
62 runHook preCheck
63 ctest -E "${excludedTestsRegex}" --output-on-failure
64 runHook postCheck
65 '';
66
67 meta = with lib; {
68 homepage = "https://github.com/google/glog";
69 license = licenses.bsd3;
70 description = "Library for application-level logging";
71 platforms = platforms.unix;
72 maintainers = with maintainers; [ nh2 r-burns ];
73 };
74}