Skip to content

Commit

Permalink
Fixing issue 21741: Modifying reference documentation for review, to …
Browse files Browse the repository at this point in the history
…improve docs
  • Loading branch information
pat-jpnk committed Aug 8, 2024
1 parent 7e689a5 commit a516c0b
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/main/starlark/builtins_bzl/common/cc/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,36 @@ most build rules</a>.
and that rule's <code>outs</code> are automatically added to
this <code>cc_library</code>'s data files.
</p>
<p>Your C++ code can access these data files like so:</p>
<p>Using the functionality defined by the <code>runfiles_src.h</code> located under
<code>tools/cpp/runfiles/runfiles_src.h</code> Your C++ code can access these data files,
like so:
</p>
<pre><code class="lang-starlark">
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(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;
}
</code></pre>
""",
),
Expand Down

0 comments on commit a516c0b

Please sign in to comment.