Skip to content

Commit

Permalink
Scripts to download, build and upload dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dancazarin committed Oct 28, 2024
1 parent 14fc09d commit eb87e26
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 61 deletions.
80 changes: 22 additions & 58 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ jobs:
- name: Vcpkg
shell: bash
run: |
DEP_HASH=$(cmake -P dep-hash.cmake)
DEP_HASH=${DEP_HASH:3}
echo Hash is $DEP_HASH
if ! aws s3 ls "s3://gh-bin/brisk-deps/${{matrix.triplet}}-$DEP_HASH.7z"; then
echo "Archive does not exist on S3, trying to build"
vcpkg install --x-feature=icu
vcpkg export --7zip --output-dir="${{runner.temp}}" --output="${{matrix.triplet}}-$DEP_HASH"
aws s3 cp --acl public-read "${{runner.temp}}/${{matrix.triplet}}-$DEP_HASH.7z" s3://gh-bin/brisk-deps/
else
echo "Archive does exist on S3, skipping build"
fi
cmake -P upload-deps.cmake
windows-deps:
strategy:
Expand All @@ -60,19 +50,7 @@ jobs:
uses: actions/checkout@v4
- name: Vcpkg
run: |
$DEP_HASH = & { cmake -P dep-hash.cmake }
$DEP_HASH = $DEP_HASH.Substring(3)
Write-Output "Hash is $DEP_HASH"
$S3Path = "s3://gh-bin/brisk-deps/${{matrix.triplet}}-$DEP_HASH.7z"
$S3Check = aws s3 ls $S3Path
if (-not $S3Check) {
Write-Output "Archive does not exist on S3, trying to build"
vcpkg install --x-feature=icu
vcpkg export --7zip --output-dir="${{runner.temp}}" --output="${{matrix.triplet}}-$DEP_HASH"
aws s3 cp --acl public-read "${{runner.temp}}/${{matrix.triplet}}-$DEP_HASH.7z" s3://gh-bin/brisk-deps/
} else {
Write-Output "Archive does exist on S3, skipping build"
}
cmake -P upload-deps.cmake
macos-deps:
strategy:
Expand All @@ -97,19 +75,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Vcpkg
shell: bash
run: |
DEP_HASH=$(cmake -P dep-hash.cmake)
DEP_HASH=${DEP_HASH:3}
echo Hash is $DEP_HASH
if ! aws s3 ls "s3://gh-bin/brisk-deps/${{matrix.triplet}}-$DEP_HASH.7z"; then
echo "Archive does not exist on S3, trying to build"
vcpkg install --x-feature=icu
vcpkg export --7zip --output-dir="${{runner.temp}}" --output="${{matrix.triplet}}-$DEP_HASH"
aws s3 cp --acl public-read "${{runner.temp}}/${{matrix.triplet}}-$DEP_HASH.7z" s3://gh-bin/brisk-deps/
else
echo "Archive does exist on S3, skipping build"
fi
cmake -P upload-deps.cmake
ubuntu-ninja-clang-x86_64:
runs-on: ubuntu-latest
Expand All @@ -124,9 +91,9 @@ jobs:
run: |
sudo apt-get update && sudo apt-get install -y ninja-build mesa-vulkan-drivers vulkan-tools wget xorg-dev libgl-dev libgl1-mesa-dev libvulkan-dev autoconf autoconf-archive libxrandr-dev libxinerama-dev libxcursor-dev mesa-common-dev libx11-xcb-dev
wget -O - https://apt.llvm.org/llvm.sh | sudo bash -s - 19
- name: Vcpkg
- name: Acquire dependencies
run: |
vcpkg install --x-install-root vcpkg_installed --x-feature=icu
cmake -DDEP_BUILD=OFF -P acquire-deps.cmake
- name: Configure
run: |
cmake -GNinja -S . -B build -DCMAKE_INSTALL_PREFIX=dist -DVCPKG_MANIFEST_MODE=OFF -DVCPKG_INSTALLED_DIR=vcpkg_installed -DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake -DBRISK_LOG_TO_STDERR=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_C_COMPILER=clang-19
Expand Down Expand Up @@ -154,9 +121,9 @@ jobs:
- name: Install prerequisites
run: |
sudo apt-get update && sudo apt-get install -y gcc-14 g++-14 ninja-build mesa-vulkan-drivers vulkan-tools wget xorg-dev libgl-dev libgl1-mesa-dev libvulkan-dev autoconf autoconf-archive libxrandr-dev libxinerama-dev libxcursor-dev mesa-common-dev libx11-xcb-dev
- name: Vcpkg
- name: Acquire dependencies
run: |
vcpkg install --x-install-root vcpkg_installed --x-feature=icu
cmake -DDEP_BUILD=OFF -P acquire-deps.cmake
- name: Configure
run: |
cmake -G"Unix Makefiles" -S . -B build -DCMAKE_INSTALL_PREFIX=dist -DVCPKG_MANIFEST_MODE=OFF -DVCPKG_INSTALLED_DIR=vcpkg_installed -DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake -DBRISK_LOG_TO_STDERR=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_C_COMPILER=gcc-14
Expand All @@ -178,16 +145,16 @@ jobs:
env:
VCPKG_DEFAULT_TRIPLET: x64-windows-static-md
VCPKG_DEFAULT_HOST_TRIPLET: x64-windows-static-md
LLVM_DIR: C:/Program Files/LLVM
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install prerequisites
run: |
choco install ninja --no-progress -y
- name: Vcpkg
- name: Acquire dependencies
run: |
set LLVM_DIR=C:/Program Files/LLVM
vcpkg install --x-install-root vcpkg_installed --x-feature=icu
cmake -DDEP_BUILD=OFF -P acquire-deps.cmake
- name: Configure
shell: cmd
run: |
Expand All @@ -214,9 +181,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Vcpkg
- name: Acquire dependencies
run: |
vcpkg install --x-install-root vcpkg_installed --x-feature=icu
cmake -DDEP_BUILD=OFF -P acquire-deps.cmake
- name: Configure
shell: cmd
run: |
Expand All @@ -242,9 +209,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Vcpkg
- name: Acquire dependencies
run: |
vcpkg install --x-install-root vcpkg_installed --x-feature=icu
cmake -DDEP_BUILD=OFF -P acquire-deps.cmake
- name: Configure
shell: cmd
run: |
Expand Down Expand Up @@ -274,14 +241,14 @@ jobs:
run: |
brew install ninja autoconf automake autoconf-archive
git clone /~https://github.com/microsoft/vcpkg "$HOME/vcpkg"
- name: Vcpkg
run: |
export VCPKG_ROOT="$HOME/vcpkg"
$HOME/vcpkg/bootstrap-vcpkg.sh -disableMetrics
$HOME/vcpkg/vcpkg install --x-install-root vcpkg_installed --x-feature=icu
echo "VCPKG_ROOT=$HOME/vcpkg" >> $GITHUB_ENV
echo "$HOME/vcpkg" >> "$GITHUB_PATH"
- name: Acquire dependencies
run: |
cmake -DDEP_BUILD=OFF -P acquire-deps.cmake
- name: Configure
run: |
export VCPKG_ROOT="$HOME/vcpkg"
cmake -GNinja -S . -B build -DCMAKE_INSTALL_PREFIX=dist -DVCPKG_MANIFEST_MODE=OFF -DCMAKE_OSX_ARCHITECTURES=arm64 -DVCPKG_INSTALLED_DIR=vcpkg_installed -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DBRISK_LOG_TO_STDERR=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
- name: Build
run: |
Expand All @@ -307,15 +274,12 @@ jobs:
- name: Install prerequisites
run: |
brew install ninja autoconf automake autoconf-archive
git clone /~https://github.com/microsoft/vcpkg "$HOME/vcpkg"
- name: Vcpkg
env
- name: Acquire dependencies
run: |
export VCPKG_ROOT="$HOME/vcpkg"
$HOME/vcpkg/bootstrap-vcpkg.sh -disableMetrics
$HOME/vcpkg/vcpkg install --x-install-root vcpkg_installed --x-feature=icu
cmake -DDEP_BUILD=OFF -P acquire-deps.cmake
- name: Configure
run: |
export VCPKG_ROOT="$HOME/vcpkg"
cmake -GNinja -S . -B build -DCMAKE_INSTALL_PREFIX=dist -DVCPKG_MANIFEST_MODE=OFF -DCMAKE_OSX_ARCHITECTURES=x86_64 -DVCPKG_INSTALLED_DIR=vcpkg_installed -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DBRISK_LOG_TO_STDERR=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
- name: Build
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ vcpkg
vcpkg_cache
vcpkg_exported
dist
deps-*
94 changes: 94 additions & 0 deletions acquire-deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
set(ROOT ${CMAKE_CURRENT_LIST_DIR})

set(URL https://gh-bin.fra1.digitaloceanspaces.com/brisk-deps/{TRIPLET}-{DEP_HASH}.7z)

if (DEFINED ENV{VCPKG_TARGET_TRIPLET})
set(VCPKG_TARGET_TRIPLET $ENV{VCPKG_TARGET_TRIPLET})
else ()
if (DEFINED ENV{VCPKG_DEFAULT_TRIPLET})
set(VCPKG_TARGET_TRIPLET $ENV{VCPKG_DEFAULT_TRIPLET})
else ()
message(FATAL_ERROR "Set VCPKG_TARGET_TRIPLET or VCPKG_DEFAULT_TRIPLET environment variable")
endif ()
endif ()

include(${ROOT}/dep-hash.cmake)

# Define the URL and destination file for download
string(REPLACE "{DEP_HASH}" "${DEP_HASH}" URL "${URL}")
string(REPLACE "{TRIPLET}" "${VCPKG_TARGET_TRIPLET}" URL "${URL}")
set(DEST_FILE ${ROOT}/deps-${VCPKG_TARGET_TRIPLET}-${DEP_HASH}.7z)

if (NOT EXISTS ${DEST_FILE})

message(STATUS "Downloading ${URL}")
# Download the file
file(
DOWNLOAD ${URL} ${DEST_FILE}
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS)
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_STATUS_CODE)
if (NOT DOWNLOAD_STATUS_CODE EQUAL 0)
if (DEFINED DEP_BUILD AND NOT DEP_BUILD)
message(FATAL_ERROR "Download failed (Status ${DOWNLOAD_STATUS_CODE}), exit")
endif ()
message(WARNING "Download failed, dependencies will be built using vcpkg (Status ${DOWNLOAD_STATUS_CODE})")

