forgejo-lts: 7.0.10 -> 7.0.11
[NixPkgs.git] / pkgs / applications / version-management / p4 / default.nix
blobec01f86a3af074a8bafb00bef80fd483d0dfa383
1 { stdenv
2 , fetchurl
3 , fetchzip
4 , lib
5 , emptyDirectory
6 , linkFarm
7 , jam
8 , openssl
9 , CoreServices
10 , Foundation
11 , Security
12 , testers
15 let
16   opensslStatic = openssl.override {
17     static = true;
18   };
19   androidZlibContrib =
20     let
21       src = fetchzip {
22         url = "https://android.googlesource.com/platform/external/zlib/+archive/61174f4fd262c6075f88768465f308aae95a2f04.tar.gz";
23         sha256 = "sha256-EMzKAHcEWOUugcHKH2Fj3ZaIHC9UlgO4ULKe3RvgxvI=";
24         stripRoot = false;
25       };
26     in
27     linkFarm "android-zlib-contrib" [
28       # We only want to keep the contrib directory as the other files conflict
29       # with p4's own zlib files. (For the same reason, we can't use the
30       # cone-based Git sparse checkout, either.)
31       { name = "contrib"; path = "${src}/contrib"; }
32     ];
34 stdenv.mkDerivation (finalAttrs: rec {
35   pname = "p4";
36   version = "2024.1/2596294";
38   src = fetchurl {
39     # Upstream replaces minor versions, so use archived URL.
40     url = "https://web.archive.org/web/20240526153453id_/https://ftp.perforce.com/perforce/r24.1/bin.tools/p4source.tgz";
41     sha256 = "sha256-6+DOJPeVzP4x0UsN9MlZRAyusapBTICX0BuyvVBQBC8=";
42   };
44   nativeBuildInputs = [ jam ];
46   buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ CoreServices Foundation Security ];
48   outputs = [ "out" "bin" "dev" ];
50   hardeningDisable = lib.optionals stdenv.hostPlatform.isDarwin [ "strictoverflow" ];
52   jamFlags =
53     [
54       "-sEXEC=bin.unix"
55       "-sCROSS_COMPILE=${stdenv.cc.targetPrefix}"
56       "-sMALLOC_OVERRIDE=no"
57       "-sSSLINCDIR=${lib.getDev opensslStatic}/include"
58       "-sSSLLIBDIR=${lib.getLib opensslStatic}/lib"
59     ]
60     ++ lib.optionals stdenv.cc.isClang [ "-sOSCOMP=clang" "-sCLANGVER=${stdenv.cc.cc.version}" ]
61     ++ lib.optionals stdenv.cc.isGNU [ "-sOSCOMP=gcc" "-sGCCVER=${stdenv.cc.cc.version}" ]
62     ++ lib.optionals stdenv.hostPlatform.isLinux [ "-sOSVER=26" ]
63     ++ lib.optionals stdenv.hostPlatform.isDarwin [
64       "-sOSVER=1013"
65       "-sMACOSX_SDK=${emptyDirectory}"
66       "-sLIBC++DIR=${lib.getLib stdenv.cc.libcxx}/lib"
67     ];
69   CCFLAGS =
70     # The file contrib/optimizations/slide_hash_neon.h is missing from the
71     # upstream distribution. It comes from the Android/Chromium sources.
72     lib.optionals stdenv.hostPlatform.isAarch64 [ "-I${androidZlibContrib}" ];
74   "C++FLAGS" =
75     # Avoid a compilation error that only occurs for 4-byte longs.
76     lib.optionals stdenv.hostPlatform.isi686 [ "-Wno-narrowing" ]
77     # See the "Header dependency changes" section of
78     # https://www.gnu.org/software/gcc/gcc-11/porting_to.html for more
79     # information on why we need to include these.
80     ++ lib.optionals
81       (stdenv.cc.isClang || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.cc.version "11.0.0"))
82       [ "-include" "limits" "-include" "thread" ];
84   buildPhase = ''
85     runHook preBuild
86     jam $jamFlags -j$NIX_BUILD_CORES p4
87     jam $jamFlags -j$NIX_BUILD_CORES -sPRODUCTION=yes p4api.tar
88     runHook postBuild
89   '';
91   installPhase = ''
92     runHook preInstall
93     mkdir -p $bin/bin $dev $out
94     cp bin.unix/p4 $bin/bin
95     cp -r bin.unix/p4api-*/include $dev
96     cp -r bin.unix/p4api-*/lib $out
97     runHook postInstall
98   '';
100   passthru.tests.version = testers.testVersion {
101     package = finalAttrs.finalPackage;
102     command = "p4 -V";
103   };
105   meta = with lib; {
106     description = "Perforce Helix Core command-line client and APIs";
107     homepage = "https://www.perforce.com";
108     license = licenses.bsd2;
109     mainProgram = "p4";
110     platforms = platforms.unix;
111     maintainers = with maintainers; [ corngood impl ];
112   };