From a6128dea0c6b6da6edbd02c9692b78cf924deac4 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 22 May 2023 18:44:00 +0000 Subject: x265: fix cross compilation to non-aarch64 Previously, the multibitdepth cmake invocations didn't use cmakeFlags. This meant that they didn't get the flags added by stdenv for cross compilation, and so they didn't cross compile. To fix this, add cmakeCommonFlags into cmakeFlags, and then add all the non-common flags to cmakeFlagsArray after the multibitdepth stuff has been configured. As a consequence of this change, we also no longer need to disable asm for RISC-V. Co-authored-by: ash lea --- pkgs/development/libraries/x265/default.nix | 78 +++++++++++++++-------------- 1 file changed, 40 insertions(+), 38 deletions(-) (limited to 'pkgs/development/libraries') diff --git a/pkgs/development/libraries/x265/default.nix b/pkgs/development/libraries/x265/default.nix index b63b0101d54..e090e460603 100644 --- a/pkgs/development/libraries/x265/default.nix +++ b/pkgs/development/libraries/x265/default.nix @@ -26,26 +26,6 @@ let mkFlag = optSet: flag: if optSet then "-D${flag}=ON" else "-D${flag}=OFF"; isCross = stdenv.buildPlatform != stdenv.hostPlatform; - - cmakeCommonFlags = [ - "-Wno-dev" - (mkFlag custatsSupport "DETAILED_CU_STATS") - (mkFlag debugSupport "CHECKED_BUILD") - (mkFlag ppaSupport "ENABLE_PPA") - (mkFlag vtuneSupport "ENABLE_VTUNE") - (mkFlag werrorSupport "WARNINGS_AS_ERRORS") - # Potentially riscv cross could be fixed by providing the correct CMAKE_SYSTEM_PROCESSOR flag - ] ++ lib.optional (isCross && stdenv.hostPlatform.isRiscV) "-DENABLE_ASSEMBLY=OFF"; - - cmakeStaticLibFlags = [ - "-DHIGH_BIT_DEPTH=ON" - "-DENABLE_CLI=OFF" - "-DENABLE_SHARED=OFF" - "-DEXPORT_C_API=OFF" - ] ++ lib.optionals stdenv.hostPlatform.isPower [ - "-DENABLE_ALTIVEC=OFF" # https://bitbucket.org/multicoreware/x265_git/issues/320/fail-to-build-on-power8-le - ]; - in stdenv.mkDerivation rec { @@ -96,32 +76,54 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake nasm ] ++ lib.optionals (numaSupport) [ numactl ]; + cmakeFlags = [ + "-Wno-dev" + (mkFlag custatsSupport "DETAILED_CU_STATS") + (mkFlag debugSupport "CHECKED_BUILD") + (mkFlag ppaSupport "ENABLE_PPA") + (mkFlag vtuneSupport "ENABLE_VTUNE") + (mkFlag werrorSupport "WARNINGS_AS_ERRORS") + ]; + + cmakeStaticLibFlags = [ + "-DHIGH_BIT_DEPTH=ON" + "-DENABLE_CLI=OFF" + "-DENABLE_SHARED=OFF" + "-DEXPORT_C_API=OFF" + ] ++ lib.optionals stdenv.hostPlatform.isPower [ + "-DENABLE_ALTIVEC=OFF" # https://bitbucket.org/multicoreware/x265_git/issues/320/fail-to-build-on-power8-le + ]; + + preConfigure = lib.optionalString multibitdepthSupport '' + cmake -B build-10bits $cmakeFlags "''${cmakeFlagsArray[@]}" $cmakeStaticLibFlags + cmake -B build-12bits $cmakeFlags "''${cmakeFlagsArray[@]}" $cmakeStaticLibFlags -DMAIN12=ON + cmakeFlagsArray+=( + -DEXTRA_LIB="x265-10.a;x265-12.a" + -DEXTRA_LINK_FLAGS=-L. + -DLINKED_10BIT=ON + -DLINKED_12BIT=ON + ) + '' + '' + cmakeFlagsArray+=( + -DGIT_ARCHETYPE=1 # https://bugs.gentoo.org/814116 + ${mkFlag (!stdenv.hostPlatform.isStatic) "ENABLE_SHARED"} + -DHIGH_BIT_DEPTH=OFF + -DENABLE_HDR10_PLUS=ON + ${mkFlag (isCross && stdenv.hostPlatform.isAarch) "CROSS_COMPILE_ARM"} + ${mkFlag cliSupport "ENABLE_CLI"} + ${mkFlag unittestsSupport "ENABLE_TESTS"} + ) + ''; + # Builds 10bits and 12bits static libs on the side if multi bit-depth is wanted # (we are in x265_/source/build) - preBuild = lib.optionalString (multibitdepthSupport) '' - cmake -S ../ -B ../build-10bits ${toString cmakeCommonFlags} ${toString cmakeStaticLibFlags} + preBuild = lib.optionalString multibitdepthSupport '' make -C ../build-10bits -j $NIX_BUILD_CORES - cmake -S ../ -B ../build-12bits ${toString cmakeCommonFlags} ${toString cmakeStaticLibFlags} -DMAIN12=ON make -C ../build-12bits -j $NIX_BUILD_CORES ln -s ../build-10bits/libx265.a ./libx265-10.a ln -s ../build-12bits/libx265.a ./libx265-12.a ''; - cmakeFlags = cmakeCommonFlags ++ [ - "-DGIT_ARCHETYPE=1" # https://bugs.gentoo.org/814116 - "-DENABLE_SHARED=${if stdenv.hostPlatform.isStatic then "OFF" else "ON"}" - "-DHIGH_BIT_DEPTH=OFF" - "-DENABLE_HDR10_PLUS=ON" - (mkFlag (isCross && stdenv.hostPlatform.isAarch) "CROSS_COMPILE_ARM") - (mkFlag cliSupport "ENABLE_CLI") - (mkFlag unittestsSupport "ENABLE_TESTS") - ] ++ lib.optionals (multibitdepthSupport) [ - "-DEXTRA_LIB=x265-10.a;x265-12.a" - "-DEXTRA_LINK_FLAGS=-L." - "-DLINKED_10BIT=ON" - "-DLINKED_12BIT=ON" - ]; - doCheck = unittestsSupport; checkPhase = '' runHook preCheck -- cgit 1.4.1