8 # NUMA support enabled by default on NUMA platforms:
9 , numaSupport ? (stdenv.hostPlatform.isLinux && (stdenv.hostPlatform.isx86 || stdenv.hostPlatform.isAarch64))
12 # Multi bit-depth support (8bit+10bit+12bit):
13 , multibitdepthSupport ? (stdenv.is64bit && !(stdenv.isAarch64 && stdenv.isLinux))
16 , cliSupport ? true # Build standalone CLI application
17 , custatsSupport ? false # Internal profiling of encoder work
18 , debugSupport ? false # Run-time sanity checks (debugging)
19 , ppaSupport ? false # PPA profiling instrumentation
20 , unittestsSupport ? (stdenv.is64bit && !(stdenv.isDarwin && stdenv.isAarch64)) # Unit tests - only testing x64 assembly
21 , vtuneSupport ? false # Vtune profiling instrumentation
22 , werrorSupport ? false # Warnings as errors
26 mkFlag = optSet: flag: if optSet then "-D${flag}=ON" else "-D${flag}=OFF";
28 isCross = stdenv.buildPlatform != stdenv.hostPlatform;
32 (mkFlag custatsSupport "DETAILED_CU_STATS")
33 (mkFlag debugSupport "CHECKED_BUILD")
34 (mkFlag ppaSupport "ENABLE_PPA")
35 (mkFlag vtuneSupport "ENABLE_VTUNE")
36 (mkFlag werrorSupport "WARNINGS_AS_ERRORS")
39 cmakeStaticLibFlags = [
44 ] ++ lib.optionals stdenv.hostPlatform.isPower [
45 "-DENABLE_ALTIVEC=OFF" # https://bitbucket.org/multicoreware/x265_git/issues/320/fail-to-build-on-power8-le
50 stdenv.mkDerivation rec {
54 outputs = [ "out" "dev" ];
56 # Check that x265Version.txt contains the expected version number
57 # whether we fetch a source tarball or a tag from the git repo
59 url = "https://bitbucket.org/multicoreware/x265_git/downloads/x265_${version}.tar.gz";
60 hash = "sha256-5wozNcrKy7oLOiDsb+zWeDkyKI68gWOtdLzJYGR3yug=";
63 sourceRoot = "x265_${version}/source";
66 # More aliases for ARM platforms + do not force CLFAGS for ARM :
68 url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/media-libs/x265/files/arm-r1.patch?id=1d1de341e1404a46b15ae3e84bc400d474cf1a2c";
69 sha256 = "1hgzq5vxkwh0nyikxjfz8gz3jvx2nq3yy12mz3fn13qvzdlb5ilp";
71 # use proper check to avoid undefined symbols when enabling assembly on ARM :
73 url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/media-libs/x265/files/neon.patch?id=1d1de341e1404a46b15ae3e84bc400d474cf1a2c";
74 sha256 = "1mmshpbyldrfqxfmdajqal4l647zvlrwdai8pxw99qg4v8gajfii";
76 # More complete PPC64 matches :
78 url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/media-libs/x265/files/x265-3.3-ppc64.patch?id=1d1de341e1404a46b15ae3e84bc400d474cf1a2c";
79 sha256 = "1mvw678xfm0vr59n5jilq56qzcgk1gmcip2afyafkqiv21nbms8c";
81 # Namespace functions for multi-bitdepth builds so that libraries are self-contained (and tests succeeds) :
83 url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/media-libs/x265/files/test-ns.patch?id=1d1de341e1404a46b15ae3e84bc400d474cf1a2c";
84 sha256 = "0zg3g53l07yh7ar5c241x50y5zp7g8nh8rh63ad4bdpchpc2f52d";
86 # Fix detection of NEON (and armv6 build) :
87 ./fix-neon-detection.patch
91 substituteInPlace cmake/Version.cmake \
92 --replace "unknown" "${version}" \
93 --replace "0.0" "${version}"
96 nativeBuildInputs = [ cmake nasm ] ++ lib.optionals (numaSupport) [ numactl ];
98 # Builds 10bits and 12bits static libs on the side if multi bit-depth is wanted
99 # (we are in x265_<version>/source/build)
100 preBuild = lib.optionalString (multibitdepthSupport) ''
101 cmake -S ../ -B ../build-10bits ${toString cmakeCommonFlags} ${toString cmakeStaticLibFlags}
102 make -C ../build-10bits -j $NIX_BUILD_CORES
103 cmake -S ../ -B ../build-12bits ${toString cmakeCommonFlags} ${toString cmakeStaticLibFlags} -DMAIN12=ON
104 make -C ../build-12bits -j $NIX_BUILD_CORES
105 ln -s ../build-10bits/libx265.a ./libx265-10.a
106 ln -s ../build-12bits/libx265.a ./libx265-12.a
109 cmakeFlags = cmakeCommonFlags ++ [
110 "-DGIT_ARCHETYPE=1" # https://bugs.gentoo.org/814116
111 "-DENABLE_SHARED=${if stdenv.hostPlatform.isStatic then "OFF" else "ON"}"
112 "-DHIGH_BIT_DEPTH=OFF"
113 "-DENABLE_HDR10_PLUS=ON"
114 (mkFlag (isCross && stdenv.hostPlatform.isAarch) "CROSS_COMPILE_ARM")
115 (mkFlag cliSupport "ENABLE_CLI")
116 (mkFlag unittestsSupport "ENABLE_TESTS")
117 ] ++ lib.optionals (multibitdepthSupport) [
118 "-DEXTRA_LIB=x265-10.a;x265-12.a"
119 "-DEXTRA_LINK_FLAGS=-L."
124 doCheck = unittestsSupport;
132 rm -f ${placeholder "out"}/lib/*.a
136 description = "Library for encoding H.265/HEVC video streams";
137 homepage = "https://www.x265.org/";
138 changelog = "https://x265.readthedocs.io/en/master/releasenotes.html#version-${lib.strings.replaceStrings ["."] ["-"] version}";
139 license = licenses.gpl2Plus;
140 maintainers = with maintainers; [ codyopel ];
141 platforms = platforms.all;