diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LibraryToLink.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LibraryToLink.java index 5811cd95074a20..94095fdde83a66 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LibraryToLink.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LibraryToLink.java @@ -566,6 +566,8 @@ public static List getDynamicLibrariesForLinking(Iterable convertLibrariesToStaticLibraries( + Iterable librariesToLink) { + ImmutableList.Builder libraries = ImmutableList.builder(); + for (LibraryToLink libraryToLink : librariesToLink) { + LibraryToLink.Builder staticLibraryToLink = libraryToLink.toBuilder(); + if (libraryToLink.getPicStaticLibrary() != null || libraryToLink.getStaticLibrary() != null) { + staticLibraryToLink.setDynamicLibrary(null); + staticLibraryToLink.setResolvedSymlinkDynamicLibrary(null); + staticLibraryToLink.setInterfaceLibrary(null); + staticLibraryToLink.setResolvedSymlinkInterfaceLibrary(null); + } + libraries.add(staticLibraryToLink.build()); + } + return libraries.build(); + } + /** Throws errors or warnings for bad attribute state. */ private static void validateAttributes(RuleContext ruleContext) throws RuleErrorException { if (ObjcRuleClasses.objcConfiguration(ruleContext).disableObjcLibraryResources()) { diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java index cafa6b28e409e6..5bc13bade4449b 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java @@ -48,6 +48,7 @@ import com.google.devtools.build.lib.analysis.config.CompilationMode; import com.google.devtools.build.lib.analysis.util.ScratchAttributeWriter; import com.google.devtools.build.lib.packages.NoSuchTargetException; +import com.google.devtools.build.lib.packages.util.MockCcSupport; import com.google.devtools.build.lib.packages.util.MockObjcSupport; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.AppleToolchain; @@ -2134,4 +2135,20 @@ public void testIncompatibleResourceAttributeFlag_resourcesEmpty() throws Except "objc_library resource attributes are not allowed. Please use the 'data' attribute instead", "objc_library(name = 'x', resources = [])"); } + + /** Regression test for https://github.com/bazelbuild/bazel/issues/7721. */ + @Test + public void testToolchainRuntimeLibrariesSolibDir() throws Exception { + MockObjcSupport.setup( + mockToolsConfig, + MockCcSupport.SUPPORTS_INTERFACE_SHARED_LIBRARIES_FEATURE, + MockCcSupport.SUPPORTS_DYNAMIC_LINKER_FEATURE); + scratch.file( + "foo/BUILD", + "cc_test(name = 'd', deps = [':b'])", + "objc_library(name = 'b', deps = [':a'])", + "cc_library(name = 'a', srcs = ['a.c'])"); + ConfiguredTarget configuredTarget = getConfiguredTarget("//foo:d"); + assertThat(configuredTarget).isNotNull(); + } } diff --git a/src/test/shell/bazel/apple/bazel_objc_test.sh b/src/test/shell/bazel/apple/bazel_objc_test.sh index 4ef88fa6fd4b4d..b2b64b1a73cc15 100755 --- a/src/test/shell/bazel/apple/bazel_objc_test.sh +++ b/src/test/shell/bazel/apple/bazel_objc_test.sh @@ -159,4 +159,41 @@ EOF || fail "should fail to find symbol addOne" } +function test_cc_test_depending_on_objc() { + setup_objc_test_support + + rm -rf foo + mkdir -p foo + + cat >foo/a.cc < +int main(int argc, char** argv) { + std::cout << "Hello! I'm a test!\n"; + return 0; +} +EOF + + cat >foo/BUILD <$TEST_log 2>&1 || fail "should pass" +} + run_suite "objc/ios test suite"