Zulip Chat Archive

Stream: mathlib4

Topic: macos sonoma


Matthew Ballard (Jul 25 2023 at 13:58):

I got excited about the new snoopy watch face and it ended up with me installing the (first) public beta for MacOS Sonoma. I figured a short report would be useful to some.

Good news (so far): everything already on my machine seems to work ok (including homebrew and nix).

Bad news: Linking libc++.1.dylib fails when compiling cache or runLinter. I guess (I couldn't figure where this was set) rpath is pointing at ./lake-packages/**/build/lib/ because that was where it tried to look for the missing library. I ended up copying the file from my nix store there and was able to do all the usual things with a fresh copy of mathlib.

Sebastian Ullrich (Jul 25 2023 at 13:59):

That's good to know. Could you elaborate on "linking fails"?

Matthew Ballard (Jul 25 2023 at 14:01):

Let me regenerate the error message

Matthew Ballard (Jul 25 2023 at 14:03):

ld64.lld: warning: directory not found for option -L/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib
dyld[46325]: Library not loaded: @rpath/libc++.1.dylib
  Referenced from: <4C4C4449-5555-3144-A15E-70B77DDF95AA> /Users/matt/GitHub/scratch/extra_scratch/mathlib4/build/bin/cache
  Reason: tried: './lake-packages/proofwidgets/build/lib/libc++.1.dylib' (no such file), './lake-packages/Cli/build/lib/libc++.1.dylib' (no such file), './build/lib/libc++.1.dylib' (no such file), './lake-packages/Qq/build/lib/libc++.1.dylib' (no such file), './lake-packages/aesop/build/lib/libc++.1.dylib' (no such file), './lake-packages/std/build/lib/libc++.1.dylib' (no such file)

Sebastian Ullrich (Jul 25 2023 at 14:04):

I see, that's interesting. We do ship libc++.dylib, now we'd just have to find out why the same clang suddenly decides to choose a different library

Matthew Ballard (Jul 25 2023 at 14:06):

Is there a difference with libc++.1.dylib or is that just a copy?

Sebastian Ullrich (Jul 25 2023 at 14:06):

It's probably a symlink even

Matthew Ballard (Jul 25 2023 at 14:08):

It's seems to physically be in my ./lake-packages/proofwidgets/build/lib (lol).

Sebastian Ullrich (Jul 25 2023 at 14:09):

uhh

Matthew Ballard (Jul 25 2023 at 14:09):

That was my doing

Matthew Ballard (Jul 25 2023 at 14:11):

Perhaps related: it seems the xcode version from ventura is no longer compatible with sonoma. There is a beta for the new version. I installed that plus the beta command line tools but it appeared to have no effect

Sebastian Ullrich (Jul 25 2023 at 14:11):

The Lean toolchain should be completely separate from xcode

Sebastian Ullrich (Jul 25 2023 at 14:11):

Which is why I'm confused that updating the OS broke this

Matthew Ballard (Jul 25 2023 at 14:11):

So it should be searching in ./elan/toolchains/***/?

Sebastian Ullrich (Jul 25 2023 at 14:13):

Oh you are right, those paths are not even listed under "tried". Could you copy the failed cmdline Lake invoked and append a -v?

Matthew Ballard (Jul 25 2023 at 14:16):

I am calling lake exe cache get! and -v seems to have no effect on the output. lake exe runLinter has the same behavior

Matthew Ballard (Jul 25 2023 at 14:19):

I get more info if I run lake -v exe cache get! from a fresh clone.

info: [9/9] Linking cache
info: > /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/bin/leanc -o ./build/bin/cache ./build/ir/Cache/Main.o ./build/ir/Cache/IO.o ./build/ir/Cache/Hashing.o ./build/ir/Cache/Requests.o
info: stderr:
ld64.lld: warning: directory not found for option -L/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib
dyld[48368]: Library not loaded: @rpath/libc++.1.dylib
  Referenced from: <4C4C4449-5555-3144-A15E-70B77DDF95AA> /Users/matt/GitHub/scratch/extra_scratch/mathlib4/build/bin/cache
  Reason: tried: './lake-packages/proofwidgets/build/lib/libc++.1.dylib' (no such file), './lake-packages/Cli/build/lib/libc++.1.dylib' (no such file), './build/lib/libc++.1.dylib' (no such file), './lake-packages/Qq/build/lib/libc++.1.dylib' (no such file), './lake-packages/aesop/build/lib/libc++.1.dylib' (no such file), './lake-packages/std/build/lib/libc++.1.dylib' (no such file)

Matthew Ballard (Jul 25 2023 at 14:21):

For the warning it looks like some script is generating the file path from xcode version and os version. But that doesn't exist and didn't on Ventura either

Sebastian Ullrich (Jul 25 2023 at 14:23):

The warning is likely a red herring. Could you run

/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/bin/leanc -o ./build/bin/cache ./build/ir/Cache/Main.o ./build/ir/Cache/IO.o ./build/ir/Cache/Hashing.o ./build/ir/Cache/Requests.o -v

?

Matthew Ballard (Jul 25 2023 at 14:24):

/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/bin/clang -I /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/include -fstack-clash-protection -fvisibility=hidden -nostdinc -isystem /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/include/clang -o ./build/bin/cache ./build/ir/Cache/Main.o ./build/ir/Cache/IO.o ./build/ir/Cache/Hashing.o ./build/ir/Cache/Requests.o -v -L /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib -L /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib/libc -fuse-ld=lld -L /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib/lean -lleancpp -lInit -lLean -lleanrt -lc++ -L /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib -Wno-unused-command-line-argument
clang version 15.0.1 (https://github.com/llvm/llvm-project b73d2c8c720a8c8e6e73b11be4e27afa6cb75bdf)
Target: arm64-apple-darwin23.0.0
Thread model: posix
InstalledDir: /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/bin
 "/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/bin/ld64.lld" -demangle -dynamic -arch arm64 -platform_version macos 14.0.0 14.0.0 -o ./build/bin/cache -L/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib -L/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib/libc -L/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib/lean -L/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib ./build/ir/Cache/Main.o ./build/ir/Cache/IO.o ./build/ir/Cache/Hashing.o ./build/ir/Cache/Requests.o -lleancpp -lInit -lLean -lleanrt -lc++ -lSystem /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib/clang/15.0.1/lib/darwin/libclang_rt.osx.a
ld64.lld: warning: directory not found for option -L/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib

Matthew Ballard (Jul 25 2023 at 14:24):

The warning is on all MacOS versions afaik

Matthew Ballard (Jul 25 2023 at 14:25):

Did clang get upgraded with Sonoma?

Matthew Ballard (Jul 25 2023 at 14:26):

Yes. I think so

Sebastian Ullrich (Jul 25 2023 at 14:26):

Again, your system toolchain is completely separate from Lean's

Matthew Ballard (Jul 25 2023 at 14:27):

Ah ok. It ships with clang?

Sebastian Ullrich (Jul 25 2023 at 14:28):

Yes, see the beginning of the output

Matthew Ballard (Jul 25 2023 at 14:28):

Ok

Sebastian Ullrich (Jul 25 2023 at 14:28):

Oh, it's not linking that fails but loading! That makes more sense but doesn't make it easier...

Matthew Ballard (Jul 25 2023 at 14:29):

Yes, sorry. I should have been more clear

Sebastian Ullrich (Jul 25 2023 at 14:32):

Then I think we would need to find out what's the proper way of referencing libc++ on that OS. Since you have a system clang installed, could you try LEAN_CC=clang lake build cache?

Matthew Ballard (Jul 25 2023 at 14:32):

cache builds without errors

Sebastian Ullrich (Jul 25 2023 at 14:33):

Great! And what does otool -L say on the produced binary?

Matthew Ballard (Jul 25 2023 at 14:33):

build/bin/cache:
    @rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)

Sebastian Ullrich (Jul 25 2023 at 14:34):

Right :) . Did it actually rebuild? Could you try removing the binary and then run again with LEAN_CC?

