Skip to content

Commit ecb8994

Browse files
authored
Merge pull request hathach#1544 from hathach/ci-parallel-build
Ci parallel build
2 parents 68c2012 + 53db231 commit ecb8994

File tree

13 files changed

+226
-190
lines changed

13 files changed

+226
-190
lines changed

.github/workflows/build_aarch64.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ jobs:
5555
- name: Set Toolchain Path
5656
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
5757

58+
- name: Get Dependencies
59+
run: python3 tools/get_dependencies.py ${{ matrix.family }}
60+
5861
- name: Build
5962
run: python3 tools/build_family.py ${{ matrix.family }}
6063

.github/workflows/build_arm.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ jobs:
6767
- name: Setup Python
6868
uses: actions/setup-python@v3
6969

70+
- name: Install ARM GCC
71+
uses: carlosperate/arm-none-eabi-gcc-action@v1
72+
with:
73+
release: '11.2-2022.02'
74+
7075
- name: Checkout TinyUSB
7176
uses: actions/checkout@v3
7277

@@ -84,12 +89,9 @@ jobs:
8489
run: |
8590
git clone --depth 1 -b develop https://github.com/raspberrypi/pico-sdk ~/pico-sdk
8691
echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk
87-
git submodule update --init hw/mcu/raspberry_pi/Pico-PIO-USB
8892
89-
- name: Install ARM GCC
90-
uses: carlosperate/arm-none-eabi-gcc-action@v1
91-
with:
92-
release: '11.2-2022.02'
93+
- name: Get Dependencies
94+
run: python3 tools/get_dependencies.py ${{ matrix.family }}
9395

9496
- name: Build
9597
run: python3 tools/build_family.py ${{ matrix.family }}
@@ -122,16 +124,16 @@ jobs:
122124
- name: Setup Python
123125
uses: actions/setup-python@v3
124126

127+
- name: Install ARM GCC
128+
uses: carlosperate/arm-none-eabi-gcc-action@v1
129+
with:
130+
release: '11.2-2022.02'
131+
125132
- name: Checkout TinyUSB
126133
uses: actions/checkout@v3
127134

128135
- name: Checkout common submodules in lib
129136
run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip
130137

131-
- name: Install ARM GCC
132-
uses: carlosperate/arm-none-eabi-gcc-action@v1
133-
with:
134-
release: '11.2-2022.02'
135-
136138
- name: Build
137139
run: python3 tools/build_board.py ${{ matrix.example }}

.github/workflows/build_msp430.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ jobs:
5252
- name: Set Toolchain Path
5353
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
5454

55+
- name: Get Dependencies
56+
run: python3 tools/get_dependencies.py ${{ matrix.family }}
57+
5558
- name: Build
5659
run: python3 tools/build_family.py ${{ matrix.family }}
5760

.github/workflows/build_renesas.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- name: Set Toolchain Path
5454
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
5555

56+
- name: Get Dependencies
57+
run: python3 tools/get_dependencies.py ${{ matrix.family }}
58+
5659
- name: Build
5760
run: python3 tools/build_family.py ${{ matrix.family }}
5861

.github/workflows/build_riscv.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- name: Set Toolchain Path
5454
run: echo >> $GITHUB_PATH `echo ~/cache/toolchain/*/bin`
5555

56+
- name: Get Dependencies
57+
run: python3 tools/get_dependencies.py ${{ matrix.family }}
58+
5659
- name: Build
5760
run: python3 tools/build_family.py ${{ matrix.family }}
5861

docs/reference/getting_started.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ Some TinyUSB examples also requires external submodule libraries in ``/lib`` suc
5050
5151
$ git submodule update --init lib
5252
53-
In addition, MCU driver submodule is also needed to provide low-level MCU peripheral's driver. Luckily, it will be fetched if needed when you run the ``make`` to build your board.
53+
In addition, MCU driver submodule is also needed to provide low-level MCU peripheral's driver. To download these depencies for your board, run the ``get-dpes`` as follow.
54+
55+
.. code-block::
56+
57+
$ make BOARD=feather_nrf52840_express get-deps
58+
5459
5560
Some modules will also require a module-specific SDK (e.g. RP2040) or binary (e.g. Sony Spresense) to build examples.
5661

