Explorar o código

Script updates for astc-encoder-3.2 on Linux aarch64 (ARM64) (#187)

* Update build scripts for astc encoder (for Linux)

- Dockerize build to make sure ubuntu 20.04 is the base (for linux)
- Use direct cmake sources for linux x86 and aarch64 separately rather than a template
- Bump rev to rev3 (for linux)
- Update build arguments for aarch64 to enable NEON
* Fix target static lib name for aarch64

Signed-off-by: Steve Pham <[email protected]>
Steve Pham %!s(int64=2) %!d(string=hai) anos
pai
achega
4da7f4e5ee

+ 44 - 0
package-system/astc-encoder/Dockerfile

@@ -0,0 +1,44 @@
+
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+
+# This docker file uses ubuntu 20.04 as the base image so that the AWS Native C++ libraries will use OpenSSL 3 as the base
+# for its dependencies
+#
+
+FROM public.ecr.aws/ubuntu/ubuntu:20.04_stable
+ 
+WORKDIR /data/workspace
+
+ARG DOCKER_BUILD_SCRIPT
+
+# Initilize apt cache
+RUN apt-get clean && apt-get update
+
+# Setup time zone and locale data (necessary for SSL and HTTPS packages)
+RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata locales keyboard-configuration
+
+RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
+    dpkg-reconfigure --frontend=noninteractive locales && \
+    update-locale LANG=en_US.UTF-8
+
+ENV LANG=en_US.UTF-8
+
+# Install the development packages needed to build Qt from source
+RUN apt-get install -y build-essential \
+                       cmake \
+                       ninja-build
+
+RUN apt upgrade -y
+
+# Prepare a target folder within the container to install the build artifacts tp
+RUN mkdir -p /data/workspace/build
+
+ARG CACHEBUST=1
+
+# Copy the build script specific to this Docker script in order to execute the build
+COPY ${DOCKER_BUILD_SCRIPT} /data/workspace/
+

+ 32 - 0
package-system/astc-encoder/Findastc-encoder.cmake.linux-aarch64

@@ -0,0 +1,32 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
+# 
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+
+# this file actually ingests the library and defines targets.
+
+
+set(LIB_NAME "astc-encoder")
+set(TARGET_WITH_NAMESPACE "3rdParty::${LIB_NAME}")
+
+set(${LIB_NAME}_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}/include)
+set(${LIB_NAME}_LIBRARY_DIR ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}/bin)
+
+set(${LIB_NAME}_LIBRARY_RELEASE ${${LIB_NAME}_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}astcenc-neon-static${CMAKE_STATIC_LIBRARY_SUFFIX})
+set(${LIB_NAME}_LIBRARY_DEBUG ${${LIB_NAME}_LIBRARY_RELEASE})
+
+# declare the target so that others can 'depend on it'
+add_library(${TARGET_WITH_NAMESPACE} STATIC IMPORTED GLOBAL)
+
+# add include directory
+ly_target_include_system_directories(TARGET ${TARGET_WITH_NAMESPACE} INTERFACE ${${LIB_NAME}_INCLUDE_DIR})
+
+# add static library as "output" IMPORTED_LOCATION for the target
+set_target_properties(${TARGET_WITH_NAMESPACE}
+    PROPERTIES
+        IMPORTED_LOCATION_DEBUG ${${LIB_NAME}_LIBRARY_DEBUG}
+        IMPORTED_LOCATION ${${LIB_NAME}_LIBRARY_RELEASE}
+)
+
+set(${LIB_NAME}_FOUND True)

+ 32 - 0
package-system/astc-encoder/Findastc-encoder.cmake.linux-x86_64

