Skip to content

kabragaurav/bazel-fundamentals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notes can be found here.


Running

bazel --version   # bazel 7.0.1

C++ Project

cd cpp-project
bazel run //greeting:helloworld

Java Project

cd java-project
bazel run //:ProjectRunner
bazel run //:salutations
bazel run //:restclient

Queries:

cd java-project
bazel run //:runner
bazel query //src/main/java/com/query/dishes/...
bazel query --noimplicit_deps "deps(:runner)"
bazel query "rdeps(//... , //src/main/java/com/query/ingredients:salt)"
bazel query 'attr(tags, "hcp", //src/main/java/com/query/customers/...)'

Python3 Project

cd py-project/app
bazel run //app:main

Rules

Gen Rules

cd rules/gen-rules
bazel build //:concat         # See output (target) in bazel-bin/concat.txt
bazel  build //:process_data  # See output (target) in bazel-bin/output.txt
bazel  build //:copy_files    # See output (target) in bazel-bin/copy_file.txt
bazel build //:cat_files      # See output (target) in bazel-bin/cat_files.txt

Custom Rules
name in BUILD is the target

cd rules/custom-rules
bazel build //:bin1                # See output (target) in bazel-bin/bin1
bazel build //:bin2                # See output (target) in bazel-bin/bin2
bazel build //:bin                 # See output (target) in bazel-bin/bin
bazel run //:say_hello_to_gaurav   # This is equivalent to bazel build //:hello-gaurav; bazel run //:say_hello_to_gaurav

Macros

cd macros
bazel build //:hello_world_code_dive    # See output in bazel-bin/hello_world_code_dive
bazel build //:hello_world_everyone     # See output in bazel-bin/hello_world_everyone

Visualize dependencies

bazel query  --notool_deps --noimplicit_deps "deps(//:*)" --output graph

Sample here

Dependency graph

Some Advanced Concepts

Queries

cd rules/gen-rules
bazel aquery 'deps(//:concat)'   # action query
bazel cquery 'deps(//:concat)'   # configurable query

Toolchain

cd pythontoolchain
bazel run //:bin       # It should print 3.10 (version mentioned in WORKSPACE) but in latest bazel version, it takes system version like 3.12.2 but you will see 3.10 version is being downloaded

Links

For debugging,

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published