Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Yosys fork into Yosys plugin plus other cleanup #4

Merged
merged 59 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0a048ca
Add old churchroad content
gussmith23 Feb 7, 2024
172687a
Lots of deleting and moving
gussmith23 Feb 7, 2024
20fe828
Update workflow
gussmith23 Feb 7, 2024
890c3fa
Cut down Dockerfile
gussmith23 Feb 8, 2024
2a9f648
Fix command
gussmith23 Feb 8, 2024
1b0b956
Run workflow on GitHub runners
gussmith23 Feb 10, 2024
9b02bfa
Move lakeroad-egglog files to top level
gussmith23 Feb 10, 2024
2bb1361
Fix test script; dump README
gussmith23 Feb 10, 2024
204705f
Rename project
gussmith23 Feb 16, 2024
54cf3c3
Fix breakages after egglog updates
gussmith23 Feb 16, 2024
dfe974b
Add files
gussmith23 Feb 16, 2024
6167f93
Build Yosys in Dockerfile
gussmith23 Feb 16, 2024
5b69c1d
Add ARG
gussmith23 Feb 16, 2024
f289627
Build Yosys plugin
gussmith23 Feb 16, 2024
165d7aa
Merge remote-tracking branch 'origin/main' into gussmith23/2024-02-15…
gussmith23 Feb 16, 2024
0a7e611
Fix path
gussmith23 Feb 16, 2024
3d70593
Run plugin tests
gussmith23 Feb 16, 2024
36da8a8
Update Yosys
gussmith23 Feb 17, 2024
ca9e365
Delete file
gussmith23 Feb 17, 2024
cb18d29
Remove Yosys dependency; move test
gussmith23 Feb 18, 2024
18125d3
Update PATH
gussmith23 Feb 18, 2024
6513589
Add readme
gussmith23 Feb 18, 2024
27827b0
Make `lit` binary
gussmith23 Feb 18, 2024
18f19d3
Point to llvm-config
gussmith23 Feb 18, 2024
a64106b
Try to enable caching with cargo build
gussmith23 Feb 18, 2024
62406c6
Change how format check works
gussmith23 Feb 18, 2024
973c8e0
Title
gussmith23 Feb 18, 2024
a2641d3
Fix fmt.sh
gussmith23 Feb 18, 2024
9e48b4a
Install lit via pip
gussmith23 Feb 18, 2024
b7c01ab
Undo use of cargo chef for now
gussmith23 Feb 18, 2024
122bee0
Add .dockerignore
gussmith23 Feb 18, 2024
e49a5a5
Add files more intelligently
gussmith23 Feb 18, 2024
023ab14
Take into account the weird behavior of ADD
gussmith23 Feb 18, 2024
29da057
Fix weird issue with trying to run " bash" binary
gussmith23 Feb 18, 2024
358ff0e
Expect a CHURCHROAD_DIR env var to be set
gussmith23 Feb 18, 2024
b41dbc2
Load plugin in tests
gussmith23 Feb 18, 2024
6d2e64b
Add yosys files to test files
gussmith23 Feb 18, 2024
86f71d3
Add env template
gussmith23 Feb 18, 2024
7a2362b
ignore file
gussmith23 Feb 18, 2024
543630d
Fix
gussmith23 Feb 18, 2024
c283b7c
Improve testing of the Yosys plugin
gussmith23 Feb 18, 2024
aa517e9
Add YOSYS env var to .env.template
gussmith23 Feb 18, 2024
1808229
Fix test
gussmith23 Feb 18, 2024
a026265
Whoops, wasn't FileChecking
gussmith23 Feb 18, 2024
2d4a2b2
Add TODO
gussmith23 Feb 18, 2024
606e72a
Fix command
gussmith23 Feb 18, 2024
cf1953f
Delete comments
gussmith23 Feb 18, 2024
3679b0b
Fix command
gussmith23 Feb 18, 2024
4d6731e
Newline
gussmith23 Feb 18, 2024
9a3fb36
Delete .gitmodules
gussmith23 Feb 18, 2024
a23c17d
ADD all files in the end, plus git dir, for fmt reasons
gussmith23 Feb 18, 2024
56452ca
Format .cfg file
gussmith23 Feb 18, 2024
1e9046a
Format
gussmith23 Feb 18, 2024
80bddf0
Status instead of diff, shows more info for debug
gussmith23 Feb 18, 2024
056b724
ignore file
gussmith23 Feb 18, 2024
9aebba5
Remove other .gitignore
gussmith23 Feb 18, 2024
f147fe1
Update actions
gussmith23 Feb 18, 2024
030a7ce
Rename and reword workflow file
gussmith23 Feb 18, 2024
2050b5e
Update .env.template with documentation
gussmith23 Feb 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*.dep
*.zo

