From fdac1fc5aa36e8edeb9f358f0fad041de2626215 Mon Sep 17 00:00:00 2001 From: xyb Date: Sat, 5 Sep 2020 10:45:48 -0700 Subject: [PATCH] Add community triple arm64-linux and arm-linux. (#11880) Verify the following command on both 32 bits and 64 bits OS on Raspberry pi 3. ./bootstrap-vcpkg.sh ./vcpkg install boost --- ports/boost-build/CONTROL | 2 +- ports/boost-build/portfile.cmake | 4 +--- .../boost-modular-build-helper/CMakeLists.txt | 2 ++ ports/boost-modular-build-helper/CONTROL | 2 +- .../boost-modular-build.cmake | 20 ++++++++++++++++--- ports/libffi/CMakeLists.txt | 18 ++++++++++++----- ports/libffi/CONTROL | 2 +- scripts/bootstrap.sh | 18 +++++++++++++++++ scripts/buildsystems/vcpkg.cmake | 4 ++++ scripts/cmake/vcpkg_configure_cmake.cmake | 2 +- toolsrc/src/vcpkg.cpp | 8 ++++++++ toolsrc/src/vcpkg/triplet.cpp | 6 ++++++ triplets/community/arm-linux.cmake | 9 +++++++++ triplets/community/arm64-linux.cmake | 9 +++++++++ 14 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 triplets/community/arm-linux.cmake create mode 100644 triplets/community/arm64-linux.cmake diff --git a/ports/boost-build/CONTROL b/ports/boost-build/CONTROL index 8b4c5e1613..036631336f 100644 --- a/ports/boost-build/CONTROL +++ b/ports/boost-build/CONTROL @@ -1,6 +1,6 @@ Source: boost-build Version: 1.73.0 -Port-Version: 3 +Port-Version: 4 Homepage: https://github.com/boostorg/build Description: Boost.Build Build-Depends: boost-uninstall \ No newline at end of file diff --git a/ports/boost-build/portfile.cmake b/ports/boost-build/portfile.cmake index 9b06d0074e..bad139ac22 100644 --- a/ports/boost-build/portfile.cmake +++ b/ports/boost-build/portfile.cmake @@ -2,9 +2,7 @@ include(vcpkg_common_functions) set(VCPKG_POLICY_EMPTY_PACKAGE enabled) -if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" AND NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "s390x") - return() -elseif(CMAKE_HOST_WIN32 AND VCPKG_CMAKE_SYSTEM_NAME AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW") +if(CMAKE_HOST_WIN32 AND VCPKG_CMAKE_SYSTEM_NAME AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW") return() endif() diff --git a/ports/boost-modular-build-helper/CMakeLists.txt b/ports/boost-modular-build-helper/CMakeLists.txt index 629e01f6d3..852430dc9b 100644 --- a/ports/boost-modular-build-helper/CMakeLists.txt +++ b/ports/boost-modular-build-helper/CMakeLists.txt @@ -37,6 +37,8 @@ endif() if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "s390x") list(APPEND B2_OPTIONS architecture=s390x) +elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" OR VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + list(APPEND B2_OPTIONS architecture=arm) else() list(APPEND B2_OPTIONS architecture=x86) endif() diff --git a/ports/boost-modular-build-helper/CONTROL b/ports/boost-modular-build-helper/CONTROL index 601b286e0e..b39ec5f422 100644 --- a/ports/boost-modular-build-helper/CONTROL +++ b/ports/boost-modular-build-helper/CONTROL @@ -1,4 +1,4 @@ Source: boost-modular-build-helper Version: 1.73.0 -Port-Version: 4 +Port-Version: 5 Build-Depends: boost-uninstall \ No newline at end of file diff --git a/ports/boost-modular-build-helper/boost-modular-build.cmake b/ports/boost-modular-build-helper/boost-modular-build.cmake index b0952e0acb..26784ed26f 100644 --- a/ports/boost-modular-build-helper/boost-modular-build.cmake +++ b/ports/boost-modular-build-helper/boost-modular-build.cmake @@ -18,7 +18,13 @@ function(boost_modular_build) # Todo: this serves too similar a purpose as vcpkg_find_acquire_program() if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux" AND VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") - set(BOOST_BUILD_PATH "${CURRENT_INSTALLED_DIR}/../x64-linux/tools/boost-build") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64") + set(BOOST_BUILD_PATH "${CURRENT_INSTALLED_DIR}/../arm64-linux/tools/boost-build") + else() + set(BOOST_BUILD_PATH "${CURRENT_INSTALLED_DIR}/../x64-linux/tools/boost-build") + endif() + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv7l") + set(BOOST_BUILD_PATH "${CURRENT_INSTALLED_DIR}/../arm-linux/tools/boost-build") elseif(CMAKE_HOST_WIN32 AND VCPKG_CMAKE_SYSTEM_NAME AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW") get_filename_component(BOOST_BUILD_PATH "${CURRENT_INSTALLED_DIR}/../x86-windows/tools/boost-build" ABSOLUTE) elseif(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" AND NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "s390x") @@ -29,9 +35,17 @@ function(boost_modular_build) if(NOT EXISTS "${BOOST_BUILD_PATH}") if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux" AND VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") - message(FATAL_ERROR "The x64 boost-build tools must be installed to build arm64 for Linux. Please run `vcpkg install boost-build:x64-linux`.") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64") + message(FATAL_ERROR "The arm64 boost-build tools must be installed to build arm64 for Linux. Please run `vcpkg install boost-build:arm64-linux`.") + else() + message(FATAL_ERROR "The x64 boost-build tools must be installed to build arm64 for Linux. Please run `vcpkg install boost-build:x64-linux`.") + endif() else() - message(FATAL_ERROR "The x86 boost-build tools must be installed to build for non-x86/x64 platforms. Please run `vcpkg install boost-build:x86-windows`.") + if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv7l") + message(FATAL_ERROR "The arm boost-build tools must be installed to build arm64 for Linux. Please run `vcpkg install boost-build:arm-linux`.") + else() + message(FATAL_ERROR "The x86 boost-build tools must be installed to build for non-x86/x64 platforms. Please run `vcpkg install boost-build:x86-windows`.") + endif() endif() endif() diff --git a/ports/libffi/CMakeLists.txt b/ports/libffi/CMakeLists.txt index d7c741859a..693fcc9358 100644 --- a/ports/libffi/CMakeLists.txt +++ b/ports/libffi/CMakeLists.txt @@ -11,7 +11,7 @@ endif() # config variables for ffi.h.in set(VERSION 3.3) -set(KNOWN_PROCESSORS x86 x86_64 AMD64 ARM ARM64 i386) +set(KNOWN_PROCESSORS x86 x86_64 AMD64 ARM ARM64 i386 armv7l aarch64) if(NOT CMAKE_SYSTEM_PROCESSOR IN_LIST KNOWN_PROCESSORS) message(FATAL_ERROR "Unknown processor: ${CMAKE_SYSTEM_PROCESSOR}") @@ -19,6 +19,10 @@ endif() if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM") set(TARGET ARM) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l") + set(TARGET ARM) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + set(TARGET ARM64) elseif(CMAKE_SYSTEM_NAME MATCHES "BSD" AND CMAKE_SIZEOF_VOID_P EQUAL 4) set(TARGET X86_FREEBSD) elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") @@ -50,9 +54,9 @@ set(FFI_EXEC_TRAMPOLINE_TABLE 0) configure_file(include/ffi.h.in ${CMAKE_BINARY_DIR}/include/ffi.h) file(COPY ${FFI_CONFIG_FILE} DESTINATION ${CMAKE_BINARY_DIR}) -if ("${TARGET}" STREQUAL "ARM_WIN64") +if ("${TARGET}" STREQUAL "ARM_WIN64" OR "${TARGET}" STREQUAL "ARM64") file(COPY src/aarch64/ffitarget.h DESTINATION ${CMAKE_BINARY_DIR}/include) -elseif ("${TARGET}" STREQUAL "ARM_WIN32") +elseif ("${TARGET}" STREQUAL "ARM_WIN32" OR "${TARGET}" STREQUAL "ARM") file(COPY src/arm/ffitarget.h DESTINATION ${CMAKE_BINARY_DIR}/include) else() file(COPY src/x86/ffitarget.h DESTINATION ${CMAKE_BINARY_DIR}/include) @@ -72,11 +76,11 @@ set(FFI_SOURCES src/prep_cif.c src/types.c) -if ("${TARGET}" STREQUAL "ARM_WIN64") +if ("${TARGET}" STREQUAL "ARM_WIN64" OR "${TARGET}" STREQUAL "ARM64") set(FFI_SOURCES ${FFI_SOURCES} src/aarch64/ffi.c) -elseif("${TARGET}" STREQUAL "ARM_WIN32") +elseif("${TARGET}" STREQUAL "ARM_WIN32" OR "${TARGET}" STREQUAL "ARM") set(FFI_SOURCES ${FFI_SOURCES} src/arm/ffi.c) @@ -162,8 +166,12 @@ elseif("${TARGET}" STREQUAL "X86_WIN64") add_assembly(src/x86/win64_intel.S) elseif("${TARGET}" STREQUAL "ARM_WIN32") add_assembly(src/arm/sysv_msvc_arm32.S) +elseif("${TARGET}" STREQUAL "ARM") + add_assembly(src/arm/sysv.S) elseif("${TARGET}" STREQUAL "ARM_WIN64") add_assembly(src/aarch64/win64_armasm.S) +elseif("${TARGET}" STREQUAL "ARM64") + add_assembly(src/aarch64/sysv.S) else() message(FATAL_ERROR "Target not implemented") endif() diff --git a/ports/libffi/CONTROL b/ports/libffi/CONTROL index a5d4c20941..6f1154eda4 100644 --- a/ports/libffi/CONTROL +++ b/ports/libffi/CONTROL @@ -1,5 +1,5 @@ Source: libffi Version: 3.3 -Port-Version: 4 +Port-Version: 5 Homepage: https://github.com/libffi/libffi Description: Portable, high level programming interface to various calling conventions diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 321a16e05d..46f695864b 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -79,6 +79,16 @@ vcpkgCheckRepoTool() fi } +vcpkgCheckBuildTool() +{ + __tool=$1 + if ! command -v "$__tool" >/dev/null 2>&1 ; then + echo "Could not find $__tool. Please install it (and other dependencies) with:" + echo "sudo apt-get install cmake ninja-build" + exit 1 + fi +} + vcpkgCheckEqualFileHash() { url=$1; filePath=$2; expectedHash=$3 @@ -226,10 +236,18 @@ selectCXX() # Preparation UNAME="$(uname)" +ARCH="$(uname -m)" + +# Force using system utilities for building vcpkg if host arch is arm or arm64. +if [ "$ARCH" = "armv7l" -o "$ARCH" = "aarch64" ]; then + vcpkgUseSystem=true +fi if $vcpkgUseSystem; then cmakeExe="cmake" ninjaExe="ninja" + vcpkgCheckBuildTool "$cmakeExe" + vcpkgCheckBuildTool "$ninjaExe" else fetchTool "cmake" "$UNAME" cmakeExe || exit 1 fetchTool "ninja" "$UNAME" ninjaExe || exit 1 diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index c1df616dad..f2e89c5db0 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -172,6 +172,10 @@ else() set(_VCPKG_TARGET_TRIPLET_ARCH x64) elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "s390x") set(_VCPKG_TARGET_TRIPLET_ARCH s390x) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv7l") + set(_VCPKG_TARGET_TRIPLET_ARCH arm) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64") + set(_VCPKG_TARGET_TRIPLET_ARCH arm64) else() if( _CMAKE_IN_TRY_COMPILE ) message(STATUS "Unable to determine target architecture, continuing without vcpkg.") diff --git a/scripts/cmake/vcpkg_configure_cmake.cmake b/scripts/cmake/vcpkg_configure_cmake.cmake index b443856f9c..63d7f87866 100644 --- a/scripts/cmake/vcpkg_configure_cmake.cmake +++ b/scripts/cmake/vcpkg_configure_cmake.cmake @@ -150,7 +150,7 @@ function(vcpkg_configure_cmake) endif() # If we use Ninja, make sure it's on PATH - if(GENERATOR STREQUAL "Ninja") + if(GENERATOR STREQUAL "Ninja" AND NOT DEFINED ENV{VCPKG_FORCE_SYSTEM_BINARIES}) vcpkg_find_acquire_program(NINJA) get_filename_component(NINJA_PATH ${NINJA} DIRECTORY) vcpkg_add_to_path("${NINJA_PATH}") diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index d0df8749fd..6c30f7ced0 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -235,6 +235,14 @@ int main(const int argc, const char* const* const argv) load_config(fs); +#if (defined(__aarch64__) || defined(__arm__) || defined(_M_ARM) || defined(_M_ARM64)) && !defined(_WIN32) + if (!System::get_environment_variable("VCPKG_FORCE_SYSTEM_BINARIES").has_value()) + { + Checks::exit_with_message(VCPKG_LINE_INFO, + "Environment variable VCPKG_FORCE_SYSTEM_BINARIES must be set on arm platform."); + } +#endif + VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(fs, argc, argv); args.imbue_from_environment(); args.check_feature_flag_consistency(); diff --git a/toolsrc/src/vcpkg/triplet.cpp b/toolsrc/src/vcpkg/triplet.cpp index c9ae749704..1d325fb65e 100644 --- a/toolsrc/src/vcpkg/triplet.cpp +++ b/toolsrc/src/vcpkg/triplet.cpp @@ -87,7 +87,13 @@ namespace vcpkg #elif defined(__FreeBSD__) return Triplet::from_canonical_name("x64-freebsd"); #elif defined(__GLIBC__) +#if defined(__aarch64__) + return Triplet::from_canonical_name("arm64-linux"); +#elif defined(__arm__) + return Triplet::from_canonical_name("arm-linux"); +#else return Triplet::from_canonical_name("x64-linux"); +#endif #else return Triplet::from_canonical_name("x64-linux-musl"); #endif diff --git a/triplets/community/arm-linux.cmake b/triplets/community/arm-linux.cmake new file mode 100644 index 0000000000..6f69da83b2 --- /dev/null +++ b/triplets/community/arm-linux.cmake @@ -0,0 +1,9 @@ +set(VCPKG_TARGET_ARCHITECTURE arm) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Linux) + +if(NOT CMAKE_HOST_SYSTEM_PROCESSOR) + execute_process(COMMAND "uname" "-m" OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() diff --git a/triplets/community/arm64-linux.cmake b/triplets/community/arm64-linux.cmake new file mode 100644 index 0000000000..5faf2f0a0f --- /dev/null +++ b/triplets/community/arm64-linux.cmake @@ -0,0 +1,9 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Linux) + +if(NOT CMAKE_HOST_SYSTEM_PROCESSOR) + execute_process(COMMAND "uname" "-m" OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR OUTPUT_STRIP_TRAILING_WHITESPACE) +endif()