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