Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMake detection of cross-compilers on arm/arm64 build arch #35084

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

basilgello
Copy link
Contributor

Fixes cross-building arm-linux / arm64-linux hon non-x86_64 hosts

Signed-off-by: Vasyl Gello <vasek.gello@gmail.com>
@basilgello
Copy link
Contributor Author

Rustdesk is built not only on amd64 hosts but aarch64 builders. CMake detects Debian/Ubuntu cross-compilers only for x86_64 architecture. With this patch, aarch64 builders produce arm-linux builds.

@LilyWangLL LilyWangLL added the category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly label Nov 14, 2023
@basilgello
Copy link
Contributor Author

@dg0yt please have a look here :)

@basilgello
Copy link
Contributor Author

@dg0yt @data-queue :)

@dg0yt
Copy link
Contributor

dg0yt commented Nov 20, 2023

Is the use of prefixed tool names the common solution to target arm from arm64?

From a more general perspective, the toolchain should probably look for <gnu-triplet>-gcc etc. when the variable isn't set and the target cpu doesn't match the host cpu (at least in more significant regards than-m32/-m64 bitness).
But I'm not an expert in this field.

@basilgello
Copy link
Contributor Author

basilgello commented Nov 20, 2023

Is the prefixed tool names the common solution to target arm from arm64 ?

Yes, and that's not only in Debian (where I test it all). Unfortunately -m32 / -m64 is x86 specific - other architectures in GCC have this convention.

Clang is different - see --target

@LilyWangLL LilyWangLL added the info:reviewed Pull Request changes follow basic guidelines label Nov 21, 2023
@data-queue data-queue added the requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. label Nov 22, 2023
@@ -13,7 +13,7 @@ elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
string(APPEND VCPKG_LINKER_FLAGS " -m32")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
set(CMAKE_SYSTEM_PROCESSOR armv7l CACHE STRING "")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the test entirely seems wrong as that will do the wrong thing when arm is the native architecture?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong, yes. But not worse than current support for modern arm64 hosts.
How much of vcpkg works out of the box on 32-bit arm hosts? The user must provide cmake and ninja, so maybe it is fair to ask for providing the compiler variables, too.

Couldn't we do find_program(var NAMES <prefix>-tool tool ...) ? This would consider user input, prefix, default. Hard-coded values belong into custom toolchain files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I declare the table of possible combinations of host & target instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we do find_program(var NAMES <prefix>-tool tool ...) ? This would consider user input, prefix, default. Hard-coded values belong into custom toolchain files.

FTR find_program is what scripts/cmake/mingw.cmake does:

find_program(CMAKE_C_COMPILER "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-gcc")
find_program(CMAKE_CXX_COMPILER "${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-g++")

