Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime_solib_name for --incompatible_macos_set_install_name #23089

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public CppLinkAction build() throws EvalException, InterruptedException {
output.getExecPathString(),
SolibSymlinkAction.getDynamicLibrarySoname(
output.getRootRelativePath(),
/* preserveName= */ false,
/* preserveName= */ linkType != LinkTargetType.NODEPS_DYNAMIC_LIBRARY,
linkActionConstruction.getContext().getConfiguration().getMnemonic()),
thinltoParamFile != null ? thinltoParamFile.getExecPathString() : null,
toolchain,
Expand Down
1 change: 1 addition & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ sh_test(
],
tags = [
"no_windows", # darwin-specific test
"requires-network", # For Bzlmod
],
)

Expand Down
53 changes: 53 additions & 0 deletions src/test/shell/bazel/cpp_darwin_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
Expand All @@ -147,10 +149,61 @@ cc_library(
srcs = ["foo.cc"],
hdrs = ["foo.h"],
)
cc_shared_library(
name = "foo_shared",
deps = [":foo"],
)
cc_test(
name = "test",
srcs = ["test.cc"],
deps = [":foo"],
dynamic_deps = [":foo_shared"],
)
EOF
cat > cpp/foo.h <<EOF
int foo();
EOF
cat > cpp/foo.cc <<EOF
int foo() { return 0; }
EOF
cat > cpp/test.cc <<EOF
#include "cpp/foo.h"
int main() {
return foo();
}
EOF

bazel test --incompatible_macos_set_install_name //cpp:test || \
fail "bazel test //cpp:test failed"
# Ensure @rpath is correctly set in the binary.
./bazel-bin/cpp/test || \
fail "//cpp:test workspace execution failed, expected return 0, got $?"
cd bazel-bin
./cpp/test || \
fail "//cpp:test execution failed, expected 0, but $?"
}

function test_cc_test_with_explicit_install_name_apple_support() {
cat > MODULE.bazel <<EOF
bazel_dep(name = "apple_support", version = "1.16.0")
EOF
comius marked this conversation as resolved.
Show resolved Hide resolved

mkdir -p cpp
cat > cpp/BUILD <<EOF
cc_library(
name = "foo",
srcs = ["foo.cc"],
hdrs = ["foo.h"],
)
cc_shared_library(
name = "foo_shared",
deps = [":foo"],
)
cc_test(
name = "test",
srcs = ["test.cc"],
deps = [":foo"],
dynamic_deps = [":foo_shared"],
)
EOF
cat > cpp/foo.h <<EOF
Expand Down
Loading