Repository: NVIDIA/hpc-container-maker

Issue:
Allow use of CMake binary package for aarch64
Currently you are forced to compile CMake from source for any architecture other than x86_64. I'm having some issues getting cmake to compile for one of my recipes which I could avoid by using the pre-compiled binaries. aarch64 binaries have been available since 3.20.0 release as far as I can tell. Installation procedure is the same as x86_64 in my experience.

Discussion:
samcmill: @NVrgaletto 
NVrgaletto: Exactly what I wanted. Thanks!

Patch:
diff --git a/docs/building_blocks.md b/docs/building_blocks.md
index d89cd70..db58f55 100644
--- a/docs/building_blocks.md
+++ b/docs/building_blocks.md
@@ -545,12 +545,12 @@ The default values are `make` and `wget`.
 - __source__: Boolean flag to specify whether to build CMake from
 source.  If True, includes the `libssl-dev` package in the list of
 OS packages for Ubuntu, and `openssl-devel` for RHEL-based
-distributions.  For x86_64 processors, the default is False, i.e.,
-use the available pre-compiled package.  For all other processors,
-the default is True.
+distributions.  For x86_64 and aarch64 processors, the default is
+False, i.e., use the available pre-compiled package.  For all
+other processors, the default is True.
 
 - __version__: The version of CMake to download.  The default value is
-`3.22.2`.
+`3.25.1`.
 
 __Examples__
 
