Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/buildsystems/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_
set(Z_VCPKG_TARGET_TRIPLET_PLAT openbsd)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "NetBSD"))
set(Z_VCPKG_TARGET_TRIPLET_PLAT netbsd)
elseif(CMAKE_SYSTEM_NAME STREQUAL "DragonFly" OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "DragonFly"))
set(Z_VCPKG_TARGET_TRIPLET_PLAT dragonfly)
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "SunOS"))
set(Z_VCPKG_TARGET_TRIPLET_PLAT solaris)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android" OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Android"))
Expand Down
6 changes: 6 additions & 0 deletions scripts/cmake/vcpkg_common_definitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
set(VCPKG_TARGET_IS_NETBSD ON)
set(VCPKG_TARGET_IS_BSD ON)
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
set(VCPKG_TARGET_IS_DRAGONFLY ON)
set(VCPKG_TARGET_IS_BSD ON)
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "SunOS")
set(VCPKG_TARGET_IS_SOLARIS ON)
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW")
Expand All @@ -62,6 +65,9 @@ elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "OpenBSD")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "NetBSD")
set(VCPKG_HOST_IS_NETBSD ON)
set(VCPKG_HOST_IS_BSD ON)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "DragonFly")
set(VCPKG_HOST_IS_DRAGONFLY ON)
set(VCPKG_HOST_IS_BSD ON)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "SunOS")
set(VCPKG_HOST_IS_SOLARIS ON)
endif()
Expand Down
2 changes: 1 addition & 1 deletion scripts/cmake/z_vcpkg_fixup_rpath.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function(z_vcpkg_fixup_rpath_in_dir)
)

execute_process(
COMMAND "${PATCHELF}" --set-rpath "${new_rpath}" "${elf_file}"
COMMAND "${PATCHELF}" --add-rpath "${new_rpath}" "${elf_file}"
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this is incorrect because it seems like it would append entries to the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one change is why I still have it marked as draft, the issue is some GCC versions that are in the official ports repository (including the default one if I recall correctly) set their own rpath which is needed for binaries to work. I'm not sure how to really deal with that in a different way.

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIU our script tries to set a combined rpath, with z_vcpkg_calculate_corrected_rpath considering the original rpath as reported by patch_elf.
And there is a test port, scripts/test_ports/vcpkg-fix-rpath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIU our script tries to set a combined rpath, with z_vcpkg_calculate_corrected_rpath considering the original rpath as reported by patch_elf. And there is a test port, scripts/test_ports/vcpkg-fix-rpath.

Right but as far as I can tell there's no handling for system rpaths. I noticed something similar on NetBSD where official GCC 14 sets the rpath to "/usr/pkg/gcc14/x86_64--netbsd/lib/.:/usr/pkg/gcc14/lib/." and this just gets overriden by vcpkg. This can get fixed by just setting a correct LD_LIBRARY_PATH but that's really a half fix, what should really be done?

Copy link
Contributor

Choose a reason for hiding this comment

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

What is meant by "system rpath" in your answer?

What is the final rpath which want for a given "system rpath" and executable in the vcpkg installed tree? Give a concrete example, as if writing a test case.

What I see is that our script calls "${PATCHELF}" --print-rpath "${elf_file}". Doesn't this include the rpath which is to be retained?

If yes, then we know that it is passed as readelf_output to

            z_vcpkg_calculate_corrected_rpath(
              ELF_FILE_DIR "${elf_file_dir}"
              ORG_RPATH "${readelf_output}"
              OUT_NEW_RPATH_VAR new_rpath
            )

Doesn't the output new_rpath include the rpath which is to be retained?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is meant by "system rpath" in your answer?

When the rpath is set by the compiler by default (and really as a requirement) because the system libraries for the specific compiler are not in the default dynamic linker path. NetBSD and DragonFly use this when you have multiple versions of GCC installed each with their own version of libstdc++, etc.

What is the final rpath?

This log shows that the rpath is read correctly, it just gets replaced entirely by vcpkg:

-- Adjusted RPATH of ... (From '/usr/pkg/gcc14/x86_64--netbsd/lib/.:/usr/pkg/gcc14/lib/.:lib' -> To '$ORIGIN:$ORIGIN/../../lib')

And once again checking with patchelf after the install:

$ patchelf --print-rpath ...
$ORIGIN:$ORIGIN/../../lib

Copy link
Contributor

Choose a reason for hiding this comment

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

The current default behavior is to only keep entries with $ORIGIN.
There is an X_VCPKG_RPATH_KEEP_SYSTEM_PATHS variable to keep all entries - you could set in the triplet file.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Yes, it will keep all entries, including those set by the port. I'm not sure this is the solution. The alternative is to provide/detect what the compiler sets in a controlled way, and put this on a positive list.)

OUTPUT_QUIET
ERROR_VARIABLE set_rpath_error
)
Expand Down
56 changes: 56 additions & 0 deletions scripts/toolchains/dragonfly.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
if(NOT _VCPKG_DRAGONFLY_TOOLCHAIN)
set(_VCPKG_DRAGONFLY_TOOLCHAIN 1)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "DragonFly")
set(CMAKE_CROSSCOMPILING OFF CACHE BOOL "")
endif()
set(CMAKE_SYSTEM_NAME DragonFly CACHE STRING "")

if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(CMAKE_SYSTEM_PROCESSOR x86_64 CACHE STRING "")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(CMAKE_SYSTEM_PROCESSOR x86 CACHE STRING "")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(CMAKE_SYSTEM_PROCESSOR arm64 CACHE STRING "")
else()
set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}" CACHE STRING "")
endif()
endif()

if(POLICY CMP0056)
cmake_policy(SET CMP0056 NEW)
endif()
if(POLICY CMP0066)
cmake_policy(SET CMP0066 NEW)
endif()
if(POLICY CMP0067)
cmake_policy(SET CMP0067 NEW)
endif()
if(POLICY CMP0137)
cmake_policy(SET CMP0137 NEW)
endif()
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
VCPKG_CRT_LINKAGE VCPKG_TARGET_ARCHITECTURE
VCPKG_C_FLAGS VCPKG_CXX_FLAGS
VCPKG_C_FLAGS_DEBUG VCPKG_CXX_FLAGS_DEBUG
VCPKG_C_FLAGS_RELEASE VCPKG_CXX_FLAGS_RELEASE
VCPKG_LINKER_FLAGS VCPKG_LINKER_FLAGS_RELEASE VCPKG_LINKER_FLAGS_DEBUG
)

string(APPEND CMAKE_C_FLAGS_INIT " -fPIC ${VCPKG_C_FLAGS} ")
string(APPEND CMAKE_CXX_FLAGS_INIT " -fPIC ${VCPKG_CXX_FLAGS} ")
string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " ${VCPKG_C_FLAGS_DEBUG} ")
string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " ${VCPKG_CXX_FLAGS_DEBUG} ")
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " ${VCPKG_C_FLAGS_RELEASE} ")
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " ${VCPKG_CXX_FLAGS_RELEASE} ")

string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ")
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ")
string(APPEND CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS_DEBUG} ")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS_DEBUG} ")
string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS_DEBUG} ")
string(APPEND CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT " ${VCPKG_LINKER_FLAGS_RELEASE} ")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT " ${VCPKG_LINKER_FLAGS_RELEASE} ")
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT " ${VCPKG_LINKER_FLAGS_RELEASE} ")
endif()
5 changes: 5 additions & 0 deletions triplets/community/x64-dragonfly.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME DragonFly)