NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.37k stars 13.59k forks source link

`__OSX_AVAILABLE_STARTING` error when building on macOS 10.14 #63046

Open ktf opened 5 years ago

ktf commented 5 years ago

Issue description

When building something on macOS 10.14, using today's nixpkgs I get:

/nix/store/lki08vfid5qgxc3niygjxq6w2yy3s02k-apple-framework-Security/Library/Frameworks/Security.framework/Headers/SecCertificate.h:146:5: error:
      expected function body after function declarator
    __OSX_AVAILABLE_STARTING(__MAC_10_12_4, __IPHONE_10_3);

which is then followed by a bunch of undefined references to Security.framework structs. Am I missing anything trivial?

Steps to reproduce

Technical details

→ which clang
/nix/store/1af9gw0gimxrhzzf5zbhajzs9110ff6p-clang-wrapper-7.1.0/bin/clang
matthewbauer commented 5 years ago

Could you post a reproduction of what you are running?

ktf commented 5 years ago

The reproduction is a bit complicated as it involves a nix environment which is then used to build our software with an internal tool. There must be something completely screwed up with what I do, however, since if I use the following shell.nix:

{
  pkgs ? import <nixpkgs-unstable> { },
}:

pkgs.mkShell {
  buildInputs = [
    pkgs.darwin.apple_sdk.sdk
  ];
}

and I try to compile:

#include "cmath"

using std::signbit;

with:

[nix-shell:~/.../active/test-new-clang]$ which clang
/nix/store/1af9gw0gimxrhzzf5zbhajzs9110ff6p-clang-wrapper-7.1.0/bin/clang

[nix-shell:~/.../active/test-new-clang]$ clang++ foo.cc

I get a bunch of errors, while using the clang from Xcode works just fine.

ktf commented 5 years ago

For the record:

[nix-shell:~/.../active/test-new-clang]$ clang++ -M foo.cc
foo.o: foo.cc \
  /nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath \
  /nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/__config \
  /nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/math.h \
  /nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/sys/cdefs.h \
  /nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/sys/_symbol_aliasing.h \
  /nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/sys/_posix_availability.h \
  /nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/Availability.h \
  /nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/AvailabilityInternal.h
ktf commented 5 years ago

The actual error is:

In file included from foo.cc:1:
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:315:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^
/nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/math.h:757:12: note: 'finite' declared here
extern int finite(double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
           ^
In file included from foo.cc:1:
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:316:9: error: no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:317:9: error: no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:318:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:319:9: error: no member named 'isgreater' in the global namespace
using ::isgreater;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:320:9: error: no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:321:9: error: no member named 'isless' in the global namespace
using ::isless;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:322:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:323:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:324:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:331:9: error: no member named 'abs' in the global namespace; did you mean 'fabs'?
using ::abs;
      ~~^
/nix/store/jhv0xgbr6slpzcwmig1776ivg9c6vshy-MacOS_SDK-10.12-dev/include/math.h:431:15: note: 'fabs' declared here
extern double fabs(double);
              ^
In file included from foo.cc:1:
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:551:28: error: expected a qualified name after 'typename'
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
                           ^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:551:37: error: expected ';' at end of declaration
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
                                    ^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:551:37: error: expected unqualified-id
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:563:39: error: use of undeclared identifier 'is_floating_point'
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
                                      ^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:563:57: error: '_A1' does not refer to a value
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
                                                        ^
/nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/cmath:561:17: note: declared here
template <class _A1>
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
ktf commented 5 years ago

(all this used to work before moving to the latest nixpkgs with the 10.12 migration, BTW).

ktf commented 5 years ago

(thank you for taking the time to look into it, BTW)...

matthewbauer commented 5 years ago

If you just need the frameworks, you can do:

{
  pkgs ? import <nixpkgs-unstable> { },
}:

pkgs.mkShell {
  buildInputs = [
    pkgs.darwin.apple_sdk.sdk.out
  ];
}

This avoids including any of the sdk 10.12 headers which appear to interfere with libc++. Maybe we should provide versioned sdk releases? Something like pkgs.darwin.apple_sdk.sdk_10_10 for users who need it. Presumably you just need to frameworks, but headers may also be needed?

ktf commented 5 years ago

Mmm... I think I would need also some header, so I am not sure if that would work. That said, it looks like that results in an even more "complicated" business with clang5 and clang7 headers mixing:

[nix-shell:~/.../active/test-new-clang]$ clang++ -M foo.cc
foo.o: foo.cc \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/cmath \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/__config \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/math.h \
  /nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/math.h \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/type_traits \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/cstddef \
  /nix/store/l5y9lragp239hsmrxq7dacwrbskni8qy-libc++-7.1.0/include/c++/v1/stddef.h \
  /nix/store/kcjs7m2ydcaqck4npqsr0wph3xmh2c4l-clang-wrapper-5.0.2/resource-root/include/stddef.h \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/__nullptr \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/limits \
  /nix/store/c3gsacyfdnfjh0f7d4jjq6zwy6fp8mgy-libc++-5.0.2/include/c++/v1/__undef_macros

[nix-shell:~/.../active/test-new-clang]$ clang++ --version
clang version 5.0.2 (tags/RELEASE_502/final)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /nix/store/p2yxcpcg920s5lx64hz0ajr11hja930v-clang-5.0.2/bin

I guess that is the culprit, albeit I am not sure why I get clang5 from the old configuration... Maybe it's due to the fact I use lorri to setup the environment for that same folder...

ktf commented 5 years ago

Ok... After a bit of fiddling I think I found a small reproducer for what is the actual issue:

$ cat foo.mm
#include <Cocoa/Cocoa.h>
#include <set>

std::set<CFFileDescriptorRef> foo;
$ cat shell.nix
{
  pkgs ? import <nixpkgs-unstable> { },
}:
pkgs.mkShell {
  buildInputs = [
    # pkgs.glew
    pkgs.darwin.cf-private
    pkgs.darwin.objc4
    pkgs.darwin.apple_sdk.frameworks.Cocoa
    pkgs.darwin.apple_sdk.frameworks.OpenGL
    pkgs.darwin.apple_sdk.frameworks.CoreServices
    pkgs.darwin.apple_sdk.frameworks.CoreText
    pkgs.darwin.CoreSymbolication
    pkgs.darwin.usr-include
  ];
}

and then:

$ clang++ -c foo.mm

works fine. If I comment out the pkgs.glew line I get:

foo.mm:4:10: error: unknown type name 'CFFileDescriptorRef'; did you mean 'CTFontDescriptorRef'?
std::set<CFFileDescriptorRef> foo;
         ^~~~~~~~~~~~~~~~~~~
         CTFontDescriptorRef
/nix/store/nhng8ibgs7bdyyw26cx73dvkn3a9x7ci-apple-framework-CoreText/Library/Frameworks/CoreText.framework/Headers/CTFontDescriptor.h:46:7
typedef const struct CF_BRIDGED_TYPE(NSFontDescriptor) __CTFontDescriptor * CTFontDescriptorRef;
ktf commented 5 years ago

More on this. The actual issue seems the inclusion of:

pkgs.darwin.apple_sdk.frameworks.AGL

(which is done by glew...)

stale[bot] commented 3 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.