diff --git a/src/main/starlark/builtins_bzl/common/cc/attrs.bzl b/src/main/starlark/builtins_bzl/common/cc/attrs.bzl index f02ab98356b08f..d65360cc83a057 100644 --- a/src/main/starlark/builtins_bzl/common/cc/attrs.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/attrs.bzl @@ -119,10 +119,36 @@ most build rules. and that rule's outs are automatically added to this cc_library's data files.

-

Your C++ code can access these data files like so:

+

Using the functionality defined by the runfiles_src.h located under + tools/cpp/runfiles/runfiles_src.h Your C++ code can access these data files, + like so: +


-  const std::string path = devtools_build::GetDataDependencyFilepath(
-      "my/test/data/file");
+  
+  #include "runfiles_src.h"
+
+  int main(int argc, char** argv) {
+    
+    try {
+
+    using bazel::tools::cpp::runfiles::Runfiles;
+    
+    std::string error;
+    std::unique_ptr runfiles(Runfiles::Create(argv[0], BAZEL_CURRENT_REPOSITORY, &error));
+    
+    // "cpp_example" is the WORKSPACE name attribute
+    // "data/example.json" is the path relative from the project root
+
+    std::string path = runfiles->Rlocation("cpp_example/data/example.json");
+    
+    //...
+    
+    } catch (const std::exception& e) {
+    	// ...
+    }
+
+    return 0;
+  }
 
""", ),