(However, I noticed this now due to insufficient initalization of CMAKE_SYSTEM_PROCESSOR in a test project.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong, yes. But not worse than current support for modern arm64 hosts.

OK, I'm sold by 'not worse than the status quo'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user must provide cmake and ninja, so maybe it is fair to ask for providing the compiler variables, too.

Sadly that doesn't seem to be so easy, overriding the variables from the command-line doesn't work... maybe via a triplet, but that would introduce a fair bit of hassle for anyone who wants to perform a native build on an ARM machine. Ideally, we should just make the defaults work (see my comment below and #38113).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should just make the defaults work

Yes, we can agree on that, and #38113 is a good direction. It is just not the whole discussion from the last days.

@BillyONeal BillyONeal merged commit aa628ce into microsoft:master Dec 5, 2023
15 checks passed
@BillyONeal
Copy link
Member

Thanks!

@fwcd
Copy link
Contributor

fwcd commented Apr 10, 2024

Wrong, yes. But not worse than current support for modern arm64 hosts.

Unfortunately, this did actually break things. Most arm64 Linux hosts report as aarch64, causing vcpkg to think that it cross-compiles, which then results in very obscure errors such as:

error: while detecting compiler information:
The log file content at "/home/<user>/git/vcpkg/buildtrees/detect_compiler/stdout-arm64-linux.log" is:
-- Configuring arm64-linux-rel
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:112 (message):
    Command failed: /usr/bin/cmake /home/<user>/git/vcpkg/scripts/detect_compiler -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/<user>/git/vcpkg/packages/detect_compiler_arm64-linux -DCMAKE_SYSTEM_NAME=Linux -DBUILD_SHARED_LIBS=OFF -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/home/<user>/git/vcpkg/scripts/toolchains/linux.cmake -DVCPKG_TARGET_TRIPLET=arm64-linux -DVCPKG_SET_CHARSET_FLAG=ON -DVCPKG_PLATFORM_TOOLSET=external -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DVCPKG_APPLOCAL_DEPS=OFF -DCMAKE_TOOLCHAIN_FILE=/home/<user>/git/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON -DVCPKG_CXX_FLAGS= -DVCPKG_CXX_FLAGS_RELEASE= -DVCPKG_CXX_FLAGS_DEBUG= -DVCPKG_C_FLAGS= -DVCPKG_C_FLAGS_RELEASE= -DVCPKG_C_FLAGS_DEBUG= -DVCPKG_CRT_LINKAGE=dynamic -DVCPKG_LINKER_FLAGS= -DVCPKG_LINKER_FLAGS_RELEASE= -DVCPKG_LINKER_FLAGS_DEBUG= -DVCPKG_TARGET_ARCHITECTURE=arm64 -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_BINDIR:STRING=bin -D_VCPKG_ROOT_DIR=/home/<user>/git/vcpkg -DZ_VCPKG_ROOT_DIR=/home/<user>/git/vcpkg -D_VCPKG_INSTALLED_DIR=/home/<user>/git/vcpkg/installed -DVCPKG_MANIFEST_INSTALL=OFF
    Working Directory: /home/<user>/git/vcpkg/buildtrees/detect_compiler/arm64-linux-rel
    Error code: 1
    See logs for more information:
      /home/<user>/git/vcpkg/buildtrees/detect_compiler/config-arm64-linux-rel-CMakeCache.txt.log
      /home/<user>/git/vcpkg/buildtrees/detect_compiler/config-arm64-linux-rel-out.log
      /home/<user>/git/vcpkg/buildtrees/detect_compiler/config-arm64-linux-rel-err.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_configure_cmake.cmake:344 (vcpkg_execute_required_process)
  scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
  scripts/ports.cmake:175 (include)


error: vcpkg was unable to detect the active compiler's information. See above for the CMake failure output.

with config-arm64-linux-rel-out.log:

-- Cross compiling arm64 on host aarch64, use cross compiler: aarch64-linux-gnu-g++/aarch64-linux-gnu-gcc
-- The C compiler identification is unknown
-- Configuring incomplete, errors occurred!

with config-arm64-linux-rel-err.log:

CMake Error at CMakeLists.txt:11 (enable_language):
  The CMAKE_C_COMPILER:

    aarch64-linux-gnu-gcc

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.

From my experimentation, the issue can be solved either

  • by making sure we don't try to reference a cross-compiler if we don't cross-compile
  • by using aarch64 instead of arm64 in the triplet (though having multiple arm64 triplets would probably only cause confusion)

JavierMatosD pushed a commit that referenced this pull request Apr 19, 2024
#35084 introduced a regression for native ARM Linux builds where the
toolchain would mistakenly try to reference a cross-compiler (e.g.
`aarch64-linux-gnu-gcc`) despite building natively because vcpkg spells
the architecture differently from what the system reports (`arm64` vs.
`aarch64`).

This fixes the issue by checking whether the
`CMAKE_HOST_SYSTEM_PROCESSOR` matches the target (in CMake's spelling of
the architecture).

---------

Co-authored-by: Kai Pastor <dg0yt@darc.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly info:reviewed Pull Request changes follow basic guidelines requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants