Skip to content

Commit d59ff5c

Browse files
authored
[BAZEL] added flash rules (#1)
* [BAZEL] added flash rules * [GITHUB] run workflows on main
1 parent 72e672b commit d59ff5c

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Linux
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ main ]
88

99
jobs:
1010

.github/workflows/mac.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: macOS
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ main ]
88

99
jobs:
1010

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Windows
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ main ]
88

99
jobs:
1010

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,28 @@ You can use cargo flash to load binaries or elf files to any target that uses a
6666

6767
You can invoke the tool directly from the command line with `bazel run @rust_embedded//:cargo-flash -- --chip CHIP --elf ELF` or use the target in your bazel rules.
6868

69+
You can also use the built in rules, as the following example shows
70+
71+
'''python
72+
# package/BUILD
73+
74+
load("@rust_embedded//:rules.bzl", "cargo_flash")
75+
76+
cargo_flash(
77+
name = "flash",
78+
file = "<your/bazel/elf>",
79+
chip = "STM32F103C8",
80+
)
81+
82+
cargo_flash(
83+
name = "flash_bin",
84+
file = "<your/bazel/elf>",
85+
chip = "STM32F103C8",
86+
bin = True,
87+
)
88+
89+
'''
90+
91+
Then `bazel run //package:flash` will load the file to the rarget
92+
6993

rules.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
""" Rules """
2+
3+
4+
def cargo_flash(name, file, chip, bin=False):
5+
"""Use cargo-flash to load an elf file onto a chip
6+
7+
To find the supported chip targets use the following command
8+
bazel run @rust_embedded//:cargo-flash -- --list-chips
9+
10+
Args:
11+
name: the target name as a string
12+
file: the label to the elf file
13+
chip: string, the target chip
14+
bin: set to True the file is a binary, False by default
15+
"""
16+
17+
file_type = "bin" if bin else "elf"
18+
tool = "@rust_embedded//:cargo-flash"
19+
cmd = """
20+
echo "$(locations {}) --chip {} --{} $(location {})" > $@
21+
""".format(tool, chip, file_type, file)
22+
23+
native.genrule(
24+
name = name,
25+
srcs = [file],
26+
outs = [name + ".sh"],
27+
executable = True,
28+
tools = [tool],
29+
cmd = cmd,
30+
)

0 commit comments

Comments
 (0)