lol
1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, simdExtensions ? null
6}:
7
8let
9 inherit (lib)
10 head
11 licenses
12 maintainers
13 platforms
14 replaceStrings
15 toList
16 ;
17
18 # SIMD instruction sets to compile for. If none are specified by the user,
19 # an appropriate one is selected based on the detected host system
20 isas = with stdenv.hostPlatform;
21 if simdExtensions != null then toList simdExtensions
22 else if avx2Support then [ "AVX2" ]
23 else if sse4_1Support then [ "SSE41" ]
24 else if isx86_64 then [ "SSE2" ]
25 else if isAarch64 then [ "NEON" ]
26 else [ "NONE" ];
27
28 # CMake Build flags for the selected ISAs. For a list of flags, see
29 # https://github.com/ARM-software/astc-encoder/blob/main/Docs/Building.md
30 isaFlags = map ( isa: "-DASTCENC_ISA_${isa}=ON" ) isas;
31
32 # The suffix of the binary to link as 'astcenc'
33 mainBinary = replaceStrings
34 [ "AVX2" "SSE41" "SSE2" "NEON" "NONE" "NATIVE" ]
35 [ "avx2" "sse4.1" "sse2" "neon" "none" "native" ]
36 ( head isas );
37in
38
39stdenv.mkDerivation rec {
40 pname = "astc-encoder";
41 version = "4.8.0";
42
43 src = fetchFromGitHub {
44 owner = "ARM-software";
45 repo = "astc-encoder";
46 rev = version;
47 sha256 = "sha256-IG/UpTaeKTXdYIR++BZA7+bMRW4NWQUo9PxsEnqPuB4=";
48 };
49
50 nativeBuildInputs = [ cmake ];
51
52 cmakeBuildType = "RelWithDebInfo";
53
54 cmakeFlags = isaFlags ++ [
55 "-DASTCENC_UNIVERSAL_BUILD=OFF"
56 ];
57
58 # Set a fixed build year to display within help output (otherwise, it would be 1980)
59 postPatch = ''
60 substituteInPlace Source/cmake_core.cmake \
61 --replace 'string(TIMESTAMP astcencoder_YEAR "%Y")' 'set(astcencoder_YEAR "2023")'
62 '';
63
64 # Provide 'astcenc' link to main executable
65 postInstall = ''
66 ln -s $out/bin/astcenc-${mainBinary} $out/bin/astcenc
67 '';
68
69 meta = {
70 homepage = "https://github.com/ARM-software/astc-encoder";
71 description = "An encoder for the ASTC texture compression format";
72 longDescription = ''
73 The Adaptive Scalable Texture Compression (ASTC) format is
74 widely supported by mobile and desktop graphics hardware and
75 provides better quality at a given bitrate compared to ETC2.
76
77 This program supports both compression and decompression in LDR
78 and HDR mode and can read various image formats. Run `astcenc
79 -help` to see all the options.
80 '';
81 platforms = platforms.unix;
82 license = licenses.asl20;
83 maintainers = with maintainers; [ dasisdormax ];
84 broken = !stdenv.is64bit;
85 };
86}