execute_process(
COMMAND vcpkg install --x-install-root ${ROOT}/vcpkg_installed --x-feature=icu ${EXTRA_VCPKG_ARGS}
WORKING_DIRECTORY ${ROOT}
RESULT_VARIABLE RESULT)
if (NOT RESULT EQUAL 0)
message(FATAL_ERROR "vcpkg install failed with exit code ${RESULT}")
endif ()
endif ()

file(REMOVE_RECURSE ${ROOT}/vcpkg_exported)

else ()

message(STATUS "File ${DEST_FILE} already exists. Remove it to force re-download")

endif ()

if (NOT EXISTS ${ROOT}/vcpkg_exported)

message(STATUS "Extracting archive")

# Create the vcpkg_exported directory
file(MAKE_DIRECTORY ${ROOT}/vcpkg_exported)

# Extract the archive
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xf ${DEST_FILE}
WORKING_DIRECTORY ${ROOT}/vcpkg_exported
RESULT_VARIABLE RESULT)
if (NOT RESULT EQUAL 0)
message(FATAL_ERROR "cmake -E tar failed with exit code ${RESULT}")
endif ()

# Move all contents of extracted folder to the root of vcpkg_exported
file(GLOB EXTRACTED_CONTENTS "${ROOT}/vcpkg_exported/*/*")
foreach (FILE IN LISTS EXTRACTED_CONTENTS)
get_filename_component(ONLY_NAME ${FILE} NAME)
file(RENAME ${FILE} ${ROOT}/vcpkg_exported/${ONLY_NAME})
endforeach ()

file(GLOB VCPKG_INSTALLED_CONTENTS ${ROOT}/vcpkg_installed/*)
if (NOT VCPKG_INSTALLED_CONTENTS STREQUAL "")
message(
FATAL_ERROR
"${ROOT}/vcpkg_installed is not empty. Remove it and run the script again to install dependencies")
endif ()

file(REMOVE_RECURSE ${ROOT}/vcpkg_installed)

file(RENAME ${ROOT}/vcpkg_exported/installed ${ROOT}/vcpkg_installed)

else ()

message(STATUS "Directory ${ROOT}/vcpkg_exported already exists. Remove it to force extraction from the archive")

endif ()

message(STATUS "All operations finished")
11 changes: 8 additions & 3 deletions dep-hash.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ file(GLOB_RECURSE FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/ports/*" "${CMAKE_CURRE

set(HASHES)

message("-- Hashing files")

foreach (FILE IN LISTS FILES)
file(READ ${FILE} CONTENT)
string(SHA256 HASH "${CONTENT}")
message("${FILE} -> ${HASH}")
file(RELATIVE_PATH REL_FILE ${CMAKE_CURRENT_LIST_DIR} ${FILE})
message(" ${REL_FILE} -> ${HASH}")
list(APPEND HASHES "${HASH}")
endforeach ()

string(SHA256 GLOB_HASH "${HASHES}")
message(STATUS ${GLOB_HASH})
message("-- Combined hash is")

string(SHA256 DEP_HASH "${HASHES}")
message(STATUS ${DEP_HASH})
55 changes: 55 additions & 0 deletions upload-deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
set(ROOT ${CMAKE_CURRENT_LIST_DIR})

if (WIN32)
set(TEMP_DIR $ENV{TEMP})
else ()
set(TEMP_DIR $ENV{TMPDIR})
endif ()

if (NOT DEFINED ENV{AWS_SECRET_ACCESS_KEY})
message(FATAL_ERROR "AWS_SECRET_ACCESS_KEY is not set. This script is for internal use only")
endif ()

if (DEFINED ENV{VCPKG_TARGET_TRIPLET})
set(VCPKG_TARGET_TRIPLET $ENV{VCPKG_TARGET_TRIPLET})
else ()
if (DEFINED ENV{VCPKG_DEFAULT_TRIPLET})
set(VCPKG_TARGET_TRIPLET $ENV{VCPKG_DEFAULT_TRIPLET})
else ()
message(FATAL_ERROR "Set VCPKG_TARGET_TRIPLET or VCPKG_DEFAULT_TRIPLET environment variable")
endif ()
endif ()

include(${ROOT}/dep-hash.cmake)

# Check if the archive exists on S3
execute_process(COMMAND aws s3 ls s3://gh-bin/brisk-deps/${VCPKG_TARGET_TRIPLET}-${DEP_HASH}.7z RESULT_VARIABLE RESULT)

if (RESULT EQUAL 0) # aws s3 ls was successfull, file exists
message("Archive does exist on S3, skipping build")
else ()
message("Archive does not exist on S3, trying to build")

# Install vcpkg dependencies with icu feature
execute_process(
COMMAND vcpkg install --x-feature=icu
WORKING_DIRECTORY ${ROOT} COMMAND_ECHO STDOUT
RESULT_VARIABLE RESULT)
if (NOT RESULT EQUAL 0)
message(FATAL_ERROR "vcpkg install failed with exit code ${RESULT}")
endif ()

# Export the package to a .7z archive
execute_process(COMMAND vcpkg export --7zip --output-dir=${TEMP_DIR} --output=${VCPKG_TARGET_TRIPLET}-${DEP_HASH}
COMMAND_ECHO STDOUT RESULT_VARIABLE RESULT)
if (NOT RESULT EQUAL 0)
message(FATAL_ERROR "vcpkg export failed with exit code ${RESULT}")
endif ()

# Upload the archive to S3
execute_process(COMMAND aws s3 cp --acl public-read ${TEMP_DIR}/${VCPKG_TARGET_TRIPLET}-${DEP_HASH}.7z
s3://gh-bin/brisk-deps/ COMMAND_ECHO STDOUT RESULT_VARIABLE RESULT)
if (NOT RESULT EQUAL 0)
message(FATAL_ERROR "aws s3 cp failed with exit code ${RESULT}")
endif ()
endif ()

0 comments on commit eb87e26

Please sign in to comment.