Matthew Ballard (Jul 25 2023 at 14:35):

Yes, I just realized that

Matthew Ballard (Jul 25 2023 at 14:35):

That works!

Sebastian Ullrich (Jul 25 2023 at 14:35):

Nice, what does otool say now?

Matthew Ballard (Jul 25 2023 at 14:36):

It resolves to /usr/lib/libc++.1.dylib

Sebastian Ullrich (Jul 25 2023 at 14:38):

Mmh, it sounds like /usr/lib used to be implicitly in the rpath but is not anymore...?

Matthew Ballard (Jul 25 2023 at 14:38):

Same behavior as in Ventura

Matthew Ballard (Jul 25 2023 at 14:38):

That was my guess but I couldn't figure who was setting that

Sebastian Ullrich (Jul 25 2023 at 14:39):

It might simply be undocumented behavior of library resolution that has changed now

Matthew Ballard (Jul 25 2023 at 14:41):

I couldn't find anyone else complaining about with it a cursory google search

Matthew Ballard (Jul 25 2023 at 14:46):

Much thanks for the help!

Sebastian Ullrich (Jul 25 2023 at 14:51):

Let's see if we can move towards an upstreamable solution here. Could you run otool -D on the libc++ shipped with Lean?

Matthew Ballard (Jul 25 2023 at 14:52):

