Skip to content

Commit b8d3c0c

Browse files
authored
Circi dynamic config (#2763)
Circleci * build cmake armgcc and arm clang on circleci * use docker medium+
1 parent 9d8052b commit b8d3c0c

File tree

4 files changed

+155
-99
lines changed

4 files changed

+155
-99
lines changed

.circleci/config.yml

Lines changed: 26 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,39 @@
11
version: 2.1
22

3-
commands:
4-
setup-toolchain:
5-
parameters:
6-
toolchain:
7-
type: string
8-
toolchain_url:
9-
type: string
10-
steps:
11-
# - run:
12-
# name: Make toolchain cache key
13-
# command: echo "<< parameters.toolchain >>-<< parameters.toolchain_url>>" > toolchain_key
14-
# - restore_cache:
15-
# name: Restore Toolchain Cache
16-
# key: deps-{{ checksum "toolchain_key" }}
17-
# paths:
18-
# - ~/cache/<< parameters.toolchain >>
19-
- run:
20-
name: Install Toolchain
21-
command: |
22-
# Only download if folder does not exist (not cached)
23-
if [ ! -d ~/cache/<< parameters.toolchain >> ]; then
24-
mkdir -p ~/cache/<< parameters.toolchain >>
25-
wget << parameters.toolchain_url>> -O toolchain.tar.gz
26-
tar -C ~/cache/<< parameters.toolchain >> -xaf toolchain.tar.gz
27-
fi
28-
# - save_cache:
29-
# name: Save Toolchain Cache
30-
# key: deps-{{ checksum "toolchain_key" }}
31-
# paths:
32-
# - ~/cache/<< parameters.toolchain >>
33-
- run:
34-
name: Setup build environment
35-
command: |
36-
echo "export PATH=$PATH:`echo ~/cache/<< parameters.toolchain >>/*/bin`" >> $BASH_ENV
37-
# Install Ninja
38-
NINJA_URL=https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip
39-
wget $NINJA_URL -O ninja-linux.zip
40-
unzip ninja-linux.zip -d ~/bin
41-
42-
get-deps:
43-
parameters:
44-
family:
45-
type: string
46-
steps:
47-
- run:
48-
name: Get Dependencies
49-
command: |
50-
python tools/get_deps.py << parameters.family >>
3+
setup: true
4+
orbs:
5+
continuation: circleci/continuation@1
516

527
jobs:
53-
arm-clang:
54-
parameters:
55-
family:
56-
type: string
57-
build-system:
58-
type: string
59-
8+
set-matrix:
9+
executor: continuation/default
6010
docker:
6111
- image: cimg/base:current
62-
resource_class: medium
63-
environment:
64-
TOOLCHAIN_URL: https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-17.0.1/LLVMEmbeddedToolchainForArm-17.0.1-Linux-x86_64.tar.xz
12+
resource_class: small
6513
steps:
6614
- checkout
67-
- setup-toolchain:
68-
toolchain: clang
69-
toolchain_url: $TOOLCHAIN_URL
70-
- get-deps:
71-
family: << parameters.family >>
7215
- run:
73-
name: Build
16+
name: Set matrix
7417
command: |
75-
# Only build one board per family for non PRs i.e commit to master
76-
ONE_PER_FAMILY=""
77-
if [ -z "$CIRCLE_PULL_REQUEST" ]; then
78-
ONE_PER_FAMILY="--one-per-family"
79-
fi
80-
python tools/build.py $ONE_PER_FAMILY -s << parameters.build-system >> --toolchain clang << parameters.family >>
18+
MATRIX_JSON=$(python .github/workflows/ci_set_matrix.py)
19+
echo "MATRIX_JSON=$MATRIX_JSON"
20+
21+
TOOLCHAIN_LIST=("arm-clang" "arm-gcc")
22+
for toolchain in "${TOOLCHAIN_LIST[@]}"; do
23+
FAMILY=$(echo $MATRIX_JSON | jq -r ".\"$toolchain\".family")
24+
echo "${toolchain}_FAMILY=$FAMILY"
25+
echo " - build:" >> .circleci/config2.yml
26+
echo " matrix:" >> .circleci/config2.yml
27+
echo " parameters:" >> .circleci/config2.yml
28+
echo " toolchain: ['$toolchain']" >> .circleci/config2.yml
29+
echo " build-system: ['cmake']" >> .circleci/config2.yml
30+
echo " family: $FAMILY" >> .circleci/config2.yml
31+
done
32+
33+
- continuation/continue:
34+
configuration_path: .circleci/config2.yml
8135

8236
workflows:
83-
build:
37+
set-matrix:
8438
jobs:
85-
- arm-clang:
86-
matrix:
87-
parameters:
88-
build-system:
89-
- cmake
90-
#family: ['stm32f1']
91-
#family: ['stm32f1', 'stm32f2']
92-
family: ['imxrt', 'kinetis_k kinetis_kl kinetis_k32l2', 'lpc11 lpc13 lpc15', 'lpc17 lpc18 lpc40 lpc43', 'lpc51 lpc54 lpc55', 'nrf', 'samd11 samd21 saml2x', 'samd5x_e5x samg', 'stm32f0 stm32f1 stm32f2 stm32f3', 'stm32f4', 'stm32f7', 'stm32g0 stm32g4 stm32h5', 'stm32h7', 'stm32l4 stm32u5 stm32wb']
39+
- set-matrix

.circleci/config2.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
version: 2.1
2+
3+
commands:
4+
setup-toolchain:
5+
parameters:
6+
toolchain:
7+
type: string
8+
steps:
9+
- run:
10+
name: Install Toolchain
11+
command: |
12+
TOOLCHAIN_JSON='{
13+
"arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-17.0.1/LLVMEmbeddedToolchainForArm-17.0.1-Linux-x86_64.tar.xz",
14+
"arm-gcc": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.1/xpack-arm-none-eabi-gcc-12.3.1-1.1-linux-x64.tar.gz"
15+
}'
16+
toolchain_url=$(echo $TOOLCHAIN_JSON | jq -r '.["<< parameters.toolchain >>"]')
17+
echo "toolchain_url=$toolchain_url"
18+
19+
# download and extract toolchain
20+
mkdir -p ~/cache/<< parameters.toolchain >>
21+
wget $toolchain_url -O toolchain.tar.gz
22+
tar -C ~/cache/<< parameters.toolchain >> -xaf toolchain.tar.gz
23+
24+
# Add toolchain to PATH
25+
echo "export PATH=$PATH:`echo ~/cache/<< parameters.toolchain >>/*/bin`" >> $BASH_ENV
26+
27+
get-deps:
28+
parameters:
29+
family:
30+
type: string
31+
steps:
32+
- run:
33+
name: Get Dependencies
34+
command: |
35+
python tools/get_deps.py << parameters.family >>
36+
37+
# Install Pico SDK
38+
if [ << parameters.family >> == "rp2040" ]; then
39+
git clone --depth 1 https://github.com/raspberrypi/pico-sdk.git ~/pico-sdk
40+
echo "export PICO_SDK_PATH=~/pico-sdk" >> $BASH_ENV
41+
fi
42+
43+
jobs:
44+
build:
45+
parameters:
46+
build-system:
47+
type: string
48+
toolchain:
49+
type: string
50+
family:
51+
type: string
52+
53+
docker:
54+
- image: cimg/base:current
55+
resource_class: medium+
56+
steps:
57+
- checkout
58+
- when:
59+
condition: << parameters.build-system >> == 'cmake'
60+
steps:
61+
- run:
62+
name: Install Ninja
63+
command: |
64+
# Install Ninja
65+
NINJA_URL=https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip
66+
wget $NINJA_URL -O ninja-linux.zip
67+
unzip ninja-linux.zip -d ~/bin
68+
- setup-toolchain:
69+
toolchain: << parameters.toolchain >>
70+
- get-deps:
71+
family: << parameters.family >>
72+
- run:
73+
name: Build
74+
command: |
75+
# Only build one board per family for non PRs i.e commit to master
76+
ONE_PER_FAMILY=""
77+
if [ -z "$CIRCLE_PULL_REQUEST" ]; then
78+
ONE_PER_FAMILY="--one-per-family"
79+
fi
80+
81+
# Toolchain option default is gcc
82+
if [ "<< parameters.toolchain >>" == "arm-clang" ]; then
83+
TOOLCHAIN_OPTION="--toolchain clang"
84+
elif [ "<< parameters.toolchain >>" == "arm-gcc" ]; then
85+
TOOLCHAIN_OPTION="--toolchain gcc"
86+
fi
87+
88+
python tools/build.py $ONE_PER_FAMILY -s << parameters.build-system >> $TOOLCHAIN_OPTION << parameters.family >>
89+
90+
workflows:
91+
build:
92+
jobs:
93+
# - build:
94+
# matrix:
95+
# parameters:
96+
# toolchain: ['arm-clang']
97+
# build-system: ['cmake']
98+
# family: ['imxrt']

