From 4956dff50d21a3346c1a63985910df10fccfd90b Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Mon, 23 Sep 2024 14:55:07 +0200 Subject: [PATCH] [7.4.0] Fix `runtime_solib_name` for `--incompatible_macos_set_install_name` (#23672) The `runtime_solib_name` link variable had an incorrect value in the case of a transitive dynamic library. Since non-transitive ("nodeps") dynamic libraries are no longer used on macOS, the `--incompatible_macos_set_install_name` flag didn't have any positive effect. This PR is intentionally limited to the fix so that it can be cherry-picked into Bazel 7, where it can make the incompatible flag work with the `apple_support` toolchain. A follow-up PR will add the feature to the Unix toolchain and flip the incompatible flag for Bazel 8. Work towards #12370 Closes #23089. PiperOrigin-RevId: 668228562 Change-Id: I7524679bfe8c6b8b28c0cb04f46c0d22d0adbe99 Fixes #23185 --- .../lib/rules/cpp/CppLinkActionBuilder.java | 2 +- src/test/shell/bazel/BUILD | 1 + .../bazel/cpp_darwin_integration_test.sh | 53 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index a85850bc26f573..266ff0c87c82ac 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -831,7 +831,7 @@ public CppLinkAction build() throws InterruptedException, RuleErrorException { output.getExecPathString(), SolibSymlinkAction.getDynamicLibrarySoname( output.getRootRelativePath(), - /* preserveName= */ false, + /* preserveName= */ linkType != LinkTargetType.NODEPS_DYNAMIC_LIBRARY, actionConstructionContext.getConfiguration().getMnemonic()), linkType.equals(LinkTargetType.DYNAMIC_LIBRARY), paramFile != null ? paramFile.getExecPathString() : null, diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 5611325c472973..2bdc998ead49c1 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -128,6 +128,7 @@ sh_test( ], tags = [ "no_windows", # darwin-specific test + "requires-network", # For Bzlmod ], ) diff --git a/src/test/shell/bazel/cpp_darwin_integration_test.sh b/src/test/shell/bazel/cpp_darwin_integration_test.sh index b1155e3778e1e3..9f648b24039ab6 100755 --- a/src/test/shell/bazel/cpp_darwin_integration_test.sh +++ b/src/test/shell/bazel/cpp_darwin_integration_test.sh @@ -139,6 +139,8 @@ EOF return 0 } +# TODO: This test passes vacuously as the default Unix toolchain doesn't use +# the set_install_name feature yet. function test_cc_test_with_explicit_install_name() { mkdir -p cpp cat > cpp/BUILD < cpp/foo.h < cpp/foo.cc < cpp/test.cc < MODULE.bazel < cpp/BUILD < cpp/foo.h <