.vscode/*
.lit_test_times.txt
**/Output

**/.DS_Store
**/.lit_test_times.txt
**/Output/
**/__pycache__

target
Cargo.lock
.env

**/*.so*
**/*.d
18 changes: 18 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# User should set these variables.
#
# Optional environment variables which you opt not to set should be
# deleted/commented out.
#
# OPTIONAL: Path to llvm-config binary. Only needed if LLVM's `llvm-config` and
# `FileCheck` binaries are not in the PATH.
export LLVM_CONFIG="/path/to/llvm-config"
# OPTIONAL: Path to Yosys binary. Only needed if the `yosys` binary is not
# available on your path, or if you want to use a specific version of Yosys.
export YOSYS="/path/to/yosys"


# Do not modify below this line.
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
export CHURCHROAD_DIR=$SCRIPTPATH
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Docker image, format check, and run tests
name: Build, Test, Check Format

on:
push:
Expand Down Expand Up @@ -48,10 +48,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -65,10 +65,10 @@ jobs:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand All @@ -85,7 +85,7 @@ jobs:
]
steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -102,7 +102,7 @@ jobs:
needs: build-and-push-image
steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -111,5 +111,7 @@ jobs:
- name: Pull image
run: docker pull ${{ env.IMAGE_TAG }}

- name: Rust format check
run: docker run ${{ env.IMAGE_TAG }} cargo fmt --manifest-path ./Cargo.toml -- --check
- name: Project-wide formatting check
run: |
docker run ${{ env.IMAGE_TAG }} \
bash -c './fmt.sh && git status && [ -z "$(git status --porcelain)" ]'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@

target
Cargo.lock
.env

**/*.so*
**/*.d
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

63 changes: 55 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,67 @@ RUN apt install -y \
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:$PATH"

# Build Rust package.
WORKDIR /root/churchroad
# ADD has weird behavior when it comes to directories. That's why we need so
# many ADDs.
ADD egglog_src egglog_src
ADD src src
ADD tests tests
ADD Cargo.toml .
RUN cargo build

# Build Yosys.
WORKDIR /root
ARG MAKE_JOBS=2
ADD dependencies.sh .
RUN source /root/dependencies.sh \
&& mkdir yosys && cd yosys \
&& wget -qO- https://github.com/YosysHQ/yosys/archive/$YOSYS_COMMIT_HASH.tar.gz | tar xz --strip-components=1 \
&& PREFIX="/root/.local" CPLUS_INCLUDE_PATH="/usr/include/tcl8.6/:$CPLUS_INCLUDE_PATH" make config-gcc \
&& PREFIX="/root/.local" CPLUS_INCLUDE_PATH="/usr/include/tcl8.6/:$CPLUS_INCLUDE_PATH" make -j ${MAKE_JOBS} install \
&& rm -rf /root/yosys

# Add /root/.local/bin to PATH.
ENV PATH="/root/.local/bin:$PATH"

# Build Yosys plugin.
WORKDIR /root/churchroad/yosys-plugin
ADD yosys-plugin .
RUN make -j ${MAKE_JOBS}

# Make a binary for `lit`. If you're on Mac, you can install lit via Brew.
# Ubuntu doesn't have a binary for it, but it is available on pip and is
# installed later in this Dockerfile.
WORKDIR /root
RUN mkdir -p /root/.local/bin \
&& echo "#!/usr/bin/env python3" >> /root/.local/bin/lit \
&& echo "from lit.main import main" >> /root/.local/bin/lit \
&& echo "if __name__ == '__main__': main()" >> /root/.local/bin/lit \
&& chmod +x /root/.local/bin/lit

# Point to llvm-config binary. Alternatively, make sure you have a binary called
# `llvm-config` on your PATH.
ENV LLVM_CONFIG=llvm-config-14

