39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
# build/build_targets/rp2040.py
|
|
from .base import BuildTarget
|
|
from ..config import RP2040_CMAKE_TEMPLATE, PICO_TOOLCHAIN_TEMPLATE
|
|
from pathlib import Path
|
|
from ..utils import run, mkdir
|
|
|
|
class RP2040Build(BuildTarget):
|
|
|
|
def sources(self) -> list[Path]:
|
|
sources = list(self.config.SRC_DIR.glob("*.c"))
|
|
sources = [s for s in sources if s.name not in ["main.c", "repl.c", "file.c"] and "test" not in s.stem.lower()]
|
|
return sources
|
|
|
|
def prepare(self, project_name: str = "sls"):
|
|
# write toolchain
|
|
with open(self.config.PICO_TOOLCHAIN_PATH, "w") as f:
|
|
f.write(self.config.PICO_TOOLCHAIN_TEMPLATE)
|
|
|
|
# gather sources
|
|
sources = self.sources()
|
|
source_files = "\n".join(f" {s}" for s in sources)
|
|
cmake_content = self.config.RP2040_CMAKE_TEMPLATE.format(
|
|
project_name=project_name,
|
|
source_files=source_files,
|
|
git_hash=self.utils.git_commit_hash(),
|
|
pico_sdk_path=str(self.config.PICO_SDK_PATH)
|
|
)
|
|
with open("CMakeLists.txt", "w") as f:
|
|
f.write(cmake_content)
|
|
|
|
def build(self):
|
|
if not self.platform.supports_rp2040():
|
|
raise RuntimeError("RP2040 build requirements not met")
|
|
print('\n=== Building for RP2040 ===\n')
|
|
self.prepare()
|
|
mkdir(self.config.PICO_BUILD_DIR)
|
|
run(["cmake", "-B", str(self.config.PICO_BUILD_DIR), "-S", ".", f"-DCMAKE_TOOLCHAIN_FILE={self.config.PICO_TOOLCHAIN_PATH}"])
|
|
run(["cmake", "--build", str(self.config.PICO_BUILD_DIR), "-j4"])
|