diff --git a/hpccm/building_blocks/cmake.py b/hpccm/building_blocks/cmake.py
index 98188d1..7d6eb92 100644
--- a/hpccm/building_blocks/cmake.py
+++ b/hpccm/building_blocks/cmake.py
@@ -60,12 +60,12 @@ class cmake(bb_base, hpccm.templates.rm, hpccm.templates.tar,
     source: Boolean flag to specify whether to build CMake from
     source.  If True, includes the `libssl-dev` package in the list of
     OS packages for Ubuntu, and `openssl-devel` for RHEL-based
-    distributions.  For x86_64 processors, the default is False, i.e.,
-    use the available pre-compiled package.  For all other processors,
-    the default is True.
+    distributions.  For x86_64 and aarch64 processors, the default is
+    False, i.e., use the available pre-compiled package.  For all
+    other processors, the default is True.
 
     version: The version of CMake to download.  The default value is
-    `3.22.2`.
+    `3.25.1`.
 
     # Examples
 
@@ -96,7 +96,7 @@ class cmake(bb_base, hpccm.templates.rm, hpccm.templates.tar,
         self.__parallel = kwargs.get('parallel', '$(nproc)')
         self.__prefix = kwargs.get('prefix', '/usr/local')
         self.__source = kwargs.get('source', False)
-        self.__version = kwargs.get('version', '3.22.2')
+        self.__version = kwargs.get('version', '3.25.1')
 
         self.__commands = [] # Filled in by __setup()
         self.__wd = kwargs.get('wd', hpccm.config.g_wd) # working directory
@@ -122,6 +122,9 @@ class cmake(bb_base, hpccm.templates.rm, hpccm.templates.tar,
         if not self.__source and hpccm.config.g_cpu_arch == cpu_arch.X86_64:
             # Use the pre-compiled x86_64 binary
             self.__binary()
+        elif not self.__source and hpccm.config.g_cpu_arch == cpu_arch.AARCH64 and LooseVersion(self.__version) >= LooseVersion('3.20'):
+            # Use the pre-compiled aarch64 binary
+            self.__binary()
         else:
             # Build from source
             self.__build()
@@ -130,7 +133,9 @@ class cmake(bb_base, hpccm.templates.rm, hpccm.templates.tar,
         """Install the pre-compiled binary"""
 
         runfile = 'cmake-{}-linux-x86_64.sh'
-        if LooseVersion(self.__version) < LooseVersion('3.20'):
+        if hpccm.config.g_cpu_arch == cpu_arch.AARCH64:
+            runfile = 'cmake-{}-linux-aarch64.sh'
+        elif hpccm.config.g_cpu_arch == cpu_arch.X86_64 and LooseVersion(self.__version) < LooseVersion('3.20'):
             runfile = 'cmake-{}-Linux-x86_64.sh'
 
         runfile = runfile.format(self.__version)


Test patch:
diff --git a/test/test_cmake.py b/test/test_cmake.py
index 2724e4d..fe0ff3f 100644
--- a/test/test_cmake.py
+++ b/test/test_cmake.py
@@ -38,16 +38,16 @@ class Test_cmake(unittest.TestCase):
         """Default cmake building block"""
         c = cmake()
         self.assertEqual(str(c),
-r'''# CMake version 3.22.2
+r'''# CMake version 3.25.1
 RUN apt-get update -y && \
     DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
         make \
         wget && \
     rm -rf /var/lib/apt/lists/*
-RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.22.2/cmake-3.22.2-linux-x86_64.sh && \
+RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-x86_64.sh && \
     mkdir -p /usr/local && \
-    /bin/sh /var/tmp/cmake-3.22.2-linux-x86_64.sh --prefix=/usr/local && \
-    rm -rf /var/tmp/cmake-3.22.2-linux-x86_64.sh
+    /bin/sh /var/tmp/cmake-3.25.1-linux-x86_64.sh --prefix=/usr/local && \
+    rm -rf /var/tmp/cmake-3.25.1-linux-x86_64.sh
 ENV PATH=/usr/local/bin:$PATH''')
 
     @x86_64
@@ -57,22 +57,22 @@ ENV PATH=/usr/local/bin:$PATH''')
         """Default cmake building block"""
         c = cmake()
         self.assertEqual(str(c),
-r'''# CMake version 3.22.2
+r'''# CMake version 3.25.1
 RUN yum install -y \
         make \
         wget && \
     rm -rf /var/cache/yum/*
-RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.22.2/cmake-3.22.2-linux-x86_64.sh && \
+RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-x86_64.sh && \
     mkdir -p /usr/local && \
-    /bin/sh /var/tmp/cmake-3.22.2-linux-x86_64.sh --prefix=/usr/local && \
-    rm -rf /var/tmp/cmake-3.22.2-linux-x86_64.sh
+    /bin/sh /var/tmp/cmake-3.25.1-linux-x86_64.sh --prefix=/usr/local && \
+    rm -rf /var/tmp/cmake-3.25.1-linux-x86_64.sh
 ENV PATH=/usr/local/bin:$PATH''')
 
     @x86_64
     @ubuntu
     @docker
-    def test_eula(self):
-        """3.20 binary naming"""
+    def test_runfile_name(self):
+        """3.20 runfile naming"""
         c = cmake(version='3.20.0')
         self.assertEqual(str(c),
 r'''# CMake version 3.20.0
@@ -128,7 +128,7 @@ ENV PATH=/usr/local/bin:$PATH''')
     @x86_64
     @ubuntu
     @docker
-    def test_defaults_ubuntu(self):
+    def test_32bit_ubuntu(self):
         """Cmake building block for old 32-bit versions"""
         c = cmake(eula=True, version='3.0.0')
         self.assertEqual(str(c),
@@ -148,7 +148,7 @@ ENV PATH=/usr/local/bin:$PATH''')
     @x86_64
     @centos
     @docker
-    def test_defaults_ubuntu(self):
+    def test_32bit_centos(self):
         """Cmake building block for old 32-bit versions"""
         c = cmake(eula=True, version='3.0.0')
         self.assertEqual(str(c),
@@ -205,3 +205,21 @@ RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://
     make install && \
     rm -rf /var/tmp/cmake-3.14.5.tar.gz /var/tmp/cmake-3.14.5
 ENV PATH=/usr/local/bin:$PATH''')
+
+    @aarch64
+    @centos
+    @docker
+    def test_aarch64_binary(self):
+        """Arm binary package"""
+        c = cmake(eula=True, version='3.25.1')
+        self.assertEqual(str(c),
+r'''# CMake version 3.25.1
+RUN yum install -y \
+        make \
+        wget && \
+    rm -rf /var/cache/yum/*
+RUN mkdir -p /var/tmp && wget -q -nc --no-check-certificate -P /var/tmp https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-aarch64.sh && \
+    mkdir -p /usr/local && \
+    /bin/sh /var/tmp/cmake-3.25.1-linux-aarch64.sh --prefix=/usr/local --skip-license && \
+    rm -rf /var/tmp/cmake-3.25.1-linux-aarch64.sh
+ENV PATH=/usr/local/bin:$PATH''')