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

Fixes incorrect install names on darwin platforms #13427

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 @@ -872,8 +872,7 @@ public CppLinkAction build() throws InterruptedException, RuleErrorException {
getLinkType().linkerOrArchiver().equals(LinkerOrArchiver.LINKER),
configuration.getBinDirectory(repositoryName).getExecPath(),
output.getExecPathString(),
SolibSymlinkAction.getDynamicLibrarySoname(
output.getRootRelativePath(), /* preserveName= */ false),
output.getRootRelativePath().getBaseName(),
linkType.equals(LinkTargetType.DYNAMIC_LIBRARY),
paramFile != null ? paramFile.getExecPathString() : null,
thinltoParamFile != null ? thinltoParamFile.getExecPathString() : null,
Expand Down
50 changes: 34 additions & 16 deletions src/test/shell/bazel/cpp_darwin_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,41 +124,59 @@ EOF
}

function test_cc_test_with_explicit_install_name() {
mkdir -p cpp
cat > cpp/BUILD <<EOF
mkdir -p cpp/install_name
cat > cpp/install_name/BUILD <<EOF
cc_library(
name = "foo",
srcs = ["foo.cc"],
hdrs = ["foo.h"],
)
cc_binary(
name = "libbar.so",
srcs = ["bar.cc"],
linkshared = 1,
)
cc_binary(
name = "libbaz.dylib",
srcs = ["baz.cc"],
linkshared = 1,
)
cc_test(
name = "test",
srcs = ["test.cc"],
srcs = ["test.cc", ":libbar.so", ":libbaz.dylib"],
deps = [":foo"],
)
EOF
cat > cpp/foo.h <<EOF
int foo();
cat > cpp/install_name/foo.cc <<EOF
int foo() { return 2; }
EOF
cat > cpp/foo.cc <<EOF
int foo() { return 0; }
cat > cpp/install_name/bar.cc <<EOF
int bar() { return 12; }
EOF
cat > cpp/test.cc <<EOF
#include "cpp/foo.h"
cat > cpp/install_name/baz.cc <<EOF
int baz() { return 42; }
EOF
cat > cpp/install_name/test.cc <<EOF
int foo();
int bar();
int baz();
int main() {
return foo();
int result = foo() + bar() + baz();
if (result == 56) {
return 0;
} else {
return result;
}
}
EOF

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

run_suite "Tests for Bazel's C++ rules on Darwin"