@@ -0,0 +1,32 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
+# 
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+
+# this file actually ingests the library and defines targets.
+
+
+set(LIB_NAME "astc-encoder")
+set(TARGET_WITH_NAMESPACE "3rdParty::${LIB_NAME}")
+
+set(${LIB_NAME}_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}/include)
+set(${LIB_NAME}_LIBRARY_DIR ${CMAKE_CURRENT_LIST_DIR}/${LIB_NAME}/bin)
+
+set(${LIB_NAME}_LIBRARY_RELEASE ${${LIB_NAME}_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}astcenc-sse4.1-static${CMAKE_STATIC_LIBRARY_SUFFIX})
+set(${LIB_NAME}_LIBRARY_DEBUG ${${LIB_NAME}_LIBRARY_RELEASE})
+
+# declare the target so that others can 'depend on it'
+add_library(${TARGET_WITH_NAMESPACE} STATIC IMPORTED GLOBAL)
+
+# add include directory
+ly_target_include_system_directories(TARGET ${TARGET_WITH_NAMESPACE} INTERFACE ${${LIB_NAME}_INCLUDE_DIR})
+
+# add static library as "output" IMPORTED_LOCATION for the target
+set_target_properties(${TARGET_WITH_NAMESPACE}
+    PROPERTIES
+        IMPORTED_LOCATION_DEBUG ${${LIB_NAME}_LIBRARY_DEBUG}
+        IMPORTED_LOCATION ${${LIB_NAME}_LIBRARY_RELEASE}
+)
+
+set(${LIB_NAME}_FOUND True)

+ 98 - 0
package-system/astc-encoder/build-linux.sh

@@ -0,0 +1,98 @@
+#!/bin/bash
+
+#
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+
+# TEMP_FOLDER and TARGET_INSTALL_ROOT get set from the pull_and_build_from_git.py script
+
+# Make sure docker is installed
+DOCKER_VERSION=$(docker --version)
+if [ $? -ne 0 ]
+then
+    echo "Required package docker is not installed"
+    echo "Follow instructions on https://docs.docker.com/engine/install/ubuntu/ to install docker properly"
+    exit 1
+fi
+echo "Detected Docker Version $DOCKER_VERSION"
+
+DOCKER_BUILD_SCRIPT=docker_build_astcencoder_linux.sh
+DOCKER_IMAGE_NAME=astcencoder_linux_3p
+
+if [ ! -f $DOCKER_BUILD_SCRIPT ]
+then
+    echo "Invalid docker build script ${DOCKER_BUILD_SCRIPT}"
+    exit 1
+fi
+
+# Prepare the docker file and use the temp folder as the context root
+cp -f ${DOCKER_BUILD_SCRIPT} temp/
+
+pushd temp
+
+# Build the Docker Image
+echo "Building the docker build script for ${DOCKER_IMAGE_NAME}"
+
+docker build --build-arg DOCKER_BUILD_SCRIPT=$DOCKER_BUILD_SCRIPT -f ../Dockerfile -t ${DOCKER_IMAGE_NAME}:latest . 
+if [ $? -ne 0 ]
+then
+    echo "Error occurred creating Docker image ${DOCKER_IMAGE_NAME}:latest." 
+    exit 1
+fi
+
+
+# Capture the Docker Image ID
+IMAGE_ID=$(docker images -q ${DOCKER_IMAGE_NAME}:latest)
+if [ -z $IMAGE_ID ]
+then
+    echo "Error: Cannot find Image ID for ${DOCKER_IMAGE_NAME}"
+    exit 1
+fi
+
+
+# Run the Docker Image
+echo "Running build script in the docker image"
+docker run -v $TEMP_FOLDER/src:/data/workspace/src --tty ${DOCKER_IMAGE_NAME}:latest /data/workspace/${DOCKER_BUILD_SCRIPT}
+if [ $? -ne 0 ]
+then
+    echo Failed to build from docker image ${DOCKER_IMAGE_NAME}:latest
+    exit 1
+fi
+
+
+# Capture the container ID
+echo "Capturing the Container ID"
+CONTAINER_ID=$(docker container ls -l -q --filter "ancestor=${DOCKER_IMAGE_NAME}:latest")
+if [ -z $CONTAINER_ID ]
+then
+    echo "Error: Cannot find Container ID for Image ${DOCKER_IMAGE_NAME}"
+    exit 1
+fi
+
+
+# Copy the build artifacts from the Docker Container
+echo "Copying the built contents from the docker container for image ${DOCKER_IMAGE_NAME}"
+
+mkdir -p build
+docker  cp --quiet $CONTAINER_ID:/data/workspace/build/. build  
+if [ $? -ne 0 ]
+then
+    echo "Error occurred copying build artifacts from Docker image ${DOCKER_IMAGE_NAME}:latest." 
+    exit 1
+fi
+
+
+# Clean up the docker image and container
+echo "Cleaning up container"
+docker container rm $CONTAINER_ID || (echo "Warning: unable to clean up container for image ${DOCKER_IMAGE_NAME}")
+
+echo "Cleaning up image"
+docker rmi --force $IMAGE_ID  || (echo "Warning: unable to clean up image ${DOCKER_IMAGE_NAME}")
+
+popd
+
+exit 0
+

+ 14 - 4
package-system/astc-encoder/build_config.json

@@ -2,16 +2,16 @@
     "git_url": "https://github.com/ARM-software/astc-encoder.git",
     "git_url": "https://github.com/ARM-software/astc-encoder.git",
     "git_tag": "3.2",
     "git_tag": "3.2",
     "package_name": "astc-encoder",
     "package_name": "astc-encoder",
-    "package_version": "3.2-rev2",
+    "package_version": "3.2-rev3",
     "package_url": "https://github.com/ARM-software/astc-encoder",
     "package_url": "https://github.com/ARM-software/astc-encoder",
     "package_license": "Apache-2.0",
     "package_license": "Apache-2.0",
     "package_license_file": "LICENSE.txt",
     "package_license_file": "LICENSE.txt",
-    "cmake_find_template": "Findastc-encoder.cmake.template",
     "cmake_find_target": "Findastc-encoder.cmake",
     "cmake_find_target": "Findastc-encoder.cmake",
     "patch_file": "astcencoder-o3de.patch",
     "patch_file": "astcencoder-o3de.patch",
     "Platforms": {
     "Platforms": {
         "Windows": {
         "Windows": {
             "Windows": {
             "Windows": {
+                "cmake_find_template": "Findastc-encoder.cmake.template",
                 "custom_build_cmd": [
                 "custom_build_cmd": [
                     "build_windows.cmd"
                     "build_windows.cmd"
                 ],
                 ],
@@ -22,6 +22,7 @@
         },
         },
         "Darwin": {
         "Darwin": {
             "Mac": {
             "Mac": {
+                "cmake_find_template": "Findastc-encoder.cmake.template",
                 "package_version": "3.2-rev5",
                 "package_version": "3.2-rev5",
                 "custom_build_cmd": [
                 "custom_build_cmd": [
                     "./build_mac.sh"
                     "./build_mac.sh"
@@ -33,14 +34,23 @@
         },
         },
         "Linux": {
         "Linux": {
             "Linux": {
             "Linux": {
+                "cmake_find_source": "Findastc-encoder.cmake.linux-x86_64",
                 "custom_build_cmd": [
                 "custom_build_cmd": [
-                    "./build_linux.sh"
+                    "./build-linux.sh"
                 ],
                 ],
                 "custom_install_cmd": [
                 "custom_install_cmd": [
                     "./install_linux.sh"
                     "./install_linux.sh"
                 ]
                 ]
             },
             },
-	    "Linux-aarch64": "@Linux"
+	    "Linux-aarch64": {
+		"cmake_find_source": "Findastc-encoder.cmake.linux-aarch64",
+                "custom_build_cmd": [
+                    "./build-linux.sh"
+                ],
+                "custom_install_cmd": [
+                    "./install_linux.sh"
+                ]
+	    }
         }
         }
     }
     }
 }
 }

+ 36 - 0
package-system/astc-encoder/docker_build_astcencoder_linux.sh

@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+
+CPU_ARCHITECTURE=$(lscpu | grep Architecture | awk '{print $2}')
+if [ "$CPU_ARCHITECTURE" = "x86_64" ]
+then
+    # On x86/x64 platforms, O3DE requires requirest SSE 4.1
+    cmake -S src -B build -G "Unix Makefiles" \
+        -DCMAKE_BUILD_TYPE=Release \
+        -DISA_SSE41=ON 
+
+elif [ "$CPU_ARCHITECTURE" = "aarch64" ]
+then
+    # On aarch64 architectures, O3DE requires NEON simd support
+    cmake -S src -B build -G "Unix Makefiles" \
+        -DCMAKE_BUILD_TYPE=Release \
+        -DISA_NEON=ON 
+fi
+
+if [ $? -ne 0 ]
+then
+    echo "Failed to generate build for astc encoder for Linux"
+    exit 1
+fi
+
+cmake --build build
+if [ $? -ne 0 ]
+then
+    echo "Failed to build astc encoder for Linux"
+    exit 1
+fi
+

+ 2 - 2
package-system/astc-encoder/install_linux.sh

@@ -25,8 +25,8 @@ then
     cp -f $BUILD_PATH/libastcenc-sse4.1-static.a $BIN_PATH/ || exit $?
     cp -f $BUILD_PATH/libastcenc-sse4.1-static.a $BIN_PATH/ || exit $?
 elif [ "$CPU_ARCHITECTURE" = "aarch64" ]
 elif [ "$CPU_ARCHITECTURE" = "aarch64" ]
 then
 then
-    cp -f $BUILD_PATH/astcenc-native $BIN_PATH/ || exit $?
-    cp -f $BUILD_PATH/libastcenc-native-static.a $BIN_PATH/ || exit $?
+    cp -f $BUILD_PATH/astcenc-neon $BIN_PATH/ || exit $?
+    cp -f $BUILD_PATH/libastcenc-neon-static.a $BIN_PATH/ || exit $?
 
 
 fi
 fi
 
 

+ 2 - 2
package_build_list_host_linux-aarch64.json

@@ -5,7 +5,7 @@
     "comment4" : "Note:  Build from source occurs before build_from_folder",
     "comment4" : "Note:  Build from source occurs before build_from_folder",
     "build_from_source": {
     "build_from_source": {
         "assimp-5.2.5-rev1-linux-aarch64":  "Scripts/extras/pull_and_build_from_git.py ../../package-system/assimp --platform-name Linux-aarch64 --clean",
         "assimp-5.2.5-rev1-linux-aarch64":  "Scripts/extras/pull_and_build_from_git.py ../../package-system/assimp --platform-name Linux-aarch64 --clean",
-        "astc-encoder-3.2-rev2-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/astc-encoder --platform-name Linux-aarch64 --clean",
+        "astc-encoder-3.2-rev3-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/astc-encoder --platform-name Linux-aarch64 --clean",
         "AWSGameLiftServerSDK-3.4.2-rev1-linux-aarch64": "package-system/AWSGameLiftServerSDK/build_package_image.py --platform-name linux-aarch64",
         "AWSGameLiftServerSDK-3.4.2-rev1-linux-aarch64": "package-system/AWSGameLiftServerSDK/build_package_image.py --platform-name linux-aarch64",
         "AwsIotDeviceSdkCpp-1.15.2-rev1-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/AwsIotDeviceSdkCpp --platform-name Linux-aarch64 --clean",
         "AwsIotDeviceSdkCpp-1.15.2-rev1-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/AwsIotDeviceSdkCpp --platform-name Linux-aarch64 --clean",
         "AWSNativeSDK-1.9.50-rev2-linux-openssl-1-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/AWSNativeSDK --platform-name Linux-OpenSSL-1-aarch64 --clean",
         "AWSNativeSDK-1.9.50-rev2-linux-openssl-1-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/AWSNativeSDK --platform-name Linux-OpenSSL-1-aarch64 --clean",
@@ -43,7 +43,7 @@
     },
     },
     "build_from_folder": {
     "build_from_folder": {
         "assimp-5.2.5-rev1-linux-aarch64": "package-system/assimp/temp/assimp-linux-aarch64",
         "assimp-5.2.5-rev1-linux-aarch64": "package-system/assimp/temp/assimp-linux-aarch64",
-        "astc-encoder-3.2-rev2-linux-aarch64": "package-system/astc-encoder/temp/astc-encoder-linux-aarch64",
+        "astc-encoder-3.2-rev3-linux-aarch64": "package-system/astc-encoder/temp/astc-encoder-linux-aarch64",
         "AWSGameLiftServerSDK-3.4.2-rev1-linux-aarch64": "package-system/AWSGameLiftServerSDK-linux-aarch64",
         "AWSGameLiftServerSDK-3.4.2-rev1-linux-aarch64": "package-system/AWSGameLiftServerSDK-linux-aarch64",
         "AwsIotDeviceSdkCpp-1.15.2-rev1-linux-aarch64": "package-system/AwsIotDeviceSdkCpp/temp/AwsIotDeviceSdkCpp-linux-aarch64",
         "AwsIotDeviceSdkCpp-1.15.2-rev1-linux-aarch64": "package-system/AwsIotDeviceSdkCpp/temp/AwsIotDeviceSdkCpp-linux-aarch64",
         "AWSNativeSDK-1.9.50-rev2-linux-openssl-1-aarch64": "package-system/AWSNativeSDK/temp/AWSNativeSDK-linux-openssl-1-aarch64",
         "AWSNativeSDK-1.9.50-rev2-linux-openssl-1-aarch64": "package-system/AWSNativeSDK/temp/AWSNativeSDK-linux-openssl-1-aarch64",

+ 2 - 2
package_build_list_host_linux.json

@@ -31,7 +31,7 @@
         "SPIRVCross-2021.04.29-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/SPIRVCross --platform-name Linux --package-root ../../package-system --clean",
         "SPIRVCross-2021.04.29-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/SPIRVCross --platform-name Linux --package-root ../../package-system --clean",
         "SQLite-3.37.2-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/sqlite --platform-name Linux --package-root ../../package-system --clean",
         "SQLite-3.37.2-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/sqlite --platform-name Linux --package-root ../../package-system --clean",
         "squish-ccr-deb557d-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/squish-ccr --platform-name Linux --package-root ../../package-system --clean",
         "squish-ccr-deb557d-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/squish-ccr --platform-name Linux --package-root ../../package-system --clean",
-        "astc-encoder-3.2-rev2-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/astc-encoder --platform-name Linux --package-root ../../package-system --clean",
+        "astc-encoder-3.2-rev3-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/astc-encoder --platform-name Linux --package-root ../../package-system --clean",
         "DirectXShaderCompilerDxc-1.6.2112-o3de-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/DirectXShaderCompiler --platform-name Linux --package-root ../../package-system --clean",
         "DirectXShaderCompilerDxc-1.6.2112-o3de-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/DirectXShaderCompiler --platform-name Linux --package-root ../../package-system --clean",
         "azslc-1.8.15-rev2-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/azslc --platform-name Linux --package-root ../../package-system/azslc/temp --clean",
         "azslc-1.8.15-rev2-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/azslc --platform-name Linux --package-root ../../package-system/azslc/temp --clean",
         "tiff-4.2.0.15-rev3-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/tiff --platform-name Linux --package-root ../../package-system --clean",
         "tiff-4.2.0.15-rev3-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/tiff --platform-name Linux --package-root ../../package-system --clean",
@@ -65,7 +65,7 @@
         "openimageio-opencolorio-2.3.17-rev2-linux": "package-system/openimageio-opencolorio/temp/package-linux",
         "openimageio-opencolorio-2.3.17-rev2-linux": "package-system/openimageio-opencolorio/temp/package-linux",
         "SPIRVCross-2021.04.29-rev1-linux": "package-system/SPIRVCross-linux",
         "SPIRVCross-2021.04.29-rev1-linux": "package-system/SPIRVCross-linux",
         "squish-ccr-deb557d-rev1-linux": "package-system/squish-ccr-linux",
         "squish-ccr-deb557d-rev1-linux": "package-system/squish-ccr-linux",
-        "astc-encoder-3.2-rev2-linux": "package-system/astc-encoder-linux",
+        "astc-encoder-3.2-rev3-linux": "package-system/astc-encoder-linux",
         "DirectXShaderCompilerDxc-1.6.2112-o3de-rev1-linux": "package-system/DirectXShaderCompilerDxc-linux",
         "DirectXShaderCompilerDxc-1.6.2112-o3de-rev1-linux": "package-system/DirectXShaderCompilerDxc-linux",
         "azslc-1.8.15-rev2-linux": "package-system/azslc/temp/azslc-linux",
         "azslc-1.8.15-rev2-linux": "package-system/azslc/temp/azslc-linux",
         "tiff-4.2.0.15-rev3-linux": "package-system/tiff-linux",
         "tiff-4.2.0.15-rev3-linux": "package-system/tiff-linux",