Skip to content

In conda-build produced binaries, use paths relative to $PREFIX #817

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

Merged
merged 14 commits into from
Apr 21, 2025
18 changes: 17 additions & 1 deletion rapids-cmake/cmake/support_conda_env.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
# Copyright (c) 2021-2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,14 @@ the behavior of conda when it builds projects.
The `target_name` target will add the required compile flags to ensure debug builds
are generated with `-O0` instead of the conda env default of `-O2`.

.. versionadded:: v25.06.00

The flag `-ffile-prefix-map` is now passed to remap absolute paths starting
with `$ENV{PREFIX}` to paths relative to it in binaries generated via
compilation. This ensures paths baked into binaries are relative to the
environment prefix. This prevents Conda from rewriting these paths when the
package is installed.
Comment on lines +44 to +50
Copy link
Member Author

Choose a reason for hiding this comment

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

How about this revision?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like it


Also offers the ability to modify :cmake:variable:`CMAKE_PREFIX_PATH <cmake:variable:CMAKE_PREFIX_PATH>` to
include the following paths based on the current conda environment:

Expand Down Expand Up @@ -164,6 +172,14 @@ function(rapids_cmake_support_conda_env target)
"$<HOST_LINK:SHELL:LINKER:-rpath-link=$ENV{BUILD_PREFIX}/lib>")
endif()

# For built binaries (like libraries), remap environment absolute paths (`$PREFIX/<path>`) to
# paths relative to the environment `$PREFIX` (`<path>`).
target_compile_options(${target}
INTERFACE "$<$<COMPILE_LANGUAGE:C>:-ffile-prefix-map=$ENV{PREFIX}/=''>"
"$<$<COMPILE_LANGUAGE:CXX>:-ffile-prefix-map=$ENV{PREFIX}/=''>"
"$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-ffile-prefix-map=$ENV{PREFIX}/=''>"
)

if(modify_prefix_path)
message(VERBOSE "Conda build detected")
set(prefix_paths "$ENV{PREFIX}" "$ENV{BUILD_PREFIX}")
Expand Down