.github/workflows/build.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ jobs:
5858
fail-fast: false
5959
matrix:
6060
toolchain:
61-
# - 'arm-clang' is built by circle-ci
61+
# - 'arm-clang' is built by circle-ci in PR
6262
- 'aarch64-gcc'
63-
- 'arm-gcc'
6463
- 'msp430-gcc'
6564
- 'riscv-gcc'
6665
with:
@@ -69,6 +68,20 @@ jobs:
6968
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }}
7069
one-per-family: ${{ github.event_name != 'pull_request' }}
7170

71+
# ---------------------------------------
72+
# Build CMake arm-gcc
73+
# only build with push, for PR: all board is built by circle-ci
74+
# ---------------------------------------
75+
cmake-arm-gcc:
76+
if: github.event_name == 'push'
77+
needs: set-matrix
78+
uses: ./.github/workflows/build_util.yml
79+
with:
80+
build-system: 'cmake'
81+
toolchain: 'arm-gcc'
82+
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)['arm-gcc'].family) }}
83+
one-per-family: true
84+
7285
# ---------------------------------------
7386
# Build Make
7487
# ---------------------------------------
@@ -80,7 +93,7 @@ jobs:
8093
fail-fast: false
8194
matrix:
8295
toolchain:
83-
# 'arm-clang' is built by circle-ci
96+
# 'arm-clang' would be built by circle-ci
8497
- 'aarch64-gcc'
8598
- 'arm-gcc'
8699
- 'msp430-gcc'