libclang-cpp.dylib? or am I looking in the wrong place

Matthew Ballard (Jul 25 2023 at 14:52):

Wrong place

Matthew Ballard (Jul 25 2023 at 14:53):

@rpath/libc++.1.dylib

Sebastian Ullrich (Jul 25 2023 at 14:54):

Okay, then let's try changing that by running install_name_tool -id /usr/lib/libc++.1.dylib on that file. Does that fix relinking and loading?

Matthew Ballard (Jul 25 2023 at 14:58):

Yes.

Sebastian Ullrich (Jul 25 2023 at 14:59):

Awesome, we can do just that in CI! Thanks for the productive remote debugging session :)

Matthew Ballard (Jul 25 2023 at 14:59):

Thank you!

Matthew Ballard (Jul 25 2023 at 15:18):

One more question if possible.

/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/bin/leanc -o ./build/bin/cache ./build/ir/Cache/Main.o ./build/ir/Cache/IO.o ./build/ir/Cache/Hashing.o ./build/ir/Cache/Requests.o -v

expands to

/Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/bin/clang -I /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/include -fstack-clash-protection -fvisibility=hidden -nostdinc -isystem /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/include/clang -o ./build/bin/cache ./build/ir/Cache/Main.o ./build/ir/Cache/IO.o ./build/ir/Cache/Hashing.o ./build/ir/Cache/Requests.o -v -L /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib -L /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib/libc -fuse-ld=lld -L /Users/matt/.elan/toolchains/leanprover--lean4---nightly-2023-07-12/lib/lean -lleancpp -lInit -lLean -lleanrt -lc++ -L /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib -Wno-unused-command-line-argument

what is generating the flag

-L /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib

since everyone on MacOS gets the warning

ld64.lld: warning: directory not found for option -L/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib

Sebastian Ullrich (Jul 25 2023 at 15:43):

It's probably this one, let's see: https://github.com/leanprover/lean4/pull/2356/commits/3a0daff81f65eebfab5969fc811c8f62b8439fe1

Sebastian Ullrich (Jul 26 2023 at 10:50):

@Matthew Ballard By the way, do you get any of these

ld64.lld: warning: /usr/lib/system/libsystem_kernel.dylib has version 12.6.0, which is newer than target minimum of 10.15.0

warnings on Sonoma?

Matthew Ballard (Jul 26 2023 at 11:05):

Those disappeared “on their own” while I was on Ventura (unless I never saw them). Not seen yet on Sonoma.

Sebastian Ullrich (Jul 26 2023 at 12:36):

Strange, one would assume the two versions would only diverge more. But then the PR should be ready to go.

Matthew Ballard (Jul 27 2023 at 15:14):

For those interested, nix just pulled down elan 2.0.1 so I think it is fully functional through the update (which hasn't always been the case).

Sebastian Ullrich (Jul 27 2023 at 15:55):

The elan version should not affect any of these

Matthew Ballard (Jul 27 2023 at 15:57):

Sorry. That was just a statement about the functionality of nix in the beta.

Sebastian Ullrich (Jul 27 2023 at 16:02):

Ah, that update :)

Matthew Ballard (Jul 31 2023 at 14:35):

Everything works great with a clean clone of current mathlib! (Just in time for the next beta lol).

Matthew Ballard (Jul 31 2023 at 14:36):

Thanks again @Sebastian Ullrich


Last updated: Dec 20 2023 at 11:08 UTC