examples/make.mk

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ else
4545
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
4646
endif
4747

48-
# Fetch submodules depended by family
49-
fetch_submodule_if_empty = $(if $(wildcard $(TOP)/$1/*),,$(info $(shell git -C $(TOP) submodule update --init $1)))
50-
ifdef DEPS_SUBMODULES
51-
$(foreach s,$(DEPS_SUBMODULES),$(call fetch_submodule_if_empty,$(s)))
52-
endif
5348

5449
#-------------- Cross Compiler ------------
5550
# Can be set by board, default to ARM GCC

examples/rules.mk

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Set all as default goal
66
.DEFAULT_GOAL := all
77

8+
# ---------------- GNU Make Start -----------------------
89
# ESP32-Sx and RP2040 has its own CMake build system
910
ifeq (,$(findstring $(FAMILY),esp32s2 esp32s3 rp2040))
1011

@@ -141,7 +142,23 @@ $(BUILD)/obj/%_asm.o: %.S
141142
@echo AS $(notdir $@)
142143
@$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
143144

144-
endif # GNU Make
145+
endif
146+
147+
.PHONY: clean
148+
clean:
149+
ifeq ($(CMDEXE),1)
150+
rd /S /Q $(subst /,\,$(BUILD))
151+
else
152+
$(RM) -rf $(BUILD)
153+
endif
154+
# ---------------- GNU Make End -----------------------
155+
156+
# get depenecies
157+
.PHONY: get-deps
158+
get-deps:
159+
ifdef DEPS_SUBMODULES
160+
git -C $(TOP) submodule update --init $(DEPS_SUBMODULES)
161+
endif
145162

146163
size: $(BUILD)/$(PROJECT).elf
147164
-@echo ''
@@ -152,14 +169,6 @@ size: $(BUILD)/$(PROJECT).elf
152169
linkermap: $(BUILD)/$(PROJECT).elf
153170
@linkermap -v $<.map
154171

155-
.PHONY: clean
156-
clean:
157-
ifeq ($(CMDEXE),1)
158-
rd /S /Q $(subst /,\,$(BUILD))
159-
else
160-
$(RM) -rf $(BUILD)
161-
endif
162-
163172
# ---------------------------------------
164173
# Flash Targets
165174
# ---------------------------------------

hw/bsp/rp2040/family.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
JLINK_DEVICE = rp2040_m0_0
22
PYOCD_TARGET = rp2040
33

4+
DEPS_SUBMODULES += hw/mcu/raspberry_pi/Pico-PIO-USB
5+
46
ifeq ($(DEBUG), 1)
57
CMAKE_DEFSYM += -DCMAKE_BUILD_TYPE=Debug
68
endif

tools/build_board.py

Lines changed: 47 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,69 @@
11
import os
2-
import glob
32
import sys
4-
import subprocess
53
import time
4+
import subprocess
5+
from multiprocessing import Pool
66

77
import build_utils
88

99
SUCCEEDED = "\033[32msucceeded\033[0m"
1010
FAILED = "\033[31mfailed\033[0m"
1111
SKIPPED = "\033[33mskipped\033[0m"
1212

13-
success_count = 0
14-
fail_count = 0
15-
skip_count = 0
16-
exit_status = 0
17-
18-
total_time = time.monotonic()
19-
20-
build_format = '| {:29} | {:30} | {:18} | {:7} | {:6} | {:6} |'
2113
build_separator = '-' * 106
2214

15+
2316
def filter_with_input(mylist):
2417
if len(sys.argv) > 1:
2518
input_args = list(set(mylist).intersection(sys.argv))
2619
if len(input_args) > 0:
2720
mylist[:] = input_args
2821

29-
# If examples are not specified in arguments, build all
30-
all_examples = []
31-
for dir1 in os.scandir("examples"):
32-
if dir1.is_dir():
33-
for entry in os.scandir(dir1.path):
34-
if entry.is_dir():
35-
all_examples.append(dir1.name + '/' + entry.name)
36-
filter_with_input(all_examples)
37-
all_examples.sort()
38-
39-
# If boards are not specified in arguments, build all
40-
all_boards = []
41-
for entry in os.scandir("hw/bsp"):
42-
if entry.is_dir() and os.path.exists(entry.path + "/board.mk"):
43-
all_boards.append(entry.name)
44-
filter_with_input(all_boards)
45-
all_boards.sort()
46-
47-
def build_board(example, board):
48-
global success_count, fail_count, skip_count, exit_status
49-
start_time = time.monotonic()
50-
flash_size = "-"
51-
sram_size = "-"
52-
53-
# Check if board is skipped
54-
if build_utils.skip_example(example, board):
55-
success = SKIPPED
56-
skip_count += 1
57-
print(build_format.format(example, board, success, '-', flash_size, sram_size))
58-
else:
59-
subprocess.run("make -C examples/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
60-
build_result = subprocess.run("make -j -C examples/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
6122

62-
if build_result.returncode == 0:
63-
success = SUCCEEDED
64-
success_count += 1
65-
(flash_size, sram_size) = build_size(example, board)
66-
else:
67-
exit_status = build_result.returncode
68-
success = FAILED
69-
fail_count += 1
23+
if __name__ == '__main__':
24+
# If examples are not specified in arguments, build all
25+
all_examples = []
26+
for dir1 in os.scandir("examples"):
27+
if dir1.is_dir():
28+
for entry in os.scandir(dir1.path):
29+
if entry.is_dir():
30+
all_examples.append(dir1.name + '/' + entry.name)
31+
filter_with_input(all_examples)
32+
all_examples.sort()
33+
34+
# If boards are not specified in arguments, build all
35+
all_boards = []
36+
for entry in os.scandir("hw/bsp"):
37+
if entry.is_dir() and os.path.exists(entry.path + "/board.mk"):
38+
all_boards.append(entry.name)
39+
filter_with_input(all_boards)
40+
all_boards.sort()
41+
42+
# Get dependencies
43+
for b in all_boards:
44+
subprocess.run("make -C examples/device/board_test BOARD={} get-deps".format(b), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
7045

71-
build_duration = time.monotonic() - start_time
72-
print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size))
73-
74-
if build_result.returncode != 0:
75-
print(build_result.stdout.decode("utf-8"))
76-
77-
def build_size(example, board):
78-
#elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board)
79-
elf_file = 'examples/{}/_build/{}/*.elf'.format(example, board)
80-
size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8")
81-
size_list = size_output.split('\n')[1].split('\t')
82-
flash_size = int(size_list[0])
83-
sram_size = int(size_list[1]) + int(size_list[2])
84-
return (flash_size, sram_size)
85-
86-
print(build_separator)
87-
print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
88-
89-
for example in all_examples:
9046
print(build_separator)
91-
for board in all_boards:
92-
build_board(example, board)
93-
94-
total_time = time.monotonic() - total_time
95-
print(build_separator)
96-
print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time))
97-
print(build_separator)
47+
print(build_utils.build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
48+
total_time = time.monotonic()
49+
50+
# succeeded, failed, skipped
51+
total_result = [0, 0, 0]
52+
for example in all_examples:
53+
print(build_separator)
54+
with Pool(processes=os.cpu_count()) as pool:
55+
pool_args = list((map(lambda b, e=example: [e, b], all_boards)))
56+
result = pool.starmap(build_utils.build_example, pool_args)
57+
# sum all element of same index (column sum)
58+
result = list(map(sum, list(zip(*result))))
59+
60+
# add to total result
61+
total_result = list(map(lambda x, y: x + y, total_result, result))
62+
63+
total_time = time.monotonic() - total_time
64+
print(build_separator)
65+
print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(total_result[0], SUCCEEDED, total_result[1],
66+
FAILED, total_result[2], SKIPPED, total_time))
67+
print(build_separator)
9868

99-
sys.exit(exit_status)
69+
sys.exit(total_result[1])

0 commit comments

Comments
 (0)