Repository: mesonbuild/meson

Issue:
gst-plugins-base fails on MacOS due to -fobjc-arc check
gst-plugins-base fails on MacOS with the following error:

```
Compiler for Objective-C supports arguments -fobjc-arc: NO 

gst-libs/gst/gl/meson.build:683:4: ERROR: Problem encountered: ARC is required for building
```

This happens because of this check:

https://gitlab.freedesktop.org/boxerab/gst-plugins-bad/commit/38c3d4ca7b8e562e1396b902bb6dea07155ed3aa

Digging into the logs, the failure is:

```
Working directory:  /Users/jenkins/jhbuild/checkout/gst-plugins-base-1.16.2/build/meson-private/tmpicamerlo
Command line:  cc -L/Users/jenkins/DCV_JHBUILD/inst/lib /Users/jenkins/jhbuild/checkout/gst-plugins-base-1.16.2/build/meson-private/tmpicamerlo/testfile.m -o /Users/jenkins/jhbuild/checkout/gst-plugins-base-1.16.2/build/meson-private/tmpicamerlo/output.obj -pipe -c -O0 -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -fobjc-arc 

Code:
 int i;

Compiler stdout:
 
Compiler stderr:
 clang: error: argument unused during compilation: '-L/Users/jenkins/DCV_JHBUILD/inst/lib' [-Werror,-Wunused-command-line-argument]

Compiler for Objective-C supports arguments -fobjc-arc: NO 

gst-libs/gst/gl/meson.build:683:4: ERROR: Problem encountered: ARC is required for building

```

So, basically it seems to fail because there are LDFLAGS in the env (which are set by jhbuild in this case).

Should meson be able to sanitize the env for these kind of checks?







Discussion:
I just had the same issue when compiling gst-plugins-base. If I look at the code from mesonbuild I see the following line:

`        myargs = ['-Werror=unknown-warning-option', '-Werror=unused-command-line-argument']`

https://github.com/mesonbuild/meson/blob/master/mesonbuild/compilers/mixins/clang.py#L64

If I change that line to look like this:

`        myargs = ['-Werror=unknown-warning-option']`

then the check works as expected. Thoughts?
@nirbheek how are you folks getting this built on osx? I would have expected a fail in your side as well...
> @nirbheek how are you folks getting this built on osx? I would have expected a fail in your side as well...

We've been running an old version of Meson in Cerbero (and we do not set `CFLAGS` or `LDFLAGS` with gst-build). I can reproduce it if I use the latest Meson. Investigating.
@nacho @pbor can you try #6668?
Sorry I was traveling. I can give it a try this week.
it seems to me that meson 0.54.1 still has this issue:
```
Compiler for Objective-C supports arguments -fobjc-arc: NO 
source_subfolder/gst-libs/gst/gl/meson.build:683:4: ERROR: Problem encountered: ARC is required for building
```

https://travis-ci.com/github/bincrafters/conan-gst-plugins-base/jobs/333029751#L782

```
Running compile:
Working directory:  /Users/travis/.conan/data/gst-plugins-base/1.16.0/bincrafters/macos/build/7801c3bc75f81248dfb5da7c3a7418467e2eac00/build_subfolder/meson-private/tmprcetksqf
Command line:  cc -I/Users/travis/.conan/data/gstreamer/1.16.0/bincrafters/stable/package/2fcb3ccf38527564935a47b8d8da77beeb7195d6/include/gstreamer-1.0 -I/Users/travis/.conan/data/glib/2.64.0/bincrafters/stable/package/2f35ff713084d1b9a9452ef9ed236a58748ab45c/include -I/Users/travis/.conan/data/glib/2.64.0/bincrafters/stable/package/2f35ff713084d1b9a9452ef9ed236a58748ab45c/include/glib-2.0 -I/Users/travis/.conan/data/glib/2.64.0/bincrafters/stable/package/2f35ff713084d1b9a9452ef9ed236a58748ab45c/lib/glib-2.0/include -I/Users/travis/.conan/data/libffi/3.2.1/_/_/package/f74366f76f700cc6e991285892ad7a23c30e6d47/include -I/Users/travis/.conan/data/pcre/8.41/_/_/package/d6dbf7bc4ba20d9c0937065aaab46dc0bba20c3a/include -I/Users/travis/.conan/data/libelf/0.8.13/_/_/package/8e2e3059f283d3d138b85d022534c5632c4ffd1b/include -I/Users/travis/.conan/data/libgettext/0.20.1/_/_/package/c1139b2191d107309c439b6c13962e1929121809/include -I/Users/travis/.conan/data/zlib/1.2.11/_/_/package/f74366f76f700cc6e991285892ad7a23c30e6d47/include -I/Users/travis/.conan/data/bzip2/1.0.8/_/_/package/32bef4803d4b079e983ecb27f105881e778bc5a7/include -I/Users/travis/.conan/data/libiconv/1.16/_/_/package/f74366f76f700cc6e991285892ad7a23c30e6d47/include /Users/travis/.conan/data/gst-plugins-base/1.16.0/bincrafters/macos/build/7801c3bc75f81248dfb5da7c3a7418467e2eac00/build_subfolder/meson-private/tmprcetksqf/testfile.m -o /Users/travis/.conan/data/gst-plugins-base/1.16.0/bincrafters/macos/build/7801c3bc75f81248dfb5da7c3a7418467e2eac00/build_subfolder/meson-private/tmprcetksqf/output.obj -pipe -c -DPCRE_STATIC=1 -DFFI_BUILDING -DNDEBUG -framework Foundation -framework CoreServices -framework CoreFoundation -m64 -O0 -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -fobjc-arc 

Code:
 int i;

Compiler stdout:
 
Compiler stderr:
 clang: error: -framework Foundation: 'linker' input unused [-Werror,-Wunused-command-line-argument]
clang: error: -framework CoreServices: 'linker' input unused [-Werror,-Wunused-command-line-argument]
clang: error: -framework CoreFoundation: 'linker' input unused [-Werror,-Wunused-command-line-argument]

Compiler for Objective-C supports arguments -fobjc-arc: NO 

gst-libs/gst/gl/meson.build:683:4: ERROR: Problem encountered: ARC is required for building
```
so the error comes from the `-framework` flags not being removed in https://github.com/mesonbuild/meson/commit/33fbc548ab74e79280d2f57b2cd499d14c1f1e91#diff-3c97ac47a5c89ea080e2e7afe851f45dR1069

Resolving patch:
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1136,7 +1136,7 @@ def get_undefined_link_args(self) -> T.List[str]:
     def remove_linkerlike_args(self, args):
         rm_exact = ('-headerpad_max_install_names',)
         rm_prefixes = ('-Wl,', '-L',)
-        rm_next = ('-L',)
+        rm_next = ('-L', '-framework',)
         ret = []
         iargs = iter(args)
         for arg in iargs:
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -5325,7 +5325,7 @@ def test_duplicate_rpath(self):
 
     def test_removing_unused_linker_args(self):
         testdir = os.path.join(self.common_test_dir, '108 has arg')
-        env = {'CFLAGS': '-L/tmp -L /var/tmp -headerpad_max_install_names -Wl,-export_dynamic'}
+        env = {'CFLAGS': '-L/tmp -L /var/tmp -headerpad_max_install_names -Wl,-export_dynamic -framework Foundation'}
         self.init(testdir, override_envvars=env)
 
 


Test patch: