2018-03-27 18:03:26 +08:00
#!/bin/sh
2021-10-30 13:39:14 +08:00
# Find .vcpkg-root.
2019-04-20 08:24:05 +08:00
vcpkgRootDir = $( X = cd -- " $( dirname -- " $0 " ) " && pwd -P)
while [ " $vcpkgRootDir " != "/" ] && ! [ -e " $vcpkgRootDir /.vcpkg-root " ] ; do
vcpkgRootDir = " $( dirname " $vcpkgRootDir " ) "
done
2021-10-30 13:39:14 +08:00
# Parse arguments.
2018-06-12 08:01:13 +08:00
vcpkgDisableMetrics = "OFF"
2018-12-12 02:15:44 +08:00
vcpkgUseSystem = false
2021-10-30 13:39:14 +08:00
vcpkgUseMuslC = "OFF"
2018-06-09 09:01:35 +08:00
for var in " $@ "
do
2018-12-12 02:15:44 +08:00
if [ " $var " = "-disableMetrics" -o " $var " = "--disableMetrics" ] ; then
2018-06-12 08:01:13 +08:00
vcpkgDisableMetrics = "ON"
2018-12-12 02:15:44 +08:00
elif [ " $var " = "-useSystemBinaries" -o " $var " = "--useSystemBinaries" ] ; then
2021-10-30 13:39:14 +08:00
echo "Warning: -useSystemBinaries no longer has any effect; ignored. Note that the VCPKG_USE_SYSTEM_BINARIES environment variable behavior is not changed."
2019-04-11 15:32:03 +08:00
elif [ " $var " = "-allowAppleClang" -o " $var " = "--allowAppleClang" ] ; then
2021-10-30 13:39:14 +08:00
echo "Warning: -allowAppleClang no longer has any effect; ignored."
2020-05-15 03:49:31 +08:00
elif [ " $var " = "-buildTests" ] ; then
2021-10-30 13:39:14 +08:00
echo "Warning: -buildTests no longer has any effect; ignored."
elif [ " $var " = "-musl" ] ; then
vcpkgUseMuslC = "ON"
2018-12-12 02:15:44 +08:00
elif [ " $var " = "-help" -o " $var " = "--help" ] ; then
echo "Usage: ./bootstrap-vcpkg.sh [options]"
echo
echo "Options:"
echo " -help Display usage help"
2021-10-30 13:39:14 +08:00
echo " -disableMetrics Mark this vcpkg root to disable metrics."
echo " -musl Use the musl binary rather than the glibc binary on Linux."
2018-12-12 02:15:44 +08:00
exit 1
2018-06-09 09:01:35 +08:00
else
2018-12-12 02:15:44 +08:00
echo " Unknown argument $var . Use '-help' for help. "
2018-06-09 09:01:35 +08:00
exit 1
fi
done
2020-05-20 06:22:44 +08:00
# 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
2021-10-30 13:39:14 +08:00
# Determine the downloads directory.
2018-12-12 03:48:41 +08:00
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
2018-03-27 18:03:26 +08:00
2021-10-30 13:39:14 +08:00
# Check for minimal prerequisites.
2018-03-27 18:03:26 +08:00
vcpkgCheckRepoTool( )
{
__tool = $1
if ! command -v " $__tool " >/dev/null 2>& 1 ; then
echo " Could not find $__tool . Please install it (and other dependencies) with: "
2021-10-30 13:39:14 +08:00
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"
2022-03-22 01:16:56 +08:00
echo "On Arch Linux and derivatives:"
2024-06-07 17:56:45 +08:00
echo " sudo pacman -Syu base-devel git curl zip unzip tar cmake ninja"
2021-10-30 13:39:14 +08:00
echo "On Alpine:"
echo " apk add build-base cmake ninja zip unzip curl git"
echo " (and export VCPKG_FORCE_SYSTEM_BINARIES=1)"
2018-03-27 18:03:26 +08:00
exit 1
fi
}
2021-10-30 13:39:14 +08:00
vcpkgCheckRepoTool curl
vcpkgCheckRepoTool zip
vcpkgCheckRepoTool unzip
vcpkgCheckRepoTool tar
UNAME = " $( uname) "
ARCH = " $( uname -m) "
if [ -e /etc/alpine-release ] ; then
vcpkgUseSystem = "ON"
2023-04-18 10:36:35 +08:00
if [ " $ARCH " = "x86_64" ] ; then
vcpkgUseMuslC = "ON"
fi
2021-10-30 13:39:14 +08:00
fi
if [ " $UNAME " = "OpenBSD" ] ; then
vcpkgUseSystem = "ON"
fi
if [ " $vcpkgUseSystem " = "ON" ] ; then
vcpkgCheckRepoTool cmake
vcpkgCheckRepoTool ninja
vcpkgCheckRepoTool git
fi
2018-03-27 18:03:26 +08:00
vcpkgCheckEqualFileHash( )
{
url = $1 ; filePath = $2 ; expectedHash = $3
2018-04-26 13:23:45 +08:00
if command -v "sha512sum" >/dev/null 2>& 1 ; then
actualHash = $( sha512sum " $filePath " )
2024-07-30 14:05:23 +08:00
elif command -v "sha512" >/dev/null 2>& 1 ; then
# OpenBSD
actualHash = $( sha512 -q " $filePath " )
2018-04-26 13:23:45 +08:00
else
2024-02-22 03:41:39 +08:00
# [g]sha512sum is not available by default on osx
2018-04-26 13:23:45 +08:00
# shasum is not available by default on Fedora
actualHash = $( shasum -a 512 " $filePath " )
2018-04-26 08:38:45 +08:00
fi
2018-03-27 18:03:26 +08:00
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 ] "
2019-03-20 07:32:24 +08:00
exit 1
2018-03-27 18:03:26 +08:00
fi
}
vcpkgDownloadFile( )
{
url = $1 ; downloadPath = $2 sha512 = $3
rm -rf " $downloadPath .part "
2021-07-28 06:42:43 +08:00
curl -L $url --tlsv1.2 --create-dirs --retry 3 --output " $downloadPath .part " --silent --show-error --fail || exit 1
2018-03-27 18:03:26 +08:00
vcpkgCheckEqualFileHash $url " $downloadPath .part " $sha512
2021-10-30 13:39:14 +08:00
chmod +x " $downloadPath .part "
2018-03-27 18:03:26 +08:00
mv " $downloadPath .part " " $downloadPath "
}
2021-10-30 13:39:14 +08:00
vcpkgExtractTar( )
2018-03-27 18:03:26 +08:00
{
archive = $1 ; toPath = $2
rm -rf " $toPath " " $toPath .partial "
mkdir -p " $toPath .partial "
2021-10-30 13:39:14 +08:00
$( cd " $toPath .partial " && tar xzf " $archive " )
2018-03-27 18:03:26 +08:00
mv " $toPath .partial " " $toPath "
}
2023-07-26 11:35:26 +08:00
# 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
# Read the vcpkg-tool config file to determine what release to download
. " $vcpkgRootDir /scripts/vcpkg-tool-metadata.txt "
vcpkgDownloadTool = "ON"
if [ " $UNAME " = "Darwin" ] ; then
echo "Downloading vcpkg-macos..."
vcpkgToolReleaseSha = $VCPKG_MACOS_SHA
vcpkgToolName = "vcpkg-macos"
elif [ " $vcpkgUseMuslC " = "ON" ] ; then
echo "Downloading vcpkg-muslc..."
vcpkgToolReleaseSha = $VCPKG_MUSLC_SHA
vcpkgToolName = "vcpkg-muslc"
elif [ " $ARCH " = "x86_64" ] ; then
echo "Downloading vcpkg-glibc..."
vcpkgToolReleaseSha = $VCPKG_GLIBC_SHA
vcpkgToolName = "vcpkg-glibc"
else
echo "Unable to determine a binary release of vcpkg; attempting to build from source."
vcpkgDownloadTool = "OFF"
vcpkgToolReleaseSha = $VCPKG_TOOL_SOURCE_SHA
fi
# Do the download or build.
2021-10-30 13:39:14 +08:00
if [ " $vcpkgDownloadTool " = "ON" ] ; then
2023-07-26 11:35:26 +08:00
vcpkgDownloadFile " https://github.com/microsoft/vcpkg-tool/releases/download/ $VCPKG_TOOL_RELEASE_TAG / $vcpkgToolName " " $vcpkgRootDir /vcpkg " $vcpkgToolReleaseSha
2021-10-30 13:39:14 +08:00
else
2023-07-26 11:35:26 +08:00
vcpkgToolReleaseTarball = " $VCPKG_TOOL_RELEASE_TAG .tar.gz "
2021-10-30 13:39:14 +08:00
vcpkgToolUrl = " https://github.com/microsoft/vcpkg-tool/archive/ $vcpkgToolReleaseTarball "
baseBuildDir = " $vcpkgRootDir /buildtrees/_vcpkg "
buildDir = " $baseBuildDir /build "
tarballPath = " $downloadsDir / $vcpkgToolReleaseTarball "
srcBaseDir = " $baseBuildDir /src "
2023-07-26 11:35:26 +08:00
srcDir = " $srcBaseDir /vcpkg-tool- $VCPKG_TOOL_RELEASE_TAG "
2020-11-24 01:43:23 +08:00
2021-10-30 13:39:14 +08:00
if [ -e " $tarballPath " ] ; then
vcpkgCheckEqualFileHash " $vcpkgToolUrl " " $tarballPath " " $vcpkgToolReleaseSha "
2019-10-08 01:35:13 +08:00
else
2021-10-30 13:39:14 +08:00
echo "Downloading vcpkg tool sources"
vcpkgDownloadFile " $vcpkgToolUrl " " $tarballPath " " $vcpkgToolReleaseSha "
2019-10-08 01:35:13 +08:00
fi
2018-03-27 18:03:26 +08:00
2021-10-30 13:39:14 +08:00
echo "Building vcpkg-tool..."
rm -rf " $baseBuildDir "
mkdir -p " $buildDir "
vcpkgExtractTar " $tarballPath " " $srcBaseDir "
cmakeConfigOptions = "-DCMAKE_BUILD_TYPE=Release -G 'Ninja' -DVCPKG_DEVELOPMENT_WARNINGS=OFF"
2021-02-05 02:15:44 +08:00
2021-10-30 13:39:14 +08:00
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
2021-02-05 02:15:44 +08:00
2024-03-01 06:04:29 +08:00
( cd " $buildDir " && eval cmake " $srcDir " $cmakeConfigOptions ) || exit 1
2021-10-30 13:39:14 +08:00
( cd " $buildDir " && cmake --build .) || exit 1
2018-03-27 18:03:26 +08:00
2021-10-30 13:39:14 +08:00
rm -rf " $vcpkgRootDir /vcpkg "
cp " $buildDir /vcpkg " " $vcpkgRootDir / "
2021-07-28 07:20:45 +08:00
fi
2023-08-25 07:20:42 +08:00
" $vcpkgRootDir /vcpkg " version --disable-metrics
2023-07-26 11:35:26 +08:00
2021-10-30 13:39:14 +08:00
# Apply the disable-metrics marker file.
2021-01-14 06:06:06 +08:00
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.
2020-05-30 05:09:03 +08:00
cat <<EOF
Telemetry
---------
vcpkg collects usage data in order to help us improve your experience.
The data collected by Microsoft is anonymous.
You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics,
passing --disable-metrics to vcpkg on the command line,
or by setting the VCPKG_DISABLE_METRICS environment variable.
Read more about vcpkg telemetry at docs/about/privacy.md
EOF
2020-02-14 10:12:12 +08:00
fi