|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + rust, |
| 5 | + rustPlatform, |
| 6 | + hdr10plus_tool, |
| 7 | + cargo-c, |
| 8 | + fontconfig, |
| 9 | +}: |
| 10 | + |
| 11 | +let |
| 12 | + inherit (lib) optionals concatStringsSep; |
| 13 | + inherit (rust.envVars) setEnv; |
| 14 | +in |
| 15 | +rustPlatform.buildRustPackage (finalAttrs: { |
| 16 | + __structuredAttrs = true; |
| 17 | + |
| 18 | + pname = "hdr10plus"; |
| 19 | + version = "2.1.3"; |
| 20 | + |
| 21 | + outputs = [ |
| 22 | + "out" |
| 23 | + "dev" |
| 24 | + ]; |
| 25 | + |
| 26 | + inherit (hdr10plus_tool) |
| 27 | + src |
| 28 | + useFetchCargoVendor |
| 29 | + cargoDeps |
| 30 | + cargoHash |
| 31 | + ; |
| 32 | + |
| 33 | + nativeBuildInputs = [ cargo-c ]; |
| 34 | + buildInputs = [ fontconfig ]; |
| 35 | + |
| 36 | + cargoCFlags = [ |
| 37 | + "--package=hdr10plus" |
| 38 | + "--frozen" |
| 39 | + "--prefix=${placeholder "out"}" |
| 40 | + "--includedir=${placeholder "dev"}/include" |
| 41 | + "--pkgconfigdir=${placeholder "dev"}/lib/pkgconfig" |
| 42 | + "--target=${stdenv.hostPlatform.rust.rustcTarget}" |
| 43 | + ]; |
| 44 | + |
| 45 | + # mirror Cargo flags |
| 46 | + cargoCBuildFlags = |
| 47 | + optionals (finalAttrs.cargoBuildType != "debug") [ |
| 48 | + "--profile=${finalAttrs.cargoBuildType}" |
| 49 | + ] |
| 50 | + ++ optionals (finalAttrs.cargoBuildNoDefaultFeatures) [ |
| 51 | + "--no-default-features" |
| 52 | + ] |
| 53 | + ++ optionals (finalAttrs.cargoBuildFeatures != [ ]) [ |
| 54 | + "--features=${concatStringsSep "," finalAttrs.cargoBuildFeatures}" |
| 55 | + ]; |
| 56 | + |
| 57 | + cargoCTestFlags = |
| 58 | + optionals (finalAttrs.cargoCheckType != "debug") [ |
| 59 | + "--profile=${finalAttrs.cargoCheckType}" |
| 60 | + ] |
| 61 | + ++ optionals (finalAttrs.cargoCheckNoDefaultFeatures) [ |
| 62 | + "--no-default-features" |
| 63 | + ] |
| 64 | + ++ optionals (finalAttrs.cargoCheckFeatures != [ ]) [ |
| 65 | + "--features=${concatStringsSep "," finalAttrs.cargoCheckFeatures}" |
| 66 | + ]; |
| 67 | + |
| 68 | + configurePhase = '' |
| 69 | + # let stdenv handle stripping |
| 70 | + export "CARGO_PROFILE_''${cargoBuildType@U}_STRIP"=false |
| 71 | +
|
| 72 | + prependToVar cargoCFlags -j "$NIX_BUILD_CORES" |
| 73 | + ''; |
| 74 | + |
| 75 | + buildPhase = '' |
| 76 | + runHook preBuild |
| 77 | +
|
| 78 | + ${setEnv} cargo cbuild "''${cargoCFlags[@]}" "''${cargoCBuildFlags[@]}" |
| 79 | +
|
| 80 | + runHook postBuild |
| 81 | + ''; |
| 82 | + |
| 83 | + checkPhase = '' |
| 84 | + runHook preCheck |
| 85 | +
|
| 86 | + ${setEnv} cargo ctest "''${cargoCFlags[@]}" "''${cargoCTestFlags[@]}" |
| 87 | +
|
| 88 | + runHook postCheck |
| 89 | + ''; |
| 90 | + |
| 91 | + installPhase = '' |
| 92 | + runHook preInstall |
| 93 | +
|
| 94 | + ${setEnv} cargo cinstall "''${cargoCFlags[@]}" "''${cargoCBuildFlags[@]}" |
| 95 | +
|
| 96 | + runHook postInstall |
| 97 | + ''; |
| 98 | + |
| 99 | + passthru.tests = { |
| 100 | + inherit hdr10plus_tool; |
| 101 | + }; |
| 102 | + |
| 103 | + meta = { |
| 104 | + description = "Library to work with HDR10+ in HEVC files"; |
| 105 | + homepage = "https://github.com/quietvoid/hdr10plus_tool"; |
| 106 | + changelog = "https://github.com/quietvoid/hdr10plus_tool/releases/tag/${hdr10plus_tool.version}"; |
| 107 | + license = lib.licenses.mit; |
| 108 | + maintainers = with lib.maintainers; [ mvs ]; |
| 109 | + pkgConfigModules = [ "hdr10plus-rs" ]; |
| 110 | + }; |
| 111 | +}) |
0 commit comments