Skip to content

Commit

Permalink
add scripts to make artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
rjodinchr committed Nov 2, 2024
1 parent 25eb742 commit b2aeffd
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
7 changes: 7 additions & 0 deletions utils/make_artifact_android_arm64.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions utils/make_artifact_android_x64.sh
Original file line number Diff line number Diff line change
@@ -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
122 changes: 122 additions & 0 deletions utils/make_artifact_functions.sh
Original file line number Diff line number Diff line change
@@ -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}"
}
7 changes: 7 additions & 0 deletions utils/make_artifact_linux_x64.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions utils/make_artifact_windows_x64.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit b2aeffd

Please sign in to comment.