From 25ce656a7601de0ccb8d684531d9acd0037e169d Mon Sep 17 00:00:00 2001 From: Siddhartha Bagaria Date: Mon, 16 Jan 2023 22:56:50 -0800 Subject: [PATCH] Fixes for macOS (#177) With newer versions of macOS, LLVM and Bazel, a few things have changed and need to be accounted. - Chained fixups is a new feature that generates a warning when dynamic lookup is used for undefined symbols. Bazel's default local toolchain has now removed the dynamic lookups (see /~https://github.com/bazelbuild/bazel/issues/16413). However, the issue is a little more complex, so we keep it for now and document the ongoing resolution threads between Apple and the community. - Bazel 6.0.0 onwards have started using @loader_path; we need to update the wrapper script to handle these options accordingly. - Some basic test fixes for macOS M1 when an LLVM distribution is available, e.g. for LLVM version 15.0.0. --- tests/WORKSPACE | 4 ++++ tests/openssl/openssl.bazel | 1 + tests/scripts/bazel.sh | 2 +- tests/scripts/run_external_tests.sh | 8 +++++++- toolchain/cc_toolchain_config.bzl | 3 +++ toolchain/osx_cc_wrapper.sh.tpl | 2 ++ 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/WORKSPACE b/tests/WORKSPACE index 1df0d83f..5ac1e7e9 100644 --- a/tests/WORKSPACE +++ b/tests/WORKSPACE @@ -25,6 +25,10 @@ bazel_toolchain_dependencies() load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain") +# Latest LLVM version is 15.0.6 as of this writing but OS support is rather +# sparse for all our container tests and some cgo tests crash with LLVM 15. +# TODO: Consider keeping the container tests to be on 14.0.0 when not supported +# by 15.0.6. LLVM_VERSION = "14.0.0" llvm_toolchain( diff --git a/tests/openssl/openssl.bazel b/tests/openssl/openssl.bazel index c8bbf211..34795609 100644 --- a/tests/openssl/openssl.bazel +++ b/tests/openssl/openssl.bazel @@ -172,6 +172,7 @@ genrule( "perl $(location crypto/x86_64cpuid.pl) $$FLAVOR $(location crypto/x86_64cpuid.s)", "perl $(location engines/asm/e_padlock-x86_64.pl) $$FLAVOR $(location engines/e_padlock-x86_64.s)", ]), + target_compatible_with = ["@platforms//cpu:x86_64"], ) cc_library( diff --git a/tests/scripts/bazel.sh b/tests/scripts/bazel.sh index 0ce75e2f..299d3bca 100644 --- a/tests/scripts/bazel.sh +++ b/tests/scripts/bazel.sh @@ -18,7 +18,7 @@ readonly os arch="$(uname -m)" if [[ "${arch}" == "x86_64" ]]; then arch="amd64" -elif [[ "${arch}" == "aarch64" ]]; then +elif [[ "${arch}" == "aarch64" ]] || [[ "${arch}" == "arm64" ]]; then arch="arm64" else >&2 echo "Unknown architecture: ${arch}" diff --git a/tests/scripts/run_external_tests.sh b/tests/scripts/run_external_tests.sh index 4a9be549..91fec13a 100755 --- a/tests/scripts/run_external_tests.sh +++ b/tests/scripts/run_external_tests.sh @@ -25,10 +25,16 @@ cd "${scripts_dir}" "${bazel}" fetch @io_bazel_rules_go//tests/core/cgo:all "$("${bazel}" info output_base)/external/io_bazel_rules_go/tests/core/cgo/generate_imported_dylib.sh" +test_args=( + "${common_test_args[@]}" + # Options needed for LLVM 15 when we switch to using it for these tests + #"--copt=-Wno-deprecated-builtins" # /~https://github.com/abseil/abseil-cpp/issues/1201 +) + # We exclude the following targets: # - cc_libs_test from rules_go because it assumes that stdlibc++ has been dynamically linked, but we # link it statically on linux. -"${bazel}" --bazelrc=/dev/null test "${common_test_args[@]}" -- \ +"${bazel}" --bazelrc=/dev/null test "${test_args[@]}" -- \ //foreign:pcre \ @openssl//:libssl \ @rules_rust//test/unit/{native_deps,linkstamps,interleaved_cc_info}:all \ diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 49679e28..2419578b 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -147,6 +147,9 @@ def cc_toolchain_config( use_lld = False link_flags.extend([ "-headerpad_max_install_names", + # This will issue a warning on macOS ventura; see: + # /~https://github.com/python/cpython/issues/97524 + # https://developer.apple.com/forums/thread/719961 "-undefined", "dynamic_lookup", ]) diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 484c55e3..0384cec6 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -42,6 +42,8 @@ function parse_option() { LIBS="${BASH_REMATCH[1]} $LIBS" elif [[ "$opt" =~ ^-L(.*)$ ]]; then LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS" + elif [[ "$opt" =~ ^\@loader_path/(.*)$ ]]; then + RPATHS="${BASH_REMATCH[1]} ${RPATHS}" elif [[ "$opt" =~ ^-Wl,-rpath,\@loader_path/(.*)$ ]]; then RPATHS="${BASH_REMATCH[1]} ${RPATHS}" elif [[ "$opt" = "-o" ]]; then