tools/build_utils.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ def skip_example(example, board):
8181
return False
8282

8383

84+
def build_size(make_cmd):
85+
size_output = subprocess.run(make_cmd + ' size', shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8").splitlines()
86+
for i, l in enumerate(size_output):
87+
text_title = 'text data bss dec'
88+
if text_title in l:
89+
size_list = size_output[i+1].split('\t')
90+
flash_size = int(size_list[0])
91+
sram_size = int(size_list[1]) + int(size_list[2])
92+
return (flash_size, sram_size)
93+
94+
return (0, 0)
95+
96+
8497
def build_example(example, board, make_option):
8598
start_time = time.monotonic()
8699
flash_size = "-"
@@ -89,22 +102,20 @@ def build_example(example, board, make_option):
89102
# succeeded, failed, skipped
90103
ret = [0, 0, 0]
91104

92-
make_cmd = "make -j -C examples/{} BOARD={} {}".format(example, board, make_option)
105+
make_cmd = f"make -j -C examples/{example} BOARD={board} {make_option}"
93106

94107
# Check if board is skipped
95108
if skip_example(example, board):
96109
status = SKIPPED
97110
ret[2] = 1
98111
print(build_format.format(example, board, status, '-', flash_size, sram_size))
99112
else:
100-
#subprocess.run(make_cmd + " clean", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
101-
build_result = subprocess.run(make_cmd + " all", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
113+
build_result = subprocess.run(f"{make_cmd} all", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
102114

103115
if build_result.returncode == 0:
104116
status = SUCCEEDED
105117
ret[0] = 1
106118
(flash_size, sram_size) = build_size(make_cmd)
107-
#subprocess.run(make_cmd + " copy-artifact", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
108119
else:
109120
status = FAILED
110121
ret[1] = 1
@@ -116,16 +127,3 @@ def build_example(example, board, make_option):
116127
print(build_result.stdout.decode("utf-8"))
117128

118129
return ret
119-
120-
121-
def build_size(make_cmd):
122-
size_output = subprocess.run(make_cmd + ' size', shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8").splitlines()
123-
for i, l in enumerate(size_output):
124-
text_title = 'text data bss dec'
125-
if text_title in l:
126-
size_list = size_output[i+1].split('\t')
127-
flash_size = int(size_list[0])
128-
sram_size = int(size_list[1]) + int(size_list[2])
129-
return (flash_size, sram_size)
130-
131-
return (0, 0)

0 commit comments

Comments
 (0)