Deduplcate rpaths in linkopts

When switching to cpp linking variables, we need to modify the Apple rules to
ensure that -Wl,-rpath,/usr/lib/swift appear before other rpaths.

But we still need to leave behind that rpath in swift rules for linking rules
that don't use apple rules (e.g. cc_binary).

The side effect is that the are now more Appler linker warning about duplicate
rpaths for simple targets.  I don't know of a way to turn that off, and since we
already have logic to deduplicate frameworks, let's deduplicate rpaths while
we're at it.

PiperOrigin-RevId: 687016661
Change-Id: Iba80b5690121ba90453e461057167d0920eafa5f
diff --git a/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl b/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl
index c93ecd9..c6e5497 100644
--- a/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl
+++ b/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl
@@ -887,13 +887,15 @@
             replace_libs,
         )
 
-    cc_linking_context = _create_deduped_linkopts_linking_context(ctx.label, cc_linking_context)
+    (cc_linking_context, seen_flags) = _create_deduped_linkopts_linking_context(ctx.label, cc_linking_context)
 
     prefixed_attr_linkopts = [
         "-Wl,%s" % linkopt
         for linkopt in attr_linkopts
     ]
 
+    (_, user_link_flags, _) = _dedup_link_flags(extra_link_args + prefixed_attr_linkopts, seen_flags)
+
     cc_common.link(
         name = name,
         actions = ctx.actions,
@@ -910,7 +912,7 @@
         main_output = binary,
         output_type = "executable",
         stamp = stamp,
-        user_link_flags = extra_link_args + prefixed_attr_linkopts,
+        user_link_flags = user_link_flags,
         variables_extension = user_variable_extensions,
     )
 
@@ -946,6 +948,12 @@
             if key not in seen_flags:
                 new_flags.extend([arg.split(",")[1], framework])
                 seen_flags[key] = True
+        elif arg.startswith("-Wl,-rpath,"):
+            rpath = arg.split(",")[2]
+            key = arg[5] + rpath
+            if key not in seen_flags:
+                new_flags.append(arg)
+                seen_flags[key] = True
         elif arg.startswith("-l"):
             if arg not in seen_flags:
                 new_flags.append(arg)
@@ -984,8 +992,11 @@
         linkstamps = cc_linking_context.linkstamps(),
     ))
 
-    return cc_common.create_linking_context(
-        linker_inputs = depset(linker_inputs),
+    return (
+        cc_common.create_linking_context(
+            linker_inputs = depset(linker_inputs),
+        ),
+        seen_flags,
     )
 
 def _substitute_j2objc_pruned_libraries(