Skip to content
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

cc_library.additional_compiler_inputs should be subject to $(location ...) substitution #23885

Closed
filmil opened this issue Oct 7, 2024 · 5 comments

Comments

@filmil
Copy link

filmil commented Oct 7, 2024

Description of the feature request:

Consider the following situation. I'm trying to compile libfst from https://github.com/gtkwave/gtkwave/tree/master/lib/libfst

Now, someone had the great idea to do #include FST_CONFIG_INCLUDE in fstapi.c here: https://github.com/gtkwave/gtkwave/blob/master/lib/libfst/fstapi.c#L41

This, of course, conflicts with bazel's idea about file placement. I added the file config.h, but it wouldn't go into either srcs or hdrs of the target :libfst below:

  1 cc_library(                                                                                                                               
  2     name = "libfst",                                                                                                                      
  3     srcs = [ "@libfst//:all_c"],                                                                                                          
  4     hdrs = [ "@libfst//:all_h",],                                                                                                         
  5     deps = [                                                                                                                              
  6     ¦   "//third_party/libjudy",                                                                                                          
  7     ],                                                                                                                                    
  8     defines = [                                                                                                                           
  9     ¦   'FST_CONFIG_INCLUDE=\\"third_party/libfst/config.h\\"',                                                                           
 10     ],                                                                                                                                    
 11     additional_compiler_inputs = [                                                                                                        
 12     ¦   ":config",                                                                                                                        
 13     ]
 14                                                                                                                                           
 15
 16 filegroup(                                                                                                                                
 17     name = "config",                                                                                                                      
 18     srcs = [ "config.h" ],                                                                                                                
 19 )                                                                                                                     
 14 )     

I wanted to define FST_CONFIG_INCLUDE=\\"$(location :config)\\", but this would not do because additional_compiler_inputs is not subject to $(location ...) substitution apparently. Placing the file elsewhere, e.g. in deps would allow it, but since deps requires CCInfo or some such, then I can't place the filegroup there. The :config target can not be a cc_library since that leads to:

ERROR: /home/fmil/tmp/bazel_delib/third_party/libfst/BUILD.bazel:1:11: in cc_library rule //third_party/libfst:libfst: label '//third_party/libfst:config' in $(location) expression expands to no files

Which category does this issue belong to?

No response

What underlying problem are you trying to solve with this feature?

I want to refer to a $(location) in a cc_library.defines.

Which operating system are you running Bazel on?

Linux. I don't think that maters.

What is the output of bazel info release?

╰─>$ bazel info release release 7.3.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@keith
Copy link
Member

keith commented Oct 7, 2024

i think this is what you want? #23102

@filmil
Copy link
Author

filmil commented Oct 7, 2024

If you can do $(location ...) in defines or local_defines, I suppose so.

I am not seeing a test for both? But I don't know what the difference is.

@keith
Copy link
Member

keith commented Oct 7, 2024

we're not adding it to defines, related quote from that thread:

but I would suggest disabling expansion for defines. There is no way to add files to downstream compilation actions, so it also wouldn't make sense to emit paths into them.

@filmil
Copy link
Author

filmil commented Oct 7, 2024

Oh, so defines will propagate downstream? I don't think my bug has a use case for that. So I suppose local_defines only is fine.

bazel-io pushed a commit to bazel-io/bazel that referenced this issue Oct 10, 2024
Fixes bazelbuild#23885

Closes bazelbuild#23102.

PiperOrigin-RevId: 684433748
Change-Id: I12cdb9a04f930a52e57bbd8551c8f2559a15932a
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Oct 10, 2024
Fixes bazelbuild#23885

Closes bazelbuild#23102.

PiperOrigin-RevId: 684433748
Change-Id: I12cdb9a04f930a52e57bbd8551c8f2559a15932a
github-merge-queue bot pushed a commit that referenced this issue Oct 10, 2024
…es (#23939)

Fixes #23885

Closes #23102.

PiperOrigin-RevId: 684433748
Change-Id: I12cdb9a04f930a52e57bbd8551c8f2559a15932a

Commit
c2d316b

Co-authored-by: Keith Smiley <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Oct 10, 2024
…es (#23940)

Fixes #23885

Closes #23102.

PiperOrigin-RevId: 684433748
Change-Id: I12cdb9a04f930a52e57bbd8551c8f2559a15932a

Commit
c2d316b

Co-authored-by: Keith Smiley <[email protected]>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.4.0 RC1. Please test out the release candidate and report any issues as soon as possible.
If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=7.4.0rc1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants