microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.75k stars 6.29k forks source link

[dbus] Build failure when cross-compiling #40031

Open davidebeatrici opened 1 month ago

davidebeatrici commented 1 month ago

Editing the portfile to pass -DDBUS_SESSION_SOCKET_DIR=/tmp to CMake fixes the issue.

Operating system

macOS (ARM64)

Steps to reproduce the behavior

./vcpkg install dbus:x64-osx-release

Failure logs

CMake Error at CMakeLists.txt:574 (message):
  cannot autodetect session socket directory when crosscompiling, pass
  -DDBUS_SESSION_SOCKET_DIR=...

-- Configuring incomplete, errors occurred!
davidebeatrici commented 1 month ago

Also, the upstream logic looks wrong to me:

https://gitlab.freedesktop.org/dbus/dbus/-/blob/68637759b916a9d6a824a01318a55a76f7f08ec7/CMakeLists.txt#L565-L582

#### Find socket directories
set(DBUS_SESSION_SOCKET_DIR "" CACHE STRING "Default directory for session socket")
if(UNIX)
    if (CMAKE_CROSSCOMPILING)
        if (NOT DBUS_SESSION_SOCKET_DIR)
            message(FATAL_ERROR "cannot autodetect session socket directory "
                    "when crosscompiling, pass -DDBUS_SESSION_SOCKET_DIR=...")
        endif()
    elseif(NOT $ENV{TMPDIR} STREQUAL "")
        set(DBUS_SESSION_SOCKET_DIR $ENV{TMPDIR})
    elseif(NOT $ENV{TEMP} STREQUAL "")
        set(DBUS_SESSION_SOCKET_DIR $ENV{TEMP})
    elseif(NOT $ENV{TMP} STREQUAL "")
        set(DBUS_SESSION_SOCKET_DIR $ENV{TMP})
    else()
        set(DBUS_SESSION_SOCKET_DIR /tmp)
    endif()
endif()

On macOS the TMPDIR environment variable's value appears to be a unique path that is generated for the current process. I believe DBUS_SESSION_SOCKET_DIR should be set to /tmp instead.

dg0yt commented 1 month ago

Editing the portfile to pass -DDBUS_SESSION_SOCKET_DIR=/tmp to CMake fixes the issue.

The actual value should depend on the target system.

the upstream logic looks wrong to me

Apart from the potential macOS issue, the given code hides the cache variable (aka input variable) for native builds by setting a normal variable.

davidebeatrici commented 1 month ago

The actual value should depend on the target system.

I agree, that should (and probably can only be) done at runtime.

Apart from the potential macOS issue, the given code hides the cache variable (aka input variable) for native builds by setting a normal variable.

That too, good catch.

bwrsandman commented 1 month ago

Seeing this also with dbus:x86-linux

dg0yt commented 1 month ago

Seeing this also with dbus:x86-linux

Well, it is cross compiling if you are on a x64 host.