From b2aeffd9dc1c8c6f1da7cc565811a81b1990ef8c Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Sat, 2 Nov 2024 18:54:30 +0100 Subject: [PATCH] add scripts to make artifacts --- utils/make_artifact_android_arm64.sh | 7 ++ utils/make_artifact_android_x64.sh | 7 ++ utils/make_artifact_functions.sh | 122 +++++++++++++++++++++++++++ utils/make_artifact_linux_x64.sh | 7 ++ utils/make_artifact_windows_x64.sh | 7 ++ 5 files changed, 150 insertions(+) create mode 100644 utils/make_artifact_android_arm64.sh create mode 100644 utils/make_artifact_android_x64.sh create mode 100644 utils/make_artifact_functions.sh create mode 100644 utils/make_artifact_linux_x64.sh create mode 100644 utils/make_artifact_windows_x64.sh diff --git a/utils/make_artifact_android_arm64.sh b/utils/make_artifact_android_arm64.sh new file mode 100644 index 000000000..988fcc826 --- /dev/null +++ b/utils/make_artifact_android_arm64.sh @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +set -x + +SCRIPT_DIR="$(dirname $(realpath "${BASH_SOURCE[0]}"))" +source "${SCRIPT_DIR}/make_artifact_functions.sh" +make_android "Linux-X64" clang++ clang arm64-v8a diff --git a/utils/make_artifact_android_x64.sh b/utils/make_artifact_android_x64.sh new file mode 100644 index 000000000..d95719a12 --- /dev/null +++ b/utils/make_artifact_android_x64.sh @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +set -x + +SCRIPT_DIR="$(dirname $(realpath "${BASH_SOURCE[0]}"))" +source "${SCRIPT_DIR}/make_artifact_functions.sh" +make_android "Linux-X64" clang++ clang x86_64 diff --git a/utils/make_artifact_functions.sh b/utils/make_artifact_functions.sh new file mode 100644 index 000000000..45f2d3dc9 --- /dev/null +++ b/utils/make_artifact_functions.sh @@ -0,0 +1,122 @@ +#!/usr/bin/bash + +set -xe + +CLSPV_ROOT="$(dirname $(realpath "${BASH_SOURCE[0]}"))/.." +NDK_NAME="android-ndk-r27c" +LIBCLC_BUILD_FOLDER="build_libclc" +CLSPV_BUILD_FOLDER="build_clspv" +LLVM_VERSION="19.1.3" + +setup_folder() { + [ $# -eq 1 ] + local BUILD_FOLDER="$1" + mkdir "${BUILD_FOLDER}" + cd "${BUILD_FOLDER}" +} + +download_ndk() { + local NDK_ZIP="${NDK_NAME}-linux.zip" + curl -L "https://dl.google.com/android/repository/${NDK_ZIP}" \ + --output "${NDK_ZIP}" + unzip -q "${NDK_ZIP}" + rm -rf "${NDK_ZIP}" +} + +download_llvm() { + [ $# -eq 1 ] + local LLVM_ARCHIVE_NAME="$1" + curl -L "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/${LLVM_ARCHIVE_NAME}.tar.xz" \ + --output "${LLVM_ARCHIVE_NAME}.tar.xz" + tar -xf "${LLVM_ARCHIVE_NAME}.tar.xz" + rm -rf "${LLVM_ARCHIVE_NAME}.tar.xz" +} + +cmake_configure() { + [ $# -ge 1 ] + local ARCHIVE_NAME="$1" + shift + + cmake -B "${CLSPV_BUILD_FOLDER}" -S "${CLSPV_ROOT}" -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="${ARCHIVE_NAME}" \ + -DCMAKE_CXX_FLAGS="-fuse-ld=lld -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-deprecated-declarations" \ + $@ +} + +make_archive() { + [ $# -ge 1 ] + local ARCHIVE_NAME_SUFFIX="$1" + shift + + local ARCHIVE_NAME="clspv-$(git rev-parse --short origin/main)-${ARCHIVE_NAME_SUFFIX}" + + cmake_configure "${ARCHIVE_NAME}" $@ + cmake --build "${CLSPV_BUILD_FOLDER}" --config Release + cmake --install "${CLSPV_BUILD_FOLDER}" --config Release + + cmake_configure "${ARCHIVE_NAME}" "-DCLSPV_SHARED_LIB=1" $@ + cmake --build "${CLSPV_BUILD_FOLDER}" --config Release --target clspv_core + cmake --install "${CLSPV_BUILD_FOLDER}" --config Release + + zip -r "${ARCHIVE_NAME}.zip" "${ARCHIVE_NAME}" +} + +make_libclc() { + [ $# -eq 3 ] + local LLVM_ARCHIVE_NAME="$1" + local CLANGXX_BINARY="$2" + local CLANG_BINARY="$3" + cmake -B "${LIBCLC_BUILD_FOLDER}" -S "${CLSPV_ROOT}/third_party/llvm/libclc" -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_CMAKE_DIR="$(pwd)/${LLVM_ARCHIVE_NAME}/lib/cmake" \ + -DCMAKE_C_COMPILER="$(pwd)/${LLVM_ARCHIVE_NAME}/bin/${CLANG_BINARY}" \ + -DCMAKE_CXX_COMPILER="$(pwd)/${LLVM_ARCHIVE_NAME}/bin/${CLANGXX_BINARY}" \ + -DCMAKE_CXX_FLAGS="-fuse-ld=lld" \ + -DLIBCLC_TARGETS_TO_BUILD="clspv--;clspv64--" + cmake --build "${LIBCLC_BUILD_FOLDER}" --config Release +} + +llvm_archive_name() { + [ $# -eq 1 ] + local DISTRO="$1" + + echo "LLVM-${LLVM_VERSION}-${DISTRO}" +} + +make_native() { + [ $# -ge 3 ] + local DISTRO="$1" + local CLANGXX_BINARY="$2" + local CLANG_BINARY="$3" + shift 3 + + local LLVM_ARCHIVE_NAME="$(llvm_archive_name ${DISTRO})" + + setup_folder "build-artifact-${DISTRO}" + download_llvm "${LLVM_ARCHIVE_NAME}" + make_archive "${DISTRO}" \ + "-DCMAKE_C_COMPILER=$(pwd)/${LLVM_ARCHIVE_NAME}/bin/${CLANG_BINARY}" \ + "-DCMAKE_CXX_COMPILER=$(pwd)/${LLVM_ARCHIVE_NAME}/bin/${CLANGXX_BINARY}" \ + $@ +} + +make_android() { + [ $# -eq 4 ] + local DISTRO="$1" + local CLANGXX_BINARY="$2" + local CLANG_BINARY="$3" + local ANDROID_ABI="$4" + + local LLVM_ARCHIVE_NAME="$(llvm_archive_name ${DISTRO})" + local ARCHIVE_NAME_SUFFIX="Android-${ANDROID_ABI}" + + setup_folder "build-artifact-${ARCHIVE_NAME_SUFFIX}" + download_llvm "${LLVM_ARCHIVE_NAME}" + download_ndk + make_libclc "${LLVM_ARCHIVE_NAME}" "${CLANGXX_BINARY}" "${CLANG_BINARY}" + make_archive "${ARCHIVE_NAME_SUFFIX}" \ + "-DCMAKE_TOOLCHAIN_FILE=$(pwd)/${NDK_NAME}/build/cmake/android.toolchain.cmake" \ + "-DANDROID_ABI=${ANDROID_ABI}" \ + "-DCLSPV_EXTERNAL_LIBCLC_DIR=$(pwd)/${LIBCLC_BUILD_FOLDER}" +} diff --git a/utils/make_artifact_linux_x64.sh b/utils/make_artifact_linux_x64.sh new file mode 100644 index 000000000..d840cc71c --- /dev/null +++ b/utils/make_artifact_linux_x64.sh @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +set -x + +SCRIPT_DIR="$(dirname $(realpath "${BASH_SOURCE[0]}"))" +source "${SCRIPT_DIR}/make_artifact_functions.sh" +make_native "Linux-X64" clang++ clang diff --git a/utils/make_artifact_windows_x64.sh b/utils/make_artifact_windows_x64.sh new file mode 100644 index 000000000..ca4f04d7f --- /dev/null +++ b/utils/make_artifact_windows_x64.sh @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +set -x + +SCRIPT_DIR="$(dirname $(realpath "${BASH_SOURCE[0]}"))" +source "${SCRIPT_DIR}/make_artifact_functions.sh" +make_native "Windows-X64" clang++.exe clang.exe "-DLLVM_HOST_TRIPLE=x86_64-w64-windows-gnu"