diff --git a/amaranth/build/run.py b/amaranth/build/run.py index 0784b48..3403561 100644 --- a/amaranth/build/run.py +++ b/amaranth/build/run.py @@ -115,6 +115,28 @@ class BuildPlan: return LocalBuildProducts(build_dir) + + def execute_local_docker(self, image, *, root="build", docker_args=[]): + """ + Execute build plan inside a Docker container. Files from the build plan are placed in the + build root directory ``root`` on the local filesystem. This directory is bind mounted to + ``/build`` in a container and the script ``{script}.sh`` is executed inside it. + ``docker_args`` is a list containing additional arguments to docker. + + Returns :class:`LocalBuildProducts`. + """ + build_dir = self.extract(root) + subprocess.check_call([ + "docker", "run", *docker_args, + "--rm", # remove the container after running + "--mount", f"type=bind,source={build_dir},target=/build", + "--workdir", "/build", + image, + "sh", f"{self.script}.sh", + ]) + return LocalBuildProducts(build_dir) + + def execute_remote_ssh(self, *, connect_to={}, root, run_script=True): """ Execute build plan using the remote SSH strategy. Files from the build diff --git a/docs/changes.rst b/docs/changes.rst index 16229cd..b7cc836 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -35,6 +35,7 @@ Platform integration changes .. currentmodule:: amaranth.vendor +* Added: :meth:`BuildPlan.execute_local_docker`. * Added: :meth:`BuildPlan.extract`. * Added: ``build.sh`` begins with ``#!/bin/sh``. * Removed: (deprecated in 0.4) :mod:`vendor.intel`, :mod:`vendor.lattice_ecp5`, :mod:`vendor.lattice_ice40`, :mod:`vendor.lattice_machxo2_3l`, :mod:`vendor.quicklogic`, :mod:`vendor.xilinx`. (`RFC 18`_)