Skip to content

[WIP, RFC] Use relative paths for __FILE__ #1861

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

Closed
wants to merge 4 commits into from

Conversation

jakirkham
Copy link
Member

Description

Explore using GCC's -fmacro-prefix-map to remap __FILE__ from absolute paths to source directory relative paths.

Related to issue: rapidsai/build-planning#159

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Copy link

copy-pr-bot bot commented Mar 14, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions bot added the conda label Mar 14, 2025
@jakirkham jakirkham added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function conda and removed conda labels Mar 14, 2025
@jakirkham
Copy link
Member Author

/ok to test

@jakirkham
Copy link
Member Author

jakirkham commented Mar 15, 2025

The builds completed. Though CI is marked as errored. Not seeing a specific error in the logs. The only thing that sticks out are these warnings:

│ │ ⚠ warning Warnings:
 │ │ ⚠ warning Overdepending against cuda-cudart
 │ │ ⚠ warning Overdepending against __glibc

Are these warnings being treated as errors?

@jakirkham
Copy link
Member Author

Ah maybe it is this error during the upload step where the tree command is not found?

/__w/_temp/51babaa4-efec-4e3b-b633-23f9d878e32a.sh: line 2: tree: command not found

Did something change in our GHA workflow? Or CI images?

@jakirkham
Copy link
Member Author

jakirkham commented Mar 15, 2025

Looks like this CI error will be fixed by this GHA workflow update: rapidsai/shared-workflows#299

Edit: We need to wait for the nightly job on branch-25.04 to rerurn. Then we can restart here

Edit 2: This is now cleared up. Turns out a new GHA run (instead of restarting) picks up the shared workflow fix

@jakirkham
Copy link
Member Author

/ok to test

Copy link
Member Author

@jakirkham jakirkham left a comment

Choose a reason for hiding this comment

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

Added a few comments below providing more details about the changes

Comment on lines +24 to +30
# Remove `-fdebug-prefix-map` line from CFLAGS and CXXFLAGS so the
# incrementing version number in the compile line doesn't break the
# cache
set -x
export CFLAGS=$(echo $CFLAGS | sed -E 's@\-fdebug\-prefix\-map[^ ]*@@g')
export CXXFLAGS=$(echo $CXXFLAGS | sed -E 's@\-fdebug\-prefix\-map[^ ]*@@g')
set +x
Copy link
Member Author

Choose a reason for hiding this comment

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

Have copied the stripping of the existing -fdebug-prefix-map over from librmm:

content: |
# Remove `-fdebug-prefix-map` line from CFLAGS and CXXFLAGS so the
# incrementing version number in the compile line doesn't break the
# cache
set -x
export CFLAGS=$(echo $CFLAGS | sed -E 's@\-fdebug\-prefix\-map[^ ]*@@g')
export CXXFLAGS=$(echo $CXXFLAGS | sed -E 's@\-fdebug\-prefix\-map[^ ]*@@g')
set +x

We would want this in both builds for the same reasons

Comment on lines +32 to +37
# Use relative paths for `__FILE__` by passing `-fmacro-prefix-map`
# https://gcc.gnu.org/onlinedocs/gcc-13.3.0/gcc/Preprocessor-Options.html#index-fmacro-prefix-map
set -x
export CFLAGS="${CFLAGS} -fmacro-prefix-map=$(pwd)/=''"
export CXXFLAGS="${CXXFLAGS} -fmacro-prefix-map=$(pwd)/=''"
set +x
Copy link
Member Author

Choose a reason for hiding this comment

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

As $(pwd) is the top-level directory of this repo, passing the -fmacro-prefix-map option simply removes the $(pwd) portion of the path in all __FILE__ expansions. Thus leaving us with paths relative to the top of the repo

A couple things we may want to consider:

  1. Moving this into our CMake logic for all builds
  2. Applying this behavior to more prefix mappings. -ffile-prefix-map would do this for all prefix-mapping cases GCC handles

Beyond fixing the __FILE__ expansion this gets us closer to reproducible builds. Also it should behave more robustly with caching (though we should test to confirm)

Copy link
Contributor

@bdice bdice Mar 17, 2025

Choose a reason for hiding this comment

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

I like this approach. I would consider merging this as-is, and doing (1) or (2) as follow-up work.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also support this approach here. I think this is a good idea. I suggest that we try and put this into rapids-cmake so that we get this for free in all our libraries. The main challenge I see with that is identifying the appropriate root path to use. I agree with Bradley that I'm OK with doing that as a follow-up if you want to get this PR merged sooner. I can open a suitable rapids-cmake issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried to describe what this would look like in the context of rapids-cmake: rapidsai/rapids-cmake#798 (comment)

Though am sure it can be improved further. Please feel free to suggest there

@jakirkham
Copy link
Member Author

Put together an example here: conda/conda-build#1674 (comment)

@bdice
Copy link
Contributor

bdice commented Mar 17, 2025

This is really nice. I'm 100% supportive of this approach!

# cache
set -x
export CFLAGS=$(echo $CFLAGS | sed -E 's@\-fdebug\-prefix\-map[^ ]*@@g')
export CXXFLAGS=$(echo $CXXFLAGS | sed -E 's@\-fdebug\-prefix\-map[^ ]*@@g')
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also export this in CUDAFLAGS I expect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Tried to capture a better recommendation here: rapidsai/rapids-cmake#798 (comment)

Please feel free to suggest further improvements

@jakirkham
Copy link
Member Author

Closing in favor of addressing this in RAPIDS-CMake via PR: rapidsai/rapids-cmake#817

@jakirkham jakirkham closed this Apr 9, 2025
@github-project-automation github-project-automation bot moved this from Review to Done in RMM Project Board Apr 9, 2025
@jakirkham jakirkham deleted the use_rel_pth_prefix branch April 9, 2025 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conda improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants