mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.53k stars 1.61k forks source link

macos framework paths not found when using clang with -std=C++<ver> or std=gnu++<ver> external CXX args #13640

Open christophecvr opened 3 weeks ago

christophecvr commented 3 weeks ago

When building some packages with macports such as gstreamer1-plugins-bad for macos system and using xcode basic systems clang apple compiler or upgraded apple clang compiler sometimes extra CXX compiler args such as for this package -std=gnu++11 is required. When building package it issues a meson configure error:

Called: `/opt/local/bin/pkg-config --modversion CoreFoundation` -> 1
stderr:
Package CoreFoundation was not found in the pkg-config search path.
Perhaps you should add the directory containing `CoreFoundation.pc'
to the PKG_CONFIG_PATH environment variable
No package 'CoreFoundation' found
-----------
Finding framework path by running:  /usr/bin/clang++ -v -E - -pipe -Os -std=gnu++11 -stdlib=libc++ -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -I/opt/local/include -L/opt/local/lib -Wno-unused-command-line-argument -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk 

CMake binary for host machine is cached.
Preliminary CMake check failed. Aborting.
Run-time dependency corefoundation found: NO (tried pkgconfig, framework and cmake)

sys/applemedia/meson.build:42:21: ERROR: Dependency "CoreFoundation" not found, tried pkgconfig, framework and cmake

Further investigation showed that the issued framework find path command failed. I tried it in terminal on it's own. failure message :

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
<whole command ...>
error: invalid argument '-std=gnu++11' not allowed with 'C'

Due to the error which can't be silenced on clang compiler the command issues 1 and is broken result : framework path not found.

When searching further on the net this issue does show up very much in environments where clang and meson is used. this for -std=c++11,-std=gnu++11,-std=c++17 or -std=gnu++17 ....

The cause is that indeed those args are only allowed for C++/Gobj++ not for 'C'

I did finally found a simple (and do think a clean solution to this issue) : First :

My solution is just to omit the invalid flags for just the framework find path command how :

changing in file mesonbuild/compilers/mixins/clike.py line 1187-1195 from :

        # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
        # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        commands += env.coredata.get_external_args(self.for_machine, self.language)
        mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')

to :

        # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
        # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        # 'std=c++<ver>','std=gnu++<ver>' are valid for C++/ObjC++ but not for 'C'
        commands += [x for x in env.coredata.get_external_args(self.for_machine, self.language) if '-std=c++' not in x and '-std=gnu++' not in x]
        mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')

Then all the framwork paths are found again and project builds fine .

I will submit in short a pull request with this change. I just added this issue first so I can refer to this issue in pull request commit.

christophecvr commented 1 week ago

@dcbaker @eli-schwartz

This is really a build breaking bug on macos.

The last reference : was not right. I referenced to this issue in commit by accident. However another solution just for this command of which the goal is just to find the default systems main framework path the clang compiler is referring to and only works for macos with apples clang compilers. Is to limit the language used to objc or c . Then then the CXXFLAGS or OBJCXXFLAGS who may contain invalid flags for c are not used. The framework path will always be found.

Changing:

        # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
        # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        commands += env.coredata.get_external_args(self.for_machine, self.language)
        mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')

Into :

       # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
       # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        # For this command with clang only 'C' or 'Objc' is ok
        # With other compiler languages objcpp cpp CXXFLAGS and OBJCXXFLAGS are added
        # Some of this flags are not supported in C such as -std=C++<ver> -std=gnu++<ver> and ...
        # If project language is objcpp change it to objc if language is cpp change to c
        # This only applies for this specific command.
        # https://github.com/mesonbuild/meson/issues/13640
        if self.language == 'objcpp':
            commands += env.coredata.get_external_args(self.for_machine, 'objc')
        else:
            commands += env.coredata.get_external_args(self.for_machine, 'c')
        mlog.debug('Finding framework path by running:', ' '.join(commands), '\n')

Since there is no reply or even not a review on the pull request #13641 I of course did not issued another. It would really be nice if You review this . Since it is a serious bug of meson on macos platform when using clang.

christophecvr commented 1 week ago

Since there is no interest in this issue we keep running by patching self the meson for macos clang

close this issue since meson developpers are not interested in improving clang macos platform

christophecvr commented 1 week ago

Just leave open since it's still there

dcbaker commented 1 week ago

It's not that we're not interested, but none of us are payed to work on Meson full time, and only one of us has a mac. It's much easier to review patches than it is to write them for a platform that we don't have direct access too.

christophecvr commented 1 week ago

,

It's not that we're not interested, but none of us are payed to work on Meson full time, and only one of us has a mac. It's much easier to review patches than it is to write them for a platform that we don't have direct access too.

Ok thanks