Skip to content

Commit

Permalink
[vcpkg] Add support for muslc, static crt linkage, and forcing the sy…
Browse files Browse the repository at this point in the history
…stem binaries for cmake and ninja
  • Loading branch information
ras0219-msft committed Dec 12, 2018
1 parent cf7e2f3 commit 828cedb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
37 changes: 27 additions & 10 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#!/bin/sh

vcpkgDisableMetrics="OFF"
vcpkgUseSystem=false
for var in "$@"
do
if [ "$var" = "-disableMetrics" ]; then
if [ "$var" = "-disableMetrics" -o "$var" = "--disableMetrics" ]; then
vcpkgDisableMetrics="ON"
elif [ "$var" = "-useSystemBinaries" -o "$var" = "--useSystemBinaries" ]; then
vcpkgUseSystem=true
elif [ "$var" = "-help" -o "$var" = "--help" ]; then
echo "Usage: ./bootstrap-vcpkg.sh [options]"
echo
echo "Options:"
echo " -help Display usage help"
echo " -disableMetrics Do not build metrics reporting into the executable"
echo " -useSystemBinaries Force use of the system utilities for building vcpkg"
exit 1
else
echo "Unknown argument $var"
echo "Unknown argument $var. Use '-help' for help."
exit 1
fi
done
Expand Down Expand Up @@ -191,13 +202,13 @@ selectCXX()
if [ "$gccversion" -lt "6" ]; then
echo "CXX ($CXX) is too old; please install a newer compiler such as g++-7."
echo "On Ubuntu try the following:"
echo "sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y"
echo "sudo apt-get update -y"
echo "sudo apt-get install g++-7 -y"
echo " sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y"
echo " sudo apt-get update -y"
echo " sudo apt-get install g++-7 -y"
echo "On CentOS try the following:"
echo "sudo yum install centos-release-scl"
echo "sudo yum install devtoolset-7"
echo "scl enable devtoolset-7 bash"
echo " sudo yum install centos-release-scl"
echo " sudo yum install devtoolset-7"
echo " scl enable devtoolset-7 bash"
return 1
fi

Expand All @@ -206,8 +217,14 @@ selectCXX()

# Preparation
UNAME="$(uname)"
fetchTool "cmake" "$UNAME" cmakeExe || exit 1
fetchTool "ninja" "$UNAME" ninjaExe || exit 1

if $vcpkgUseSystem; then
cmakeExe="cmake"
ninjaExe="ninja"
else
fetchTool "cmake" "$UNAME" cmakeExe || exit 1
fetchTool "ninja" "$UNAME" ninjaExe || exit 1
fi
selectCXX CXX || exit 1

# Do the build
Expand Down
4 changes: 4 additions & 0 deletions scripts/toolchains/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ if(NOT _CMAKE_IN_TRY_COMPILE)

string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ")
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ")
if(VCPKG_CRT_LINKAGE STREQUAL "static")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT "-static ")
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-static ")
endif()
endif()
endif()
4 changes: 3 additions & 1 deletion toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ static void inner(const VcpkgCmdArguments& args)
default_triplet = Triplet::from_canonical_name("x64-osx");
#elif defined(__FreeBSD__)
default_triplet = Triplet::from_canonical_name("x64-freebsd");
#else
#elif defined(__GLIBC__)
default_triplet = Triplet::from_canonical_name("x64-linux");
#else
default_triplet = Triplet::from_canonical_name("x64-linux-musl");
#endif
}
}
Expand Down
10 changes: 10 additions & 0 deletions toolsrc/src/vcpkg/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ namespace vcpkg

static PathAndVersion get_path(const VcpkgPaths& paths)
{
if (System::get_environment_variable("VCPKG_FORCE_SYSTEM_BINARIES").has_value())
{
return {"cmake", "0"};
}

std::vector<fs::path> candidate_paths;
#if defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
static const ToolData TOOL_DATA = parse_tool_data_from_xml(paths, "cmake");
Expand Down Expand Up @@ -317,6 +322,11 @@ namespace vcpkg

static PathAndVersion get_path(const VcpkgPaths& paths)
{
if (System::get_environment_variable("VCPKG_FORCE_SYSTEM_BINARIES").has_value())
{
return {"ninja", "0"};
}

static const ToolData TOOL_DATA = parse_tool_data_from_xml(paths, "ninja");

std::vector<fs::path> candidate_paths;
Expand Down

0 comments on commit 828cedb

Please sign in to comment.