Page MenuHomeFreeBSD

cross-build make.py: Handle lld brew packages on macOS
ClosedPublic

Authored by jhb on Thu, Jul 31, 1:03 PM.
Tags
None
Referenced Files
F125909821: D51653.diff
Wed, Aug 13, 5:19 AM
F125887120: D51653.id159493.diff
Tue, Aug 12, 11:13 PM
F125881415: D51653.id159767.diff
Tue, Aug 12, 9:51 PM
Unknown Object (File)
Mon, Aug 11, 4:21 AM
Unknown Object (File)
Sun, Aug 10, 12:01 PM
Unknown Object (File)
Sun, Aug 10, 9:01 AM
Unknown Object (File)
Wed, Aug 6, 9:25 PM
Unknown Object (File)
Sat, Aug 2, 6:17 AM
Subscribers

Details

Summary

Homebrew uses separate packages for llvm and lld starting with llvm19.
To handle this case automatically, pass the binary_name to
default_cross_toolchain() and only use the automatic path for a given
binary if the binary is found in the path (not just if the directory
exists). Add a second clause for ld.lld that looks for a lld package
if lld wasn't found in the llvm directory.

Note that manually specifying the path cannot use a single
--cross-bindir option. Instead, XLD must be manually set in addition
to --cross-bindir when requesting a specific version.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65974
Build 62857: arc lint + arc unit

Event Timeline

jhb requested review of this revision.Thu, Jul 31, 1:03 PM

Note that currently on my MacBook the default version of llvm (llvm20) doesn't finish a buildworld because llvm20 raises an error for libc++ headers from llvm19 when building some google test stuff, but it does get pretty far:

===> lib/googletest/gtest (all)
/opt/homebrew/opt/llvm/bin/clang++  -target x86_64-unknown-freebsd15.0 --sysroot=/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp -B/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/bin  -O2 -pipe -fno-common -g -gz=zlib -MD -MF.depend.gtest-all.o -MTgtest-all.o -Wno-format-zero-length -nobuiltininc -idirafter /opt/homebrew/Cellar/llvm/20.1.3/lib/clang/20/include -fstack-protector-strong -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wchar-subscripts -Wdate-time -Wmissing-variable-declarations -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-parameter -Wno-error=cast-function-type-mismatch -Qunused-arguments   -I/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/private  -I/Users/jhb/work/git/freebsd/contrib/googletest/googletest/include -I/Users/jhb/work/git/freebsd/contrib/googletest/googletest -g -gz=zlib -std=gnu++17 -Wno-deprecated-copy       -c /Users/jhb/work/git/freebsd/contrib/googletest/googletest/src/gtest-all.cc -o gtest-all.o
In file included from /Users/jhb/work/git/freebsd/contrib/googletest/googletest/src/gtest-all.cc:38:
In file included from /Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/private/gtest/gtest.h:55:
In file included from /Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/memory:944:
In file included from /Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/__memory/inout_ptr.h:16:
In file included from /Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/__memory/shared_ptr.h:31:
/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/__memory/uninitialized_algorithms.h:645:22: error: first argument in call to '__builtin_memcpy' is a pointer to non-trivially copyable type '__remove_const_t<string>' (aka 'std::string') [-Werror,-Wnontrivial-memcall]
  645 |     __builtin_memcpy(const_cast<__remove_const_t<_Tp>*>(__result), __first, sizeof(_Tp) * (__last - __first));
      |                      ^
/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/vector:1052:8: note: in instantiation of function template specialization 'std::__uninitialized_allocator_relocate<std::allocator<std::string>, std::string>' requested here
 1052 |   std::__uninitialized_allocator_relocate(
      |        ^
/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/vector:1502:3: note: in instantiation of member function 'std::vector<std::string>::__swap_out_circular_buffer' requested here
 1502 |   __swap_out_circular_buffer(__v);
      |   ^
/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/vector:1514:13: note: in instantiation of function template specialization 'std::vector<std::string>::__push_back_slow_path<const std::string &>' requested here
 1514 |     __end = __push_back_slow_path(__x);
      |             ^
/Users/jhb/work/git/freebsd/contrib/googletest/googletest/src/gtest-death-test.cc:1381:8: note: in instantiation of member function 'std::vector<std::string>::push_back' requested here
 1381 |   args.push_back(filter_flag);
      |        ^
/Users/jhb/obj/Users/jhb/work/git/freebsd/amd64.amd64/tmp/usr/include/c++/v1/__memory/uninitialized_algorithms.h:645:22: note: explicitly cast the pointer to silence this warning
  645 |     __builtin_memcpy(const_cast<__remove_const_t<_Tp>*>(__result), __first, sizeof(_Tp) * (__last - __first));
      |                      ^
1 error generated.
*** Error code 1

Stop.
bmake[6]: stopped making "all" in /Users/jhb/work/git/freebsd/lib/googletest/gtest
*** Error code 1

Stop.
bmake[5]: stopped making "all" in /Users/jhb/work/git/freebsd/lib/googletest
*** Error code 1

Stop.
bmake[4]: stopped making "all" in /Users/jhb/work/git/freebsd/lib
*** Error code 1

Stop.
bmake[3]: stopped making "_generic_libs" in /Users/jhb/work/git/freebsd
*** Error code 1

Stop.
bmake[2]: stopped making "libraries" in /Users/jhb/work/git/freebsd
*** Error code 1

Stop.
bmake[1]: stopped making "buildworld" in /Users/jhb/work/git/freebsd
*** Error code 1

Stop.
bmake: stopped making "buildworld buildkernel" in /Users/jhb/work/git/freebsd

This looks sensible to me. One suggestion would be to avoid the manual caching.

tools/build/make.py
209

Instead of manually caching I wonder if it would be better to just use functools.cache

@functools.cache
def llvm_dir():
    ...

Or maybe even better to handle both of llvm and lld:

@functools.cache
def brew_prefix(package):
    ...
This revision is now accepted and ready to land.Mon, Aug 4, 8:12 PM

This looks sensible to me. One suggestion would be to avoid the manual caching.

Huh, TIL. I will rework this to use that. One thought I had is that it might be nice if we could specify a toolchain by "name" somehow, similar to how CROSS_TOOLCHAIN works, so something like --toolchain llvm19.

Use functools.cache and refactor

This revision now requires review to proceed.Tue, Aug 5, 1:38 PM
jhb marked an inline comment as done.Tue, Aug 5, 8:17 PM
arichardson added inline comments.
tools/build/make.py
190–203

Maybe better to do the decode in the brew_prefix function?

Feel free to ignore the type hints suggestion, the only reason I didn't initially include them in this script is that it originally had to support ancient python versions.

This revision is now accepted and ready to land.Tue, Aug 5, 11:13 PM
jhb marked an inline comment as done.Wed, Aug 6, 3:07 PM