# Python dependencies.
WORKDIR /root/churchroad
ADD requirements.txt .
RUN pip install -r requirements.txt

ENV CHURCHROAD_DIR=/root/churchroad

# Add other Churchroad files. It's useful to put this as far down as possible.
# In general, only ADD files just before they're needed. This maximizes the
# ability to cache intermediate containers and minimizes rebuilding.
#
# In reality, we use the git functionality of ADD (enabled in our case via the
# optional flag --keep-git-dir) to add all of the checked-in files of the
# Churchroad repo (but not including the .git directory itself). We could cut
# this down further if we wanted, but I think this is a clean approach for now.
# We use the git functionality of ADD (enabled in our case via the optional flag
# --keep-git-dir) to add all of the checked-in files of the Churchroad repo (but
# not including the .git directory itself). We could cut this down further if we
# wanted, but I think this is a clean approach for now.
WORKDIR /root/churchroad
ADD --keep-git-dir=false . .

# Build Rust package.
WORKDIR /root/churchroad
RUN cargo build

WORKDIR /root/churchroad
ADD fmt.sh run-tests.sh ./
CMD [ "/bin/bash", "run-tests.sh" ]
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Churchroad

:letsgo3:

## Yosys Plugin

[`./yosys-plugin/](./yosys-plugin/)

We provide a Yosys plugin,
which can output Churchroad IR
from Yosys.
Please see the README
in that directory
for information on building
and using the plugin.
22 changes: 22 additions & 0 deletions dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# This script exports a number of variables that help to pin the versions of
# various Churchroad dependencies.
#
# To use, source this script before running relevant commands e.g. in a
# Dockerfile.
#
# This is just one possible way to implement dependency tracking. Some of the
# other options are:
# - No tracking at all. E.g. in the Dockerfile, we could clone Yosys at a
# specific commit, using a "magic constant" commit hash. This isn't ideal,
# because if we use Yosys elsewhere (e.g. in the evaluation) we have to make
# sure we keep the commit hashes in sync.
# - Git submodules. This is very similar to what we've chosen to do, but it's
# more directly supported by Git. However, it's a bit overkill to add a full
# repository as a submodule when we only need the resulting binary.
#
# This option is essentially a lighter-weight version of submodules. We track
# the commit hashes of the dependencies we need, but nothing additional is
# cloned on a `git clone --recursive`.

export YOSYS_COMMIT_HASH="f8d4d7128cf72456cc03b0738a8651ac5dbe52e1"
9 changes: 6 additions & 3 deletions fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -e
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
raco fmt -i "$SCRIPT_DIR"/racket/*.rkt
raco fmt -i "$SCRIPT_DIR"/bin/*.rkt
cargo fmt --manifest-path "$SCRIPT_DIR"/rust/Cargo.toml

# Rust formatting.
cargo fmt --manifest-path "$SCRIPT_DIR"/Cargo.toml

# Python formatting.
black "$SCRIPT_DIR"/yosys-plugin/tests/lit.cfg
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
black==24.2.0
lit==15.0.0
4 changes: 3 additions & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

set -e

cargo test
cargo test

./yosys-plugin/run_tests.sh
1 change: 0 additions & 1 deletion yosys
Submodule yosys deleted from 316e2b
7 changes: 7 additions & 0 deletions yosys-plugin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
churchroad.so: churchroad.cc
$(CXX) $(shell yosys-config --cxxflags --ldflags) -shared -o $@ churchroad.cc -lboost_filesystem

clean:
rm -rfv *.d *.o churchroad.so*

-include *.d
30 changes: 30 additions & 0 deletions yosys-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Churchroad Backend Plugin for Yosys

We provide a plugin
for Yosys
which produces Churchroad code.

## Note on Building

Yosys plugins are simply shared libraries
that can be loaded into Yosys at runtime.
As a result,
you are required to build
a Yosys plugin using the same
build environment
as your `yosys` binary.
The easiest way to ensure this
is to simply build Yosys
from source.
If you prefer to use
a prebuilt Yosys binary,
Yosys provides a Docker image
which sets up the appropriate
environment:
<https://github.com/YosysHQ-GmbH/tabby-cad-plugin-build>
We don't yet support
using this option easily.
If you would like this feature,
please open an issue.
Until then, all plugin users should build Yosys
from source.
Loading