summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaximilian Wende <dasisdormax@mailbox.org>2021-04-20 09:17:53 +0200
committerMaximilian Wende <dasisdormax@mailbox.org>2021-04-20 09:17:53 +0200
commitd94462e97be88caa6006b2d6c1e3a2e595758eb2 (patch)
tree4f9dd1551675adc2b38778eea225c701e6bb57ea
parent6426d1e6c063c8cd11b18a3b67c90a2d9af2da25 (diff)
downloadnixpkgs-d94462e97be88caa6006b2d6c1e3a2e595758eb2.tar
nixpkgs-d94462e97be88caa6006b2d6c1e3a2e595758eb2.tar.gz
nixpkgs-d94462e97be88caa6006b2d6c1e3a2e595758eb2.tar.bz2
nixpkgs-d94462e97be88caa6006b2d6c1e3a2e595758eb2.tar.lz
nixpkgs-d94462e97be88caa6006b2d6c1e3a2e595758eb2.tar.xz
nixpkgs-d94462e97be88caa6006b2d6c1e3a2e595758eb2.tar.zst
nixpkgs-d94462e97be88caa6006b2d6c1e3a2e595758eb2.zip
astc-encoder: init at 2.5
This builds the astc-encoder with the appropriate SIMD
instructions automatically selected depending on host machine.
-rw-r--r--pkgs/tools/graphics/astc-encoder/default.nix71
-rw-r--r--pkgs/top-level/all-packages.nix2
2 files changed, 73 insertions, 0 deletions
diff --git a/pkgs/tools/graphics/astc-encoder/default.nix b/pkgs/tools/graphics/astc-encoder/default.nix
new file mode 100644
index 00000000000..859d6f1eee0
--- /dev/null
+++ b/pkgs/tools/graphics/astc-encoder/default.nix
@@ -0,0 +1,71 @@
+{ lib
+, gccStdenv
+, fetchFromGitHub
+, cmake
+, simdExtensions ? null
+}:
+
+with rec {
+  # SIMD instruction sets to compile for. If none are specified by the user,
+  # an appropriate one is selected based on the detected host system
+  isas = with gccStdenv.hostPlatform;
+    if simdExtensions != null then lib.toList simdExtensions
+    else if avx2Support then [ "AVX2" ]
+    else if sse4_1Support then [ "SSE41" ]
+    else if isx86_64 then [ "SSE2" ]
+    else if isAarch64 then [ "NEON" ]
+    else [ "NONE" ];
+
+  archFlags = lib.optionals gccStdenv.hostPlatform.isAarch64 [ "-DARCH=aarch64" ];
+
+  # CMake Build flags for the selected ISAs. For a list of flags, see
+  # https://github.com/ARM-software/astc-encoder/blob/main/Docs/Building.md
+  isaFlags = map ( isa: "-DISA_${isa}=ON" ) isas;
+
+  # The suffix of the binary to link as 'astcenc'
+  mainBinary = builtins.replaceStrings
+    [ "AVX2" "SSE41"  "SSE2" "NEON" "NONE" ]
+    [ "avx2" "sse4.1" "sse2" "neon" "none" ]
+    ( builtins.head isas );
+};
+
+gccStdenv.mkDerivation rec {
+  pname = "astc-encoder";
+  version = "2.5";
+
+  src = fetchFromGitHub {
+    owner = "ARM-software";
+    repo = "astc-encoder";
+    rev = version;
+    sha256 = "0ff5jh40w942dz7hmgvznmpa9yhr1j4i9qqj5wy6icm2jb9j4pak";
+  };
+
+  nativeBuildInputs = [ cmake ];
+
+  cmakeFlags = isaFlags ++ archFlags ++ [
+    "-DCMAKE_BUILD_TYPE=Release"
+  ];
+
+  # Link binaries into environment and provide 'astcenc' link
+  postInstall = ''
+    mv $out/astcenc $out/bin
+    ln -s $out/bin/astcenc-${mainBinary} $out/bin/astcenc
+  '';
+
+  meta = with lib; {
+    homepage = "https://github.com/ARM-software/astc-encoder";
+    description = "An encoder for the ASTC texture compression format";
+    longDescription = ''
+      The Adaptive Scalable Texture Compression (ASTC) format is
+      widely supported by mobile and desktop graphics hardware and
+      provides better quality at a given bitrate compared to ETC2.
+
+      This program supports both compression and decompression in LDR
+      and HDR mode and can read various image formats. Run `astcenc
+      -help` to see all the options.
+    '';
+    platforms = platforms.unix;
+    license = licenses.asl20;
+    maintainers = with maintainers; [ dasisdormax ];
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 403ed59ba32..8ca8da2449b 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -1035,6 +1035,8 @@ in
 
   asls = callPackage ../development/tools/misc/asls { };
 
+  astc-encoder = callPackage ../tools/graphics/astc-encoder { };
+
   asymptote = callPackage ../tools/graphics/asymptote {
     texLive = texlive.combine { inherit (texlive) scheme-small epsf cm-super texinfo; };
     gsl = gsl_1;