Bazel RUN command for C and python Programs.

38 views
Skip to first unread message

Uma Patil

unread,
Sep 19, 2022, 2:30:26 AM9/19/22
to bazel-discuss
Hi Everyone,

I have main application in C and I need to integrate few tools into Bazel using Python. 
I have written the STLink CLI deploy mechanism in Python and passing the executable(.hex) of C program as input to Python program to deploy to microcontroller board. 
For now 
"Bazel Build --platform=... //application" is creating a hex file and working perfectly. 

Now i need to implement RUN command that builds the executable and also deploy that executable using STlink python Program. 
"Bazel RUN target --platform=... //application"

Here is snippet:
Main C application/ Build:
cc_binary(
  name = "app",
  srcs = glob(["*.c"]),
  deps = [
  ....
  ],
  visibility = ["//visibility:public"],
)

Python Program: //Tools/stlink/Build
py_binary(
  name = "run",
  srcs = glob(["*.py"]),
  main = "main.py",
)

Tool implementation is present in Main.py.
def flash(
try:
        programming_output = subprocess.check_output(
            [
                'ST-LINK_CLI.exe',
                '-c',
                'SN=' + str(probe),
                'SWD',
                'UR',
                'Hrst',
                '-Q',
                '-P',
                hex_file_path,
                '-V',
                '-HardRST',
                'HIGH',
                '-Rst',
            ],
          ..................................................................
if __name__ == '__main__':
    status, checksum = flash('.hex file path')
    print(status)

Problem:
I'm unable to get the RUN command to work. I need to know how can I integrate the python program into the Bazel to get the RUN Command to work. Any guidance would be of great help.

Thank you in advance.
Uma

Konstantin

unread,
Nov 12, 2022, 4:43:05 PM11/12/22
to bazel-discuss
py_binary?
Reply all
Reply to author
Forward
0 new messages