From c050450e61f94b11c226784762e2b665d956c533 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 27 Mar 2025 16:14:40 -0700 Subject: [PATCH 1/2] Delete osx_cc_wrapper.sh This was only used to fix the install_name of shared libraries, which is now obsolete since they are set correctly by the crosstool with `-install_name`. --- crosstool/BUILD.tpl | 2 - crosstool/cc_toolchain_config.bzl | 12 +-- crosstool/osx_cc_wrapper.sh.tpl | 139 ------------------------------ 3 files changed, 4 insertions(+), 149 deletions(-) delete mode 100755 crosstool/osx_cc_wrapper.sh.tpl diff --git a/crosstool/BUILD.tpl b/crosstool/BUILD.tpl index 7e9b2c0a..acada16a 100644 --- a/crosstool/BUILD.tpl +++ b/crosstool/BUILD.tpl @@ -46,7 +46,6 @@ filegroup( filegroup( name = "tools", srcs = [ - "@build_bazel_apple_support//crosstool:exec_cc_wrapper", "@build_bazel_apple_support//crosstool:exec_libtool", "@build_bazel_apple_support//crosstool:exec_wrapped_clang", "@build_bazel_apple_support//crosstool:exec_wrapped_clang_pp", @@ -81,7 +80,6 @@ filegroup( features = [ %{features} ], - cc_wrapper = "@build_bazel_apple_support//crosstool:exec_cc_wrapper", cxx_builtin_include_directories = [ %{cxx_builtin_include_directories} ], diff --git a/crosstool/cc_toolchain_config.bzl b/crosstool/cc_toolchain_config.bzl index 612ceab0..0a759bb9 100644 --- a/crosstool/cc_toolchain_config.bzl +++ b/crosstool/cc_toolchain_config.bzl @@ -309,7 +309,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new ], tools = [ tool( - tool = ctx.file.cc_wrapper, + tool = ctx.file.wrapped_clang, execution_requirements = xcode_execution_requirements, ), ], @@ -532,7 +532,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new ], tools = [ tool( - tool = ctx.file.cc_wrapper, + tool = ctx.file.wrapped_clang, execution_requirements = xcode_execution_requirements, ), ], @@ -599,7 +599,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new ], tools = [ tool( - tool = ctx.file.cc_wrapper, + tool = ctx.file.wrapped_clang, execution_requirements = xcode_execution_requirements, ), ], @@ -2678,7 +2678,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new "ar": ctx.file.libtool.path, "cpp": "/usr/bin/cpp", "dwp": "/usr/bin/dwp", - "gcc": ctx.file.cc_wrapper.path, + "gcc": ctx.file.wrapped_clang.path, "gcov": "/usr/bin/gcov", "ld": "/usr/bin/ld", "nm": "/usr/bin/nm", @@ -2714,10 +2714,6 @@ cc_toolchain_config = rule( implementation = _impl, attrs = { "cpu": attr.string(mandatory = True), - "cc_wrapper": attr.label( - allow_single_file = True, - mandatory = True, - ), "cxx_builtin_include_directories": attr.string_list(), "extra_env": attr.string_dict(), "libtool": attr.label( diff --git a/crosstool/osx_cc_wrapper.sh.tpl b/crosstool/osx_cc_wrapper.sh.tpl deleted file mode 100755 index 979358be..00000000 --- a/crosstool/osx_cc_wrapper.sh.tpl +++ /dev/null @@ -1,139 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# OS X relpath is not really working. This is a wrapper script around gcc -# to simulate relpath behavior. -# -# This wrapper uses install_name_tool to replace all paths in the binary -# (bazel-out/.../path/to/original/library.so) by the paths relative to -# the binary. It parses the command line to behave as rpath is supposed -# to work. -# -# See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac -# on how to set those paths for Mach-O binaries. -# -set -eu - -LIBS= -LIB_PATHS= -LIB_DIRS= -RPATHS= -OUTPUT= - -function parse_option() { - local -r opt="$1" - if [[ "${OUTPUT}" = "1" ]]; then - OUTPUT=$opt - elif [[ "$opt" =~ ^-l(.*)$ ]]; then - LIBS="${BASH_REMATCH[1]} $LIBS" - elif [[ "$opt" =~ ^(.*)\.so$ ]]; then - LIB_PATHS="${opt} $LIB_PATHS" - elif [[ "$opt" =~ ^(.*)\.dylib$ ]]; then - LIB_PATHS="${opt} $LIB_PATHS" - elif [[ "$opt" =~ ^-L(.*)$ ]]; then - LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS" - elif [[ "$opt" =~ ^\@loader_path/(.*)$ ]]; then - RPATHS="${BASH_REMATCH[1]} ${RPATHS}" - elif [[ "$opt" = "-o" ]]; then - # output is coming - OUTPUT=1 - fi -} - -# let parse the option list -for i in "$@"; do - if [[ "$i" = @* && -r "${i:1}" ]]; then - while IFS= read -r opt - do - parse_option "$opt" - done < "${i:1}" || exit 1 - else - parse_option "$i" - fi -done - -# wrapped_clang uses the path it's called as to relativize paths, so we cannot -# call it using an absolute path -script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -relative_script_path=${script_path##*"$(pwd)"/} -"$relative_script_path"/wrapped_clang "$@" - -# Generate an empty file if header processing succeeded. -if [[ "${OUTPUT}" == *.h.processed ]]; then - echo -n > "${OUTPUT}" -fi - -function get_library_path() { - for libdir in ${LIB_DIRS}; do - if [ -f ${libdir}/lib$1.so ]; then - echo "${libdir}/lib$1.so" - elif [ -f ${libdir}/lib$1.dylib ]; then - echo "${libdir}/lib$1.dylib" - fi - done -} - -# A convenient method to return the actual path even for non symlinks -# and multi-level symlinks. -function get_realpath() { - local previous="$1" - local next=$(readlink "${previous}") - while [ -n "${next}" ]; do - previous="${next}" - next=$(readlink "${previous}") - done - echo "${previous}" -} - -# Get the path of a lib inside a tool -function get_otool_path() { - # the lib path is the path of the original lib relative to the workspace - get_realpath $1 | sed 's|^.*/bazel-out/|bazel-out/|' -} - -function call_install_name() { - /usr/bin/xcrun install_name_tool -change $(get_otool_path "$1") \ - "@loader_path/$2/$3" "${OUTPUT}" -} - -# TODO: Remove when --incompatible_macos_set_install_name is not disable-able -# Do replacements in the output -for rpath in ${RPATHS}; do - for lib in ${LIBS}; do - unset libname - if [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.so" ]; then - libname="lib${lib}.so" - elif [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.dylib" ]; then - libname="lib${lib}.dylib" - fi - # ${libname-} --> return $libname if defined, or undefined otherwise. This is to make - # this set -e friendly - if [[ -n "${libname-}" ]]; then - libpath=$(get_library_path ${lib}) - if [ -n "${libpath}" ]; then - call_install_name "${libpath}" "${rpath}" "${libname}" - fi - fi - done - for libpath in ${LIB_PATHS}; do - if [ -f "$libpath" ]; then - libname=$(basename "$libpath") - if [ -f "$(dirname ${OUTPUT})/${rpath}/${libname}" ]; then - call_install_name "${libpath}" "${rpath}" "${libname}" - fi - fi - done -done From 032b73cd68f8f28253a4cc3856fd20caebee8e3d Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 28 Mar 2025 10:46:31 -0700 Subject: [PATCH 2/2] encode that this is required --- crosstool/BUILD | 14 +------------- crosstool/cc_toolchain_config.bzl | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/crosstool/BUILD b/crosstool/BUILD index 28766f6b..407842f8 100644 --- a/crosstool/BUILD +++ b/crosstool/BUILD @@ -1,5 +1,5 @@ load("@build_bazel_apple_support//rules:apple_genrule.bzl", "apple_genrule") -load(":universal_exec_tool.bzl", "force_exec", "universal_exec_tool") +load(":universal_exec_tool.bzl", "universal_exec_tool") package(default_visibility = ["//visibility:public"]) @@ -34,18 +34,6 @@ universal_exec_tool( out = "libtool", ) -genrule( - name = "exec_cc_wrapper.target_config", - srcs = ["osx_cc_wrapper.sh.tpl"], - outs = ["cc_wrapper.sh"], - cmd = "cp $(SRCS) $(OUTS)", # Make sure this script is always beside wrapped_clang -) - -force_exec( - name = "exec_cc_wrapper", - target = ":exec_cc_wrapper.target_config", -) - # TODO: Remove when we drop bazel 6.x filegroup( name = "xcrunwrapper", diff --git a/crosstool/cc_toolchain_config.bzl b/crosstool/cc_toolchain_config.bzl index 0a759bb9..aeba9d5d 100644 --- a/crosstool/cc_toolchain_config.bzl +++ b/crosstool/cc_toolchain_config.bzl @@ -2311,7 +2311,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new set_install_name = feature( name = "set_install_name", - enabled = getattr(ctx.fragments.cpp, "do_not_use_macos_set_install_name", True), + enabled = True, flag_sets = [ flag_set( actions = [