#!/bin/sh # Find .vcpkg-root. vcpkgRootDir=$(X= cd -- "$(dirname -- "$0")" && pwd -P) while [ "$vcpkgRootDir" != "/" ] && ! [ -e "$vcpkgRootDir/.vcpkg-root" ]; do vcpkgRootDir="$(dirname "$vcpkgRootDir")" done # Parse arguments. vcpkgDisableMetrics="OFF" vcpkgUseSystem=false vcpkgUseMuslC="OFF" for var in "$@" do if [ "$var" = "-disableMetrics" -o "$var" = "--disableMetrics" ]; then vcpkgDisableMetrics="ON" elif [ "$var" = "-useSystemBinaries" -o "$var" = "--useSystemBinaries" ]; then echo "Warning: -useSystemBinaries no longer has any effect; ignored. Note that the VCPKG_USE_SYSTEM_BINARIES environment variable behavior is not changed." elif [ "$var" = "-allowAppleClang" -o "$var" = "--allowAppleClang" ]; then echo "Warning: -allowAppleClang no longer has any effect; ignored." elif [ "$var" = "-buildTests" ]; then echo "Warning: -buildTests no longer has any effect; ignored." elif [ "$var" = "-musl" ]; then vcpkgUseMuslC="ON" elif [ "$var" = "-help" -o "$var" = "--help" ]; then echo "Usage: ./bootstrap-vcpkg.sh [options]" echo echo "Options:" echo " -help Display usage help" echo " -disableMetrics Mark this vcpkg root to disable metrics." echo " -musl Use the musl binary rather than the glibc binary on Linux." exit 1 else echo "Unknown argument $var. Use '-help' for help." exit 1 fi done # Enable using this entry point on windows from git bash by redirecting to the .bat file. unixName=$(uname -s | sed 's/MINGW.*_NT.*/MINGW_NT/') if [ "$unixName" = "MINGW_NT" ]; then if [ "$vcpkgDisableMetrics" = "ON" ]; then args="-disableMetrics" else args="" fi vcpkgRootDir=$(cygpath -aw "$vcpkgRootDir") cmd "/C $vcpkgRootDir\\bootstrap-vcpkg.bat $args" || exit 1 exit 0 fi # Determine the downloads directory. if [ -z ${VCPKG_DOWNLOADS+x} ]; then downloadsDir="$vcpkgRootDir/downloads" else downloadsDir="$VCPKG_DOWNLOADS" if [ ! -d "$VCPKG_DOWNLOADS" ]; then echo "VCPKG_DOWNLOADS was set to '$VCPKG_DOWNLOADS', but that was not a directory." exit 1 fi fi # Check for minimal prerequisites. vcpkgCheckRepoTool() { __tool=$1 if ! command -v "$__tool" >/dev/null 2>&1 ; then echo "Could not find $__tool. Please install it (and other dependencies) with:" echo "On Debian and Ubuntu derivatives:" echo " sudo apt-get install curl zip unzip tar" echo "On recent Red Hat and Fedora derivatives:" echo " sudo dnf install curl zip unzip tar" echo "On older Red Hat and Fedora derivatives:" echo " sudo yum install curl zip unzip tar" echo "On SUSE Linux and derivatives:" echo " sudo zypper install curl zip unzip tar" echo "On Arch Linux and derivatives:" echo " sudo pacman -S curl zip unzip tar cmake ninja" echo "On Alpine:" echo " apk add build-base cmake ninja zip unzip curl git" echo " (and export VCPKG_FORCE_SYSTEM_BINARIES=1)" exit 1 fi } vcpkgCheckRepoTool curl vcpkgCheckRepoTool zip vcpkgCheckRepoTool unzip vcpkgCheckRepoTool tar UNAME="$(uname)" ARCH="$(uname -m)" if [ -e /etc/alpine-release ]; then vcpkgUseSystem="ON" vcpkgUseMuslC="ON" fi if [ "$UNAME" = "OpenBSD" ]; then vcpkgUseSystem="ON" if [ -z "$CXX" ]; then CXX=/usr/bin/clang++ fi if [ -z "$CC" ]; then CC=/usr/bin/clang fi fi if [ "$vcpkgUseSystem" = "ON" ]; then vcpkgCheckRepoTool cmake vcpkgCheckRepoTool ninja vcpkgCheckRepoTool git vcpkgCheckRepoTool gcc fi # Determine what we are going to do to bootstrap: # MacOS -> Download vcpkg-macos # Linux # useMuslC -> download vcpkg-muslc # amd64 -> download vcpkg-glibc # Otherwise # Download and build from source # Choose the vcpkg binary to download vcpkgDownloadTool="ON" vcpkgToolReleaseTag="2022-10-12" if [ "$UNAME" = "Darwin" ]; then echo "Downloading vcpkg-macos..." vcpkgToolReleaseSha="9849326c5926b6ba35245686b9a38cce79b6bdf93491b922732583c9676abbbd617576987673ebfeb58809ecf93238b8f69c0f75c4432e52ee11aa24fc3a18d8" vcpkgToolName="vcpkg-macos" elif [ "$vcpkgUseMuslC" = "ON" ]; then echo "Downloading vcpkg-muslc..." vcpkgToolReleaseSha="c5611167093568fe512b6a421638aa53d944f4750153192c56a145c7a7775b52ff1121d666ffee38fd4311c7886282c507028443aa268dc927b94cd65ebf3f25" vcpkgToolName="vcpkg-muslc" elif [ "$ARCH" = "x86_64" ]; then echo "Downloading vcpkg-glibc..." vcpkgToolReleaseSha="42c86ac721a5f115087d33de037a1107fdf4275bfcb237b47a30c5c547c56a338ef7af7fb18e3275b327579436b4841e46b846436bcface67edc7ceafcbf7211" vcpkgToolName="vcpkg-glibc" else echo "Unable to determine a binary release of vcpkg; attempting to build from source." vcpkgDownloadTool="OFF" vcpkgToolReleaseSha="02034b38a9bdd491ccd0832539fb4aa1bdd4812531d861ba336ea61c70d6926bfb08a3a40de958b0e66d24a3ff1e44f383c0d15258df04a18d683ac29d5dd28e" fi # Do the download or build. vcpkgCheckEqualFileHash() { url=$1; filePath=$2; expectedHash=$3 if command -v "sha512sum" >/dev/null 2>&1 ; then actualHash=$(sha512sum "$filePath") else # sha512sum is not available by default on osx # shasum is not available by default on Fedora actualHash=$(shasum -a 512 "$filePath") fi actualHash="${actualHash%% *}" # shasum returns [hash filename], so get the first word if ! [ "$expectedHash" = "$actualHash" ]; then echo "" echo "File does not have expected hash:" echo " url: [ $url ]" echo " File path: [ $downloadPath ]" echo " Expected hash: [ $sha512 ]" echo " Actual hash: [ $actualHash ]" exit 1 fi } vcpkgDownloadFile() { url=$1; downloadPath=$2 sha512=$3 rm -rf "$downloadPath.part" curl -L $url --tlsv1.2 --create-dirs --retry 3 --output "$downloadPath.part" --silent --show-error --fail || exit 1 vcpkgCheckEqualFileHash $url "$downloadPath.part" $sha512 chmod +x "$downloadPath.part" mv "$downloadPath.part" "$downloadPath" } vcpkgExtractTar() { archive=$1; toPath=$2 rm -rf "$toPath" "$toPath.partial" mkdir -p "$toPath.partial" $(cd "$toPath.partial" && tar xzf "$archive") mv "$toPath.partial" "$toPath" } if [ "$vcpkgDownloadTool" = "ON" ]; then vcpkgDownloadFile "https://github.com/microsoft/vcpkg-tool/releases/download/$vcpkgToolReleaseTag/$vcpkgToolName" "$vcpkgRootDir/vcpkg" $vcpkgToolReleaseSha else if [ "x$CXX" = "x" ]; then if which g++-12 >/dev/null 2>&1; then CXX=g++-12 elif which g++-11 >/dev/null 2>&1; then CXX=g++-11 elif which g++-10 >/dev/null 2>&1; then CXX=g++-10 elif which g++-9 >/dev/null 2>&1; then CXX=g++-9 elif which g++-8 >/dev/null 2>&1; then CXX=g++-8 elif which g++-7 >/dev/null 2>&1; then CXX=g++-7 elif which g++-6 >/dev/null 2>&1; then CXX=g++-6 elif which g++ >/dev/null 2>&1; then CXX=g++ fi # If we can't find g++, allow CMake to do the look-up fi vcpkgToolReleaseTarball="$vcpkgToolReleaseTag.tar.gz" vcpkgToolUrl="https://github.com/microsoft/vcpkg-tool/archive/$vcpkgToolReleaseTarball" baseBuildDir="$vcpkgRootDir/buildtrees/_vcpkg" buildDir="$baseBuildDir/build" tarballPath="$downloadsDir/$vcpkgToolReleaseTarball" srcBaseDir="$baseBuildDir/src" srcDir="$srcBaseDir/vcpkg-tool-$vcpkgToolReleaseTag" if [ -e "$tarballPath" ]; then vcpkgCheckEqualFileHash "$vcpkgToolUrl" "$tarballPath" "$vcpkgToolReleaseSha" else echo "Downloading vcpkg tool sources" vcpkgDownloadFile "$vcpkgToolUrl" "$tarballPath" "$vcpkgToolReleaseSha" fi echo "Building vcpkg-tool..." rm -rf "$baseBuildDir" mkdir -p "$buildDir" vcpkgExtractTar "$tarballPath" "$srcBaseDir" cmakeConfigOptions="-DCMAKE_BUILD_TYPE=Release -G 'Ninja' -DVCPKG_DEVELOPMENT_WARNINGS=OFF" if [ "${VCPKG_MAX_CONCURRENCY}" != "" ] ; then cmakeConfigOptions=" $cmakeConfigOptions '-DCMAKE_JOB_POOL_COMPILE:STRING=compile' '-DCMAKE_JOB_POOL_LINK:STRING=link' '-DCMAKE_JOB_POOLS:STRING=compile=$VCPKG_MAX_CONCURRENCY;link=$VCPKG_MAX_CONCURRENCY' " fi (cd "$buildDir" && CXX="$CXX" eval cmake "$srcDir" $cmakeConfigOptions) || exit 1 (cd "$buildDir" && cmake --build .) || exit 1 rm -rf "$vcpkgRootDir/vcpkg" cp "$buildDir/vcpkg" "$vcpkgRootDir/" fi # Apply the disable-metrics marker file. if [ "$vcpkgDisableMetrics" = "ON" ]; then touch "$vcpkgRootDir/vcpkg.disable-metrics" elif ! [ -f "$vcpkgRootDir/vcpkg.disable-metrics" ]; then # Note that we intentionally leave any existing vcpkg.disable-metrics; once a user has # opted out they should stay opted out. cat <