|
5 | 5 | import subprocess |
6 | 6 | import re |
7 | 7 |
|
8 | | -toolchain_dir = "/opt/arm" |
9 | | -toolchains = os.listdir(toolchain_dir) |
| 8 | +toolchains = [os.path.join("/opt/arm", x) for x in os.listdir("/opt/arm")] |
| 9 | +toolchains += [os.path.join("/opt/riscv", x) for x in os.listdir("/opt/riscv")] |
10 | 10 |
|
11 | | -gcc_versions = OrderedDict() |
| 11 | +compilers = [] |
| 12 | +class Compiler: |
| 13 | + def __init__(self, version, path, type): |
| 14 | + self.version = version |
| 15 | + self.path = path |
| 16 | + self.type = type |
12 | 17 |
|
| 18 | + @property |
| 19 | + def gcc(self): |
| 20 | + return self.type == "GCC" |
| 21 | + |
| 22 | + @property |
| 23 | + def llvm(self): |
| 24 | + return self.type == "LLVM" |
| 25 | + |
| 26 | + @property |
| 27 | + def riscv(self): |
| 28 | + return "RISCV" in self.type |
| 29 | + |
| 30 | + def __repr__(self): |
| 31 | + return self.version |
| 32 | + |
| 33 | +seen_versions = [] |
13 | 34 | for toolchain in toolchains: |
14 | | - fullpath = os.path.join(toolchain_dir, toolchain) |
15 | | - gcc_path = os.path.join(fullpath, "bin/arm-none-eabi-gcc") |
16 | | - version = subprocess.run([gcc_path, "--version"], capture_output=True) |
| 35 | + gcc_path = os.path.join(toolchain, "bin/arm-none-eabi-gcc") |
| 36 | + llvm_path = os.path.join(toolchain, "bin/clang") |
| 37 | + riscv_gcc_path = os.path.join(toolchain, "bin/riscv32-unknown-elf-gcc") |
| 38 | + |
| 39 | + type = None |
| 40 | + path = None |
| 41 | + if os.path.exists(gcc_path): |
| 42 | + path = gcc_path |
| 43 | + type = "GCC" |
| 44 | + elif os.path.exists(llvm_path): |
| 45 | + path = llvm_path |
| 46 | + type = "LLVM" |
| 47 | + elif os.path.exists(riscv_gcc_path): |
| 48 | + path = riscv_gcc_path |
| 49 | + type = "RISCV GCC" |
| 50 | + else: |
| 51 | + raise Exception("Unknown compiler type") |
| 52 | + |
| 53 | + version = subprocess.run([path, "--version"], capture_output=True) |
17 | 54 | stdout = version.stdout.decode('utf-8') |
18 | 55 | stderr = version.stderr.decode('utf-8') |
19 | 56 | assert(len(stderr) == 0) |
|
23 | 60 | assert(m is not None) |
24 | 61 | version = m.group(1) |
25 | 62 |
|
26 | | - if version in gcc_versions: |
27 | | - raise Exception("Already have version {} in versions current path {}, this path {}".format(version, gcc_versions[version], fullpath)) |
28 | | - |
29 | | - gcc_versions[version] = fullpath |
| 63 | + if version in seen_versions: |
| 64 | + raise Exception("Already have version {} in versions current path {}, this path {}".format(version, gcc_versions[version], path)) |
30 | 65 |
|
31 | | -# Sort by major version |
32 | | -gcc_versions_sorted = OrderedDict(sorted(gcc_versions.items(), key=lambda item: int(item[0].replace(".", "")))) |
| 66 | + compilers.append(Compiler(version, toolchain, type)) |
| 67 | + seen_versions.append(version) |
33 | 68 |
|
| 69 | +compilers_sorted = sorted(compilers, key=lambda x: int(x.version.replace(".", ""))) |
34 | 70 |
|
35 | 71 | # Create output |
36 | 72 | output = ''' |
|
59 | 95 |
|
60 | 96 | - name: Checkout submodules |
61 | 97 | run: git submodule update --init |
| 98 | +
|
| 99 | + - name: Host Release |
| 100 | + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Release -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) |
| 101 | +
|
| 102 | + - name: Host Debug |
| 103 | + run: cd ${{github.workspace}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE=Debug -DPICO_NO_PICOTOOL=1 -DPICO_PLATFORM=host; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc) |
62 | 104 | ''' |
63 | 105 |
|
64 | | -for gcc_version, toolchain_path in gcc_versions_sorted.items(): |
65 | | - for build_type in ["Debug", "Release"]: |
66 | | - output += "\n" |
67 | | - output += " - name: GCC {} {}\n".format(gcc_version, build_type) |
68 | | - output += " if: always()\n" |
69 | | - output += " shell: bash\n" |
70 | | - output += " run: cd ${{{{github.workspace}}}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE={} -DPICO_TOOLCHAIN_PATH={} -DPICO_BOARD=pico_w; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc)\n".format(build_type, toolchain_path) |
| 106 | +platforms = [] |
| 107 | +class Platform: |
| 108 | + def __init__(self, name, platform, board, minimum_gcc_version=None): |
| 109 | + self.name = name |
| 110 | + self.board = board |
| 111 | + self.platform = platform |
| 112 | + self.riscv = "riscv" in platform |
| 113 | + self.minimum_gcc_version = minimum_gcc_version |
| 114 | + |
| 115 | + def cmake_string(self, compiler): |
| 116 | + opts = [] |
| 117 | + # Temporary while private repo |
| 118 | + opts.append("-DPICO_NO_PICOTOOL=1") |
| 119 | + if self.board: opts.append(f"-DPICO_BOARD={self.board}") |
| 120 | + opts.append(f"-DPICO_PLATFORM={self.platform}") |
| 121 | + if compiler.llvm: opts.append("-DPICO_COMPILER=pico_arm_clang") |
| 122 | + opts.append(f"-DPICO_TOOLCHAIN_PATH={compiler.path}") |
| 123 | + return " ".join(opts) |
| 124 | + |
| 125 | + def compiler_valid(self, compiler): |
| 126 | + if compiler.riscv != self.riscv: |
| 127 | + return False |
| 128 | + |
| 129 | + if self.minimum_gcc_version and compiler.gcc: |
| 130 | + if int(compiler.version.split(".")[0]) < self.minimum_gcc_version: |
| 131 | + return False |
71 | 132 |
|
| 133 | + return True |
| 134 | + |
| 135 | + |
| 136 | +platforms.append(Platform("Pico W", "rp2040", "pico_w")) |
| 137 | +platforms.append(Platform("RP2350", "rp2350", None, 9)) |
| 138 | +platforms.append(Platform("RP2350 RISCV", "rp2350-riscv", None)) |
| 139 | + |
| 140 | +for compiler in compilers_sorted: |
| 141 | + for build_type in ["Debug", "Release"]: |
| 142 | + for p in platforms: |
| 143 | + if not p.compiler_valid(compiler): continue |
| 144 | + output += "\n" |
| 145 | + output += " - name: {} {} {} {}\n".format(compiler.type, compiler.version, build_type, p.name) |
| 146 | + output += " if: always()\n" |
| 147 | + output += " shell: bash\n" |
| 148 | + output += " run: cd ${{{{github.workspace}}}}; mkdir -p build; rm -rf build/*; cd build; cmake ../ -DPICO_SDK_TESTS_ENABLED=1 -DCMAKE_BUILD_TYPE={} {}; make --output-sync=target --no-builtin-rules --no-builtin-variables -j$(nproc)\n".format(build_type, p.cmake_string(compiler)) |
72 | 149 | print(output) |
0 commit comments