Skip to content

Commit

Permalink
initial move from SiliconCompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
gadfort committed Aug 31, 2023
0 parents commit 0cdf111
Show file tree
Hide file tree
Showing 20 changed files with 3,918 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .flake8
@@ -0,0 +1,4 @@
[flake8]
extend-exclude = third_party,setup/deps,_skbuild
max-line-length = 100
ignore =
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,42 @@
name: 'CI Tests'

on:
workflow_dispatch:
push:

jobs:
python_test_job:
timeout-minutes: 15
runs-on: ${{ matrix.version.os }}
name: 'Pure Python tests'
strategy:
fail-fast: false
matrix:
version:
- {python: "3.6", os: "ubuntu-20.04"}
- {python: "3.7", os: "ubuntu-latest"}
- {python: "3.8", os: "ubuntu-latest"}
- {python: "3.9", os: "ubuntu-latest"}
- {python: "3.10", os: "ubuntu-latest"}
- {python: "3.11", os: "ubuntu-latest"}
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install graphviz
- name: Set up Python ${{ matrix.version.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.version.python }}
cache: pip

- name: Run Python tests
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -e .[test]
pytest
135 changes: 135 additions & 0 deletions .github/workflows/wheels.yml
@@ -0,0 +1,135 @@
name: Wheels

on:
workflow_dispatch:
release:
types:
- published

# Ensures wheels are compatible with macOS 10.15+
env:
MACOSX_DEPLOYMENT_TARGET: "10.15"

jobs:
build_wheels:
name: Wheels leflib on ${{ matrix.platform.os }} ${{ matrix.platform.arch}}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- os: ubuntu-latest
arch: x86_64
- os: ubuntu-latest
arch: aarch64
- os: macos-latest
arch: universal
- os: windows-latest
arch: x86_64

env:
CIBW_ARCHS_LINUX: ${{ matrix.platform.arch }}

steps:
- uses: actions/checkout@v3
with:
submodules: true

# This facilitates building Linux+arm64 wheels
# https://cibuildwheel.readthedocs.io/en/stable/faq/#emulation
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Setup env (Windows)
if: matrix.platform.os == 'windows-latest'
run: |
choco install -y winflexbison3
vcpkg install zlib zlib:x64-windows
- name: Setup env (macOS)
if: matrix.platform.os == 'macos-latest'
run: |
brew install bison
# https://github.com/The-OpenROAD-Project/OpenROAD/issues/1688
echo "/usr/local/opt/bison/bin" >> $GITHUB_PATH
brew install flex
echo "/usr/local/opt/flex/bin" >> $GITHUB_PATH
- uses: pypa/cibuildwheel@v2.12.1
env:
CIBW_BEFORE_ALL_LINUX: |
yum --disablerepo=epel -y update ca-certificates
yum install -y zlib-devel wget
CIBW_BEFORE_BUILD_WINDOWS: if exist "{package}\\_skbuild\" rd /q /s "{package}\\_skbuild"
CIBW_ENVIRONMENT_MACOS: >
LDFLAGS="-L/usr/local/opt/bison/lib -L/usr/local/opt/flex/lib"
CPPFLAGS="-I/usr/local/opt/flex/include"
CIBW_ENVIRONMENT_WINDOWS: SC_CMAKEARGS="-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake."
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_SKIP: "pp* *win32 *i686 *-musllinux_*"
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_TEST_SKIP: "*_arm64"
CIBW_TEST_EXTRAS: test
CIBW_TEST_COMMAND: >
pytest {package}/tests/
# "if: always()" ensures that we always upload any wheels that have
# been created, even if cibuildwheel action fails
- name: Upload wheels
if: always()
uses: actions/upload-artifact@v3
with:
name: artifact
path: wheelhouse/*.whl

publish:
needs: [build_wheels]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.event.release.body, 'NOPUBLISH')

steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.PYPI_DEPLOY }}

package_offline:
# We want to run this on the official PEP Python-wheel building platform to
# ensure the downloaded wheels have the broadest compatibility. Using the
# '--platform' tag for 'pip download' doesn't work for us, since it requires
# setting --only-binary=:all: and some of our deps aren't available as
# wheels on some platforms.
container: quay.io/pypa/manylinux2014_x86_64
needs: [build_wheels]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: [cp36-cp36m, cp37-cp37m, cp38-cp38, cp39-cp39, cp310-cp310, cp311-cp311]
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: Package sc-leflib
run: |
mkdir deps
$python -m pip download pip -d deps
$python -m pip download ./dist/sc_leflib*${{matrix.python}}*linux*x86_64.whl -d deps
tar -czvf deps-${{matrix.python}}.tar.gz deps
env:
python: /opt/python/${{matrix.python}}/bin/python

- name: Upload package
uses: actions/upload-artifact@v3
with:
path: deps*.tar.gz
24 changes: 24 additions & 0 deletions .gitignore
@@ -0,0 +1,24 @@

# Byte-compiled / optimized / DLL files
__pycache__/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
wheels/
share/python-wheels/
*.egg-info/
*.egg
MANIFEST
.vagrant/

# Scikit-build build directory
_skbuild/

# C++ module for leflib gets installed in leflib/ after running pip install -e .
_leflib.*.so
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "siliconcompiler"]
path = siliconcompiler
url = ../siliconcompiler
80 changes: 80 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,80 @@
cmake_minimum_required(VERSION 3.15...3.19)

project(sc-leflib)

# Need C++11 support
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Packages we rely on
find_package(PythonInterp)
find_package(PythonLibs)
find_package(PythonExtensions)
find_package(Cython REQUIRED)

set(TOOLS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/siliconcompiler/setup/_tools.py)

execute_process(
COMMAND python3 ${TOOLS_SCRIPT} --tool openroad --field git-url
OUTPUT_VARIABLE openroad_URL
)
string(STRIP ${openroad_URL} openroad_URL)
execute_process(
COMMAND python3 ${TOOLS_SCRIPT} --tool openroad --field git-commit
OUTPUT_VARIABLE openroad_COMMIT
)
string(STRIP ${openroad_COMMIT} openroad_COMMIT)

include(FetchContent)
FetchContent_Declare(openroad
GIT_REPOSITORY ${openroad_URL}
GIT_TAG ${openroad_COMMIT}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)

# Needed to find *.pxd file
include_directories(${CMAKE_CURRENT_LIST_DIR}/sc_leflib)

# Build Cython module
# source: https://github.com/scikit-build/scikit-build-sample-projects/blob/master/projects/hello-cython/hello/CMakeLists.txt
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/sc_leflib)
add_cython_target(_leflib ${CMAKE_CURRENT_LIST_DIR}/sc_leflib/_leflib.pyx CXX)
add_library(_leflib MODULE ${_leflib})
python_extension_module(_leflib)

# Link in lef library
target_link_libraries(_leflib lef)

# We want to be extra strict about error checking -- enable all warnings and
# treat them as errors. We only apply this to the _leflib target since the LEF
# parser library has warnings under -Wall -pedantic, but there's not much we can
# do about those.
#
# We exempt deprecated-declarations since Cython uses something deprecated in at
# least one of the Python versions we support, and there's not much we can do
# about that either.
#
# Microsoft's compiler uses a totally different set of flags, so we just set
# these for MacOS/Linux (which will be using GCC or clang).
if(NOT WIN32)
target_compile_options(_leflib PRIVATE -Wall -Werror -Wno-error=deprecated-declarations)
endif()

FetchContent_Populate(openroad)
# Stuff to include Si2 LEF library
set(LEF_DIR ${openroad_SOURCE_DIR}/src/odb/src/lef)

# this lets us include lef headers
include_directories(${LEF_DIR}/lef)
# this causes cmake to build lef/
add_subdirectory(${LEF_DIR})

# The CMake config for the LEF parser sets a single compilation option,
# -Wno-class-memaccess, which is incompatible with Microsoft's compiler. I don't
# see any particular reason to enable this warning, so overwrite the flags here
# to ensure our Windows build passes.
set_target_properties(lef PROPERTIES COMPILE_OPTIONS "")

install(TARGETS _leflib DESTINATION .)

0 comments on commit 0cdf111

Please sign in to comment.