urbit / vere

An implementation of the Urbit runtime
MIT License
59 stars 39 forks source link

Problem building on macOs Monterey #131

Open pkova opened 1 year ago

pkova commented 1 year ago

OS version: 12.6.2 (21G320)

Tried the steps in the guide at INSTALL.md, also tried the solutions in #119.

Pyrys-MacBook-Pro:vere pkova$ bazel clean --expunge
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.
Pyrys-MacBook-Pro:vere pkova$ bazel --version
bazel 6.0.0
Pyrys-MacBook-Pro:vere pkova$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Pyrys-MacBook-Pro:vere pkova$ brew info automake
==> automake: stable 1.16.5 (bottled)
Tool for generating GNU Standards-compliant Makefiles
https://www.gnu.org/software/automake/
/usr/local/Cellar/automake/1.16.5 (131 files, 3.5MB) *
  Poured from bottle on 2023-01-15 at 15:35:23
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/automake.rb
License: GPL-2.0-or-later
==> Dependencies
Required: autoconf ✔
==> Analytics
install: 58,627 (30 days), 178,144 (90 days), 736,041 (365 days)
install-on-request: 39,115 (30 days), 122,671 (90 days), 488,706 (365 days)
build-error: 8 (30 days)
Pyrys-MacBook-Pro:vere pkova$ brew info libtool
==> libtool: stable 2.4.7 (bottled)
Generic library support script
https://www.gnu.org/software/libtool/
/usr/local/Cellar/libtool/2.4.7 (75 files, 3.8MB) *
  Poured from bottle on 2022-09-27 at 17:21:45
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libtool.rb
License: GPL-2.0-or-later
==> Dependencies
Required: m4 ✔
==> Caveats
All commands have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
  PATH="/usr/local/opt/libtool/libexec/gnubin:$PATH"
==> Analytics
install: 196,137 (30 days), 646,533 (90 days), 3,404,165 (365 days)
install-on-request: 26,660 (30 days), 84,118 (90 days), 429,625 (365 days)
build-error: 13 (30 days)

The first error I encountered is below. Some quick googling brought me to this. The fix was importing unistd.h before this line in pkg/ent/ent.c. https://github.com/urbit/vere/blob/98cbc349cf93058d9f3da2a84791ed4e8167b0ec/pkg/ent/ent.c#L15

Pyrys-MacBook-Pro:vere pkova$ bazel build --clang_version="12.0.0" --verbose_failures :urbit
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:urbit (76 packages loaded, 10846 targets configured).
INFO: Found 1 target...
WARNING: /Users/pkova/Desktop/vere/BUILD.bazel:144:8: input '.git' to //:version is a directory; dependency checking of directories is unsound
INFO: From Linking external/softfloat/libsoftfloat_x86_64.a:
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: bazel-out/darwin-fastbuild/bin/external/softfloat/libsoftfloat_x86_64.a(s_countLeadingZeros16.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: bazel-out/darwin-fastbuild/bin/external/softfloat/libsoftfloat_x86_64.a(s_countLeadingZeros32.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: bazel-out/darwin-fastbuild/bin/external/softfloat/libsoftfloat_x86_64.a(s_countLeadingZeros64.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: bazel-out/darwin-fastbuild/bin/external/softfloat/libsoftfloat_x86_64.a(s_mul64ByShifted32To128.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: bazel-out/darwin-fastbuild/bin/external/softfloat/libsoftfloat_x86_64.a(s_mul64To128.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: bazel-out/darwin-fastbuild/bin/external/softfloat/libsoftfloat_x86_64.a(s_mul128By32.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: bazel-out/darwin-fastbuild/bin/external/softfloat/libsoftfloat_x86_64.a(s_mul128To256M.o) has no symbols
INFO: From Compiling deps/libyrmcds/counter.c:
external/h2o/deps/libyrmcds/counter.c:212:18: warning: implicit conversion loses integer precision: 'yrmcds_cnt_command' to 'uint8_t' (aka 'unsigned char') [-Wimplicit-int-conversion]
    r->command = (yrmcds_cnt_command)c->recvbuf[1];
               ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/h2o/deps/libyrmcds/counter.c:213:17: warning: implicit conversion loses integer precision: 'yrmcds_cnt_status' to 'uint8_t' (aka 'unsigned char') [-Wimplicit-int-conversion]
    r->status = (yrmcds_cnt_status)c->recvbuf[2];
              ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
ERROR: /Users/pkova/Desktop/vere/pkg/ent/BUILD.bazel:5:11: Compiling pkg/ent/ent.c failed: (Exit 1): clang failed: error executing command (from target //pkg/ent:ent) 
  (cd /private/var/tmp/_bazel_pkova/7da81147f29e30d81d8599eb0dba1610/sandbox/darwin-sandbox/329/execroot/__main__ && \
  exec env - \
    BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \
    PATH=/Users/pkova/Library/Caches/bazelisk/downloads/bazelbuild/bazel-6.0.0-darwin-x86_64/bin:/usr/local/opt/ruby/bin:/Users/pkova/.cargo/bin:/Users/pkova/.nvm/versions/node/v19.0.0/bin:/Users/pkova/.nix-profile/bin:/Users/pkova/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin \
    PWD=/proc/self/cwd \
  /usr/bin/clang -MD -MF bazel-out/darwin-fastbuild/bin/pkg/ent/_objs/ent/ent.d '-frandom-seed=bazel-out/darwin-fastbuild/bin/pkg/ent/_objs/ent/ent.o' -DENT_GETENTROPY_SYSRANDOM '-DBAZEL_CURRENT_REPOSITORY=""' -iquote . -iquote bazel-out/darwin-fastbuild/bin -Ibazel-out/darwin-fastbuild/bin/pkg/ent/_virtual_includes/ent -isystem pkg/ent -isystem bazel-out/darwin-fastbuild/bin/pkg/ent -g -O3 -O3 -Wall -Werror -pedantic '-std=gnu99' -c pkg/ent/ent.c -o bazel-out/darwin-fastbuild/bin/pkg/ent/_objs/ent/ent.o)
# Configuration: cd136eed1be80cb273330eb5168236c66ee4d8157a90fd826cc557297fbe3bca
# Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from pkg/ent/ent.c:15:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/random.h:36:21: error: expected parameter declarator
    __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
                    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/random.h:36:21: error: expected ')'
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/random.h:36:20: note: to match this '('
    __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
                   ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/random.h:36:28: error: expected function body after function declarator
    __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
                           ^
pkg/ent/ent.c:17:10: error: implicit declaration of function 'getentropy' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  return getentropy(buf, len);
         ^
4 errors generated.
Target //pkg/vere:urbit failed to build
INFO: Elapsed time: 30.882s, Critical Path: 13.46s
INFO: 343 processes: 19 internal, 324 darwin-sandbox.
FAILED: Build did NOT complete successfully

After bazel clean --expunge and trying again with this fix I run up against errors like this:

ERROR: /Users/pkova/Desktop/vere/pkg/urcrypt/BUILD.bazel:5:11: Compiling pkg/urcrypt/argon.c failed: undeclared inclusion(s) in rule '//pkg/urcrypt:urcrypt':
this rule is missing dependency declarations for the following files included by 'pkg/urcrypt/argon.c':
  '/usr/local/include/blake2.h

I can fix each of these by manually copying in the correct header file but that takes forever and is obviously incorrect.

mcevoypeter commented 1 year ago

I suspect this is because we're erroneously using #include <> instead of #include "" for when referring to header files from some of the dependencies we're building ourselves. Can you switch to i/131/macos-build, which fixes #include issue I just mentioned, and try again?

pkova commented 1 year ago

That got me further, ran into this issue next:

ERROR: /private/var/tmp/_bazel_pkova/7da81147f29e30d81d8599eb0dba1610/external/h2o/BUILD.bazel:243:11: Compiling lib/core/util.c failed: undeclared inclusion(s) in rule '@h2o//:h2o':
this rule is missing dependency declarations for the following files included by 'lib/core/util.c':
  '/usr/local/include/uv.h'
  '/usr/local/include/uv/errno.h'
  '/usr/local/include/uv/version.h'
  '/usr/local/include/uv/unix.h'
  '/usr/local/include/uv/threadpool.h'
  '/usr/local/include/uv/darwin.h'
Target //pkg/vere:urbit failed to build
pkova commented 1 year ago

Note that trying to build from i/131/macos-build without my fix to pkg/ent/ent.c will fail with the same error as in the original issue.

mcevoypeter commented 1 year ago

@pkova I think the h2o is using #include <> for some of the dependencies we're building ourselves, namely libuv, openssl, and curl. I updated the h2o patch to use #include "" instead, which should pick up the versions of those dependencies we're building. I also included the macOS #include <sys/random.h> fix you linked to above. Can you pull and try again?

pkova commented 1 year ago

Now I'm running into this one. No permutation of double quotes or < > seems to do the trick either.

ERROR: /Users/pkova/Desktop/vere/pkg/urcrypt/BUILD.bazel:5:11: Compiling pkg/urcrypt/argon.c failed: undeclared inclusion(s) in rule '//pkg/urcrypt:urcrypt':
this rule is missing dependency declarations for the following files included by 'pkg/urcrypt/argon.c':
  '/usr/local/include/blake2.h'
mcevoypeter commented 1 year ago

Can you try installing clang with brew and running with the brew-installed clang toolchain:

$ brew install clang
$ bazel build --clang_version="14.0.6" --extra_toolchains=//bazel/toolchain:brew-clang-macos-x86_64-toolchain :urbit

We ran into a similar issue on the macos-x86_64 CI runners, and using the brew-installed clang toolchain worked in that case. Also note you can put the extra options in .user.bazelrc to avoid typing them every time i.e. the above bazel build command is equivalent to:

$ echo 'build --clang_version=14.0.6' >> .user.bazelrc
$ echo 'build --extra_toolchains=//bazel/toolchain/brew-clang-macos-x86_64-toolchain' >> .user.bazelrc
# From now on, you can simply type `bazel build :urbit`.
$ bazel build :urbit
pkova commented 1 year ago

No dice. After trying an ungodly amount of permutations of clang versions and messing with sys_includes for brew-clang-macos-x86_64-config in /bazel/toolchain/BUILD.bazel the best I've been able to do is have it compile 736/739 steps and then seemingly infinitely loop on compiling /pkg/noun/allocate.c.

mcevoypeter commented 1 year ago

That sounds like https://github.com/urbit/urbit/issues/5561. Try commenting out build --copt='-g' in .bazelrc. If that doesn't work, maybe try adjusting the optimization level via --copt i.e. --copt='-O2'.

pkova commented 1 year ago

Thank god, I was about to end it all. I made #147 with my changes.

mcevoypeter commented 1 year ago

It turns out the system-provided clang on macos-x86_64 has /usr/local/include in its set of include paths, whereas the system-provided clang on macos-aarch64 does not. You can confirm this by running clang -v -x c - -v /dev/null on both platforms. @pkova, your change to include /usr/local/include turned out to be correct. I'm going to put up a new PR, which includes a few other changes to the macOS toolchains' include paths (to ensure parity with the output of clang -v -x c - -v /dev/null).