Skip to content

Commit de1012f

Browse files
authored
In conda-build produced binaries, use paths relative to $PREFIX (#817)
Fixes #798 Add compiler flags in conda-build runs to remap binary embedded paths from absolute paths (with `$PREFIX`) to `$PREFIX` relative paths. This keeps the meaningful portion of the path while dropping the build time specific `$PREFIX`. Plus bypasses the need to do prefix replacement with these paths. <hr> Authors: - https://github.com/jakirkham - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Kyle Edwards (https://github.com/KyleFromNVIDIA) - Vyas Ramasubramani (https://github.com/vyasr) - Bradley Dice (https://github.com/bdice) - Robert Maynard (https://github.com/robertmaynard) URL: #817
1 parent 4f203ce commit de1012f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

rapids-cmake/cmake/support_conda_env.cmake

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#=============================================================================
2-
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
2+
# Copyright (c) 2021-2025, NVIDIA CORPORATION.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -41,6 +41,14 @@ the behavior of conda when it builds projects.
4141
The `target_name` target will add the required compile flags to ensure debug builds
4242
are generated with `-O0` instead of the conda env default of `-O2`.
4343
44+
.. versionadded:: v25.06.00
45+
46+
The flag `-ffile-prefix-map` is now passed to remap absolute paths starting
47+
with `$ENV{PREFIX}` to paths relative to it in binaries generated via
48+
compilation. This ensures paths baked into binaries are relative to the
49+
environment prefix. This prevents Conda from rewriting these paths when the
50+
package is installed.
51+
4452
Also offers the ability to modify :cmake:variable:`CMAKE_PREFIX_PATH <cmake:variable:CMAKE_PREFIX_PATH>` to
4553
include the following paths based on the current conda environment:
4654
@@ -164,6 +172,14 @@ function(rapids_cmake_support_conda_env target)
164172
"$<HOST_LINK:SHELL:LINKER:-rpath-link=$ENV{BUILD_PREFIX}/lib>")
165173
endif()
166174

175+
# For built binaries (like libraries), remap environment absolute paths (`$PREFIX/<path>`) to
176+
# paths relative to the environment `$PREFIX` (`<path>`).
177+
target_compile_options(${target}
178+
INTERFACE "$<$<COMPILE_LANGUAGE:C>:-ffile-prefix-map=$ENV{PREFIX}/=''>"
179+
"$<$<COMPILE_LANGUAGE:CXX>:-ffile-prefix-map=$ENV{PREFIX}/=''>"
180+
"$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-ffile-prefix-map=$ENV{PREFIX}/=''>"
181+
)
182+
167183
if(modify_prefix_path)
168184
message(VERBOSE "Conda build detected")
169185
set(prefix_paths "$ENV{PREFIX}" "$ENV{BUILD_PREFIX}")

0 commit comments

Comments
 (0)