Default cc_sysroot data to sysroot if not passed (#875)

Fixes https://github.com/bazelbuild/rules_cc/issues/243

Closes #875

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_cc/pull/875 from keith:ks/default-cc_sysroot-data-to-sysroot-if-not-passed 566c235a8cd5e65f929d87ddab0be78d34e18e73
PiperOrigin-RevId: 980832424
Change-Id: Ied4cd9d45bbf83369c07511899bcdda9cc2781af
diff --git a/cc/toolchains/args/sysroot.bzl b/cc/toolchains/args/sysroot.bzl
index 98c99f7..3760279 100644
--- a/cc/toolchains/args/sysroot.bzl
+++ b/cc/toolchains/args/sysroot.bzl
@@ -36,6 +36,9 @@
       args: (List[str]) Extra command-line args to add.
       **kwargs: kwargs to pass to cc_args.
     """
+    if "data" not in kwargs:
+        kwargs["data"] = [sysroot]
+
     cc_args(
         name = name,
         actions = actions,
diff --git a/tests/rule_based_toolchain/toolchain_config/BUILD b/tests/rule_based_toolchain/toolchain_config/BUILD
index 8aaa316..d3e2e5e 100644
--- a/tests/rule_based_toolchain/toolchain_config/BUILD
+++ b/tests/rule_based_toolchain/toolchain_config/BUILD
@@ -73,6 +73,7 @@
         "//tests/rule_based_toolchain/actions:c_compile",
         "//tests/rule_based_toolchain/actions:cpp_compile",
     ],
+    data = [],
     sysroot = "//tests/rule_based_toolchain/testdata:directory",
 )