meson icon indicating copy to clipboard operation
meson copied to clipboard

CUDA compiler doesn't pass cuda_args to `links` check

Open bmerry opened this issue 1 year ago • 4 comments

Describe the bug When using meson.get_compiler('cpp').links(...), compiler options that the user has configured via -Dcpp_args=... are passed to the compiler, but meson.get_compiler('cuda').links(...) does not do the same with cuda_args.

To Reproduce meson.build:

project('detect', 'cpp', 'cuda')

foreach lang : ['cpp', 'cuda']
  compiler = meson.get_compiler(lang)
  compiler.links(
    '''
    #include <foo.h>
    int main() { return 0; }
    ''',
    name : f'foo (@lang@)',
  )
endforeach

Create foo.h as an empty file in the same directory. Run meson setup build -Dcpp_args=-I$PWD -Dcuda_args=-I$PWD (on a machine with CUDA). It will output

...
Checking if "foo (cpp)" : links: YES 
Checking if "foo (cuda)" : links: NO 
...

The logs show the command lines are respectively

  • c++ -I/home/bmerry/tmp/detect /home/bmerry/tmp/detect/build/meson-private/tmpy9zhzag9/testfile.cpp -o /home/bmerry/tmp/detect/build/meson-private/tmpy9zhzag9/output.exe -D_FILE_OFFSET_BITS=64 -O0 -fpermissive
  • nvcc /home/bmerry/tmp/detect/build/meson-private/tmp02_14frw/testfile.cu -o /home/bmerry/tmp/detect/build/meson-private/tmp02_14frw/output.exe -O0

Expected behavior The cuda behaviour should be changed to be consistent with the C++ behaviour, i.e., cuda_args are used in links() checks.

system parameters

  • Not a cross build
  • Ubuntu 20.04
  • Python 3.8.10
  • meson 1.2.1
  • ninja 1.11.1.git.kitware.jobserver-1

bmerry avatar Aug 28 '23 14:08 bmerry

From a quick look, it seems like the "clike" mixin has a much more thorough build_wrapper_args (in particular, it always adds {lang}_args even for link tests, which the generic Compiler class does not) than the cuda compiler does. I'm not sure why cuda doesn't inherit from clike, actually.

Probably @obilaniu or @SoapGentoo would have a better idea.

eli-schwartz avatar Aug 29 '23 01:08 eli-schwartz

we should inherit from clike, agreed

SoapGentoo avatar Aug 29 '23 09:08 SoapGentoo

@bmerry would you want to submit a fix? Sounds like the solution would be pretty small

tristan957 avatar Aug 31 '23 02:08 tristan957

@bmerry would you want to submit a fix? Sounds like the solution would be pretty small

I only started using meson a few weeks ago, so I don't feel like I have a firm enough grasp to understand all the implications of inheriting from Clike.

bmerry avatar Aug 31 '23 07:08 bmerry