From db15f9db5cdd1a8bc65773a82d495d79a4ec79de Mon Sep 17 00:00:00 2001 From: Jeff Goeders Date: Thu, 20 Jul 2023 17:29:10 -0400 Subject: [PATCH] Local cache of fasm2bels Signed-off-by: Jeff Goeders --- .github/actions/setup_env/Makefile | 14 ++++++++++++++ .github/actions/setup_env/action.yml | 25 ++++++++++++++++++++++++- .github/workflows/unittests.yml | 2 ++ bfasst/paths.py | 7 +++++++ bfasst/reverse_bit/xray.py | 2 +- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .github/actions/setup_env/Makefile diff --git a/.github/actions/setup_env/Makefile b/.github/actions/setup_env/Makefile new file mode 100644 index 000000000..749a91bd3 --- /dev/null +++ b/.github/actions/setup_env/Makefile @@ -0,0 +1,14 @@ +FASM2BELS_COMMIT ?= master + +install_fasm2bels: + rm -rf ${BFASST_PATH_FASM2BELS} + git clone https://github.com/chipsalliance/f4pga-xc-fasm2bels.git ${BFASST_PATH_FASM2BELS} + cd ${BFASST_PATH_FASM2BELS} && git reset --hard ${FASM2BELS_COMMIT} + cd ${BFASST_PATH_FASM2BELS} && make env + cd ${BFASST_PATH_FASM2BELS} && make build + cd ${BFASST_PATH_FASM2BELS} && make test-py + + cd ../../.. && python scripts/run_design.py designs/basic/and3/ xilinx_and_reversed + + + diff --git a/.github/actions/setup_env/action.yml b/.github/actions/setup_env/action.yml index 2be3e3f79..576380049 100644 --- a/.github/actions/setup_env/action.yml +++ b/.github/actions/setup_env/action.yml @@ -2,6 +2,11 @@ # TODO: Use https://github.com/actions/cache to cache rapidwright tool name: "Setup Environment" + +inputs: + cache_path: + description: "Path to local runner cache" + runs: using: "composite" steps: @@ -22,10 +27,28 @@ runs: run: | make env + - name: fasm2bels_env + shell: bash + run: | + if [[ -n "${{ inputs.cache_path }}" ]]; then + echo "BFASST_PATH_FASM2BELS=${{ inputs.cache_path }}/fasm2bels" >> "$GITHUB_ENV" + fi + - name: fasm2bels shell: bash run: | - make install_fasm2bels + if [[ -n "${{ inputs.cache_path }}" ]]; then + # Check if cache file matches current commit + FASM2BELS_COMMIT=$(git submodule status third_party/fasm2bels/ | awk '{print $1}') + if [ -f ${{ inputs.cache_path }}/fasm2bels_commit.txt ] && [ $FASM2BELS_COMMIT == $(cat ${{ inputs.cache_path }}/fasm2bels_commit.txt) ]; then + # Successful cache, do nothing + echo "Using cached version of fasm2bels" + else + echo "Installing cached version of fasm2bels" + . .venv/bin/activate && cd $GITHUB_ACTION_PATH && CACHE_PATH=${{ inputs.cache_path }} FASM2BELS_COMMIT=$FASM2BELS_COMMIT make install_fasm2bels + echo $FASM2BELS_COMMIT > ${{ inputs.cache_path }}/fasm2bels_commit.txt + fi + fi - name: fasm2bels_artifacts if: failure() diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index d052bf86c..5a272ac17 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -45,6 +45,8 @@ jobs: with: submodules: 'recursive' - uses: ./.github/actions/setup_env + with: + cache_path: $HOME/actions-runner/cache - name: experiments timeout-minutes: 30 run: | diff --git a/bfasst/paths.py b/bfasst/paths.py index d35f074e6..e4c0f2d42 100644 --- a/bfasst/paths.py +++ b/bfasst/paths.py @@ -1,6 +1,7 @@ """ Repository paths using pathlib """ import pathlib +import os ROOT_PATH = pathlib.Path(__file__).resolve().parent.parent @@ -15,3 +16,9 @@ YOSYS_RESOURCES = RESOURCES_PATH / "yosys" ONESPIN_RESOURCES = RESOURCES_PATH / "onespin" YOSYS_INSTALL_DIR = THIRD_PARTY_PATH / "yosys" + + +def get_fasm2bels_path(): + if "BFASST_PATH_FASM2BELS" in os.environ: + return pathlib.Path(os.environ["BFASST_PATH_FASM2BELS"]) + return THIRD_PARTY_PATH / "fasm2bels" diff --git a/bfasst/reverse_bit/xray.py b/bfasst/reverse_bit/xray.py index bf18c0b24..5d69ade9d 100644 --- a/bfasst/reverse_bit/xray.py +++ b/bfasst/reverse_bit/xray.py @@ -16,7 +16,7 @@ class XRayReverseBitTool(ReverseBitTool): def __init__(self, cwd, design, flow_args): super().__init__(cwd, design, flow_args) - self.fasm2bels_path = paths.ROOT_PATH / "third_party" / "fasm2bels" + self.fasm2bels_path = paths.get_fasm2bels_path() self.fasm2bels_python_path = ( self.fasm2bels_path / "env"