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

/usr/include no longer exists on macOS 10.14 #365

Closed
elliottslaughter opened this issue Apr 4, 2019 · 14 comments
Closed

/usr/include no longer exists on macOS 10.14 #365

elliottslaughter opened this issue Apr 4, 2019 · 14 comments

Comments

@elliottslaughter
Copy link
Member

elliottslaughter commented Apr 4, 2019

On macOS 10.14 with an updated copy of the Command Line Tools, /usr/include no longer appears to exist. This means that Terra fails to find basic headers like math.h. Terra relies on Clang for this functionality, but a generic (non-Apple) Clang build doesn't seem to be smart enough to find it, at least as of LLVM 7.

A short-term workaround for this is to set INCLUDE_PATH to the location where headers are located. On my machine this is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include.

Hopefully in the longer term LLVM will be updated to be able to find the headers. Otherwise we'll have to find some way of locating them ourselves, and I can't think of any solution that isn't going to be very brittle. For example, running /usr/bin/clang++ -E -x c - -v < /dev/null prints the system search path, but I'm not sure we can depend on the output of this command being stable.

@pmccormick
Copy link
Contributor

pmccormick commented Apr 4, 2019 via email

@elliottslaughter
Copy link
Member Author

Confirmed that fixes the problem (actually it works better than my workaround). I guess we'll have to revisit this once that package gets removed.

@elliottslaughter
Copy link
Member Author

Adding a note to myself to check this again now that #412 has merged. It's possible this problem has finally been fixed.

@aiverson
Copy link
Contributor

On nixos global include directories do not exist either. This permits nixos to do things like have multiple major versions of dependencies simultaneously installed for different projects and switch versions around freely, however, it also causes problems when build scripts assume things like "the clang header and library files are this relative path from the LLVM header and library files." Since the build scripts make this assumption and I'm using nixos as my primary OS now (seriously, it's really great) is making my life developing this more difficult.

@elliottslaughter
Copy link
Member Author

elliottslaughter commented Oct 13, 2019

Let's split nixos off into a separate issue, because macOS still does (as I understand it) have a global location for headers, it's just off in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr (or something like that) now instead of /usr. In theory the new Clang auto-detect should be smart enough to see that, whereas on nixos I'm guessing the solution will be to either parse the value of CFLAGS that the OS gives you, or else to use some sort of scripting to construct the necessary INCLUDE_PATH.

@elliottslaughter
Copy link
Member Author

I got confirmation today that this has NOT been fixed by #412. So I guess Clang's auto-detect isn't smart enough. I do wonder how Apple's Clang manages to get it right though.

@elliottslaughter
Copy link
Member Author

elliottslaughter commented Jan 17, 2020

This gets even better: in macOS Catalina 10.15, the package mentioned above doesn't exist at all, so there's no way to get /usr/include back. The current best guess for a workaround is:

export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

Based on this comment: https://stackoverflow.com/questions/58278260/cant-compile-a-c-program-on-a-mac-after-upgrading-to-catalina-10-15#comment103258053_58323411

But I sure am not upgrading to find out if it works.

Edit: I can at least confirm that directory exists on macOS Mojave 10.14. But I can't really test if compilation with work with that fix because I installed the package above.

@elliottslaughter
Copy link
Member Author

Ok, the CPATH fix doesn't seem to work (and in fact, I can't tell what tools even obey CPATH in the first place).

Some searching around seems to indicate the solution is to set SDKROOT: oracle/truffleruby#1764

@nateberkopec
Copy link

nateberkopec commented Feb 18, 2020

export SDKROOT=`xcrun --show-sdk-path` works for me.

@jameshegarty
Copy link
Contributor

export INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include

Seemed to fix this for me on Catalina.

@elliottslaughter
Copy link
Member Author

I have a branch where I've been playing around with Github Actions, which uses Catalina. The line I've been using there is:

https://github.com/elliottslaughter/terra/blob/github-actions/travis.sh#L148

Though it compiles, the resulting Terra is not fully functional and several tests fail. So there's more debugging to be done here if someone has time/energy to do it.

elliottslaughter added a commit to elliottslaughter/terra that referenced this issue Apr 17, 2020
elliottslaughter added a commit that referenced this issue Apr 22, 2020
This commit enables Terra to build and pass all tests on macOS Mojave
without the installing the header package suggested in #365 (which
does not exist in macOS Catalina anyway).

Caveats:

  * It requires CMake. Make fails somewhere in the step where we run a
    Lua script to unpack the .a files.

  * It requires passing -DCMAKE_C_COMPILER=$(which CC), because
    apparently CMake tries to auto-detect the XCode installation, and
    LuaJIT can't build with that compiler.

  * It still requires setting INCLUDE_PATH="$(xcrun --sdk macosx
    --show-sdk-path)/usr/include". This may indicate we're still
    not getting all of the Clang initialization right.

  * It includes a workaround for LuaJIT/LuaJIT#575, which at the
    moment means we bump the deployment target to 10.7. Shouldn't
    matter for most users but if you want to use a LuaJIT 2.1 build
    from Git, this is now required.
@elliottslaughter
Copy link
Member Author

This isn't fully fixed, but if you follow the set of caveats listed in #435 (namely, setting -DCMAKE_C_COMPILER=$(which clang) at configure time and then exporting the environment variable INCLUDE_PATH="$(xcrun --sdk macosx --show-sdk-path)/usr/include") this should now work on both Mojave and Catalina without the need for the header package.

@elliottslaughter
Copy link
Member Author

elliottslaughter commented Feb 22, 2021

As of #481 Terra now supports SDKROOT. If you set that, then it should no longer be necessary to set INCLUDE_PATH explicitly.

Since this matches the behavior of Clang itself (see #479 (comment)), I'm going to consider this issue fixed.

Edit: for posterity, a typical setting of SDKROOT might look like:

export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"

@elliottslaughter
Copy link
Member Author

I confirmed as of #483 the workaround for the setting of CC is also no longer necessary. It may have been fixed by SDKROOT, or by an unrelated XCode or CLT change, I'm not sure.

So as of this comment, the ONLY setting that is required is SDKROOT:

export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"

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

No branches or pull requests

5 participants