Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 45 additions & 28 deletions .github/workflows/build_wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,65 @@ on: workflow_dispatch

jobs:
build_wheels:
name: Build wheels for ${{ matrix.os }}, python ${{ matrix.pyver }}
runs-on: ${{ matrix.os }}
name: Build wheels on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# windows-latest is not enabled because is untested yet.
# macos-latest is not enabled because ABC refures to compile.
os: [ubuntu-latest]
pyver: [cp39, cp310, cp311, cp312, cp313]
include:
- os: ubuntu-latest
cibw_archs_macos: ""
- os: macos-15-intel
cibw_archs_macos: x86_64
macos_deploy_target: "10.15"
- os: macos-14
cibw_archs_macos: arm64
macos_deploy_target: "11.0"
# FIXME: troubles with ABC build, need proper investigation.
# - os: windows-latest
# cibw_archs_macos: ""

steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
runs-on: ${{ matrix.os }}

- name: Update CMake
uses: jwlawson/actions-setup-cmake@v2.0
# To use bash commands syntax on Windows.
defaults:
run:
shell: bash

- name: Install brew dependencies
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install readline ninja
if: ${{ contains(matrix.os, 'macos') }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
submodules: recursive

- name: Build wheels
uses: pypa/cibuildwheel@v2.22.0
uses: pypa/cibuildwheel@v3.3.1
env:
CIBW_BUILD: ${{matrix.pyver}}-*
CIBW_ARCHS_LINUX: auto
CIBW_ARCHS_MACOS: auto
CIBW_ARCHS_WINDOWS: auto
CIBW_BUILD: "cp3{9,10,11,12,13}-*"
CIBW_BUILD_FRONTEND: "pip"
CIBW_BUILD_VERBOSITY: "2"
# win32 conflicts with mockturtle
# "...conversion from '_Ty2' to 'size_t' requires a narrowing conversion..."
CIBW_SKIP: "*-win32"
CIBW_ARCHS_MACOS: ${{ matrix.cibw_archs_macos }}
CIBW_ARCHS_WINDOWS: "AMD64"
CIBW_ENVIRONMENT_MACOS: >-
MACOSX_DEPLOYMENT_TARGET=${{ matrix.macos_deploy_target }}
CMAKE_ARGS="-DCMAKE_OSX_DEPLOYMENT_TARGET=${{ matrix.macos_deploy_target }}"
CIBW_BEFORE_ALL_MACOS: "HOMEBREW_NO_AUTO_UPDATE=1 brew install ninja readline"
CIBW_BEFORE_ALL_LINUX: "yum install -y ninja-build; python -m pip install ninja"
CIBW_TEST_REQUIRES: pytest mock
CIBW_TEST_COMMAND: pytest {package}/tests
CIBW_TEST_SKIP: >-
*-musllinux_*
*-macosx_universal2:arm64
pp*-macosx_*
CIBW_TEST_COMMAND: pytest -m "not manual" {package}/tests
CIBW_TEST_SKIP: "*-musllinux_*"
with:
package-dir: .
output-dir: wheelhouse
config-file: "{package}/pyproject.toml"

- uses: actions/upload-artifact@v4
if: always()
with:
name: wheel-${{ matrix.pyver }}-${{ matrix.os }}
path: ./wheelhouse/*.whl
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: |
wheelhouse/*.whl
**/CMakeFiles/CMakeOutput.log
**/CMakeFiles/CMakeError.log
34 changes: 27 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ option(DISABLE_ABC_CEXT "Controls if ABC should be compiled." OFF)
# Note: must be before mockturtle's CMakeLists is added.
SET(MOCKTURTLE_EXAMPLES OFF CACHE BOOL "Build examples" FORCE)

# Disabled because it requires gnu readline to be installed on build
# machine, but not necessary for the ABC compilation as library.
list(APPEND ABC_READLINE_FLAGS "ABC_USE_NO_READLINE=1")

add_subdirectory(third_party/pybind11)
add_subdirectory(third_party/mockturtle)

Expand All @@ -24,11 +20,35 @@ target_include_directories(mockturtle_wrapper PRIVATE third_party)

# ABC related libs can be disabled using environment variable.
IF(NOT DISABLE_ABC_CEXT)
# Disabled because it requires gnu readline to be installed on build
# machine, but is not necessary for the ABC compilation as library.
set(READLINE_FOUND FALSE CACHE BOOL "" FORCE)

add_subdirectory(third_party/abc)
# Needed for correct library compilation.
target_compile_options(libabc PRIVATE -fPIC)

pybind11_add_module(abc_wrapper extensions/abc_wrapper/src/module.cpp)
target_link_libraries(abc_wrapper PRIVATE libabc)
target_link_libraries(abc_wrapper PRIVATE libabc-pic)
target_include_directories(abc_wrapper PRIVATE third_party)

# Fixes case in CI, when ABC compilation
# fails with "#error unknown platform" on
# macos runners (both intel and apple silicon).
if(NOT WIN32)
target_compile_definitions(abc_wrapper PRIVATE ABC_USE_STDINT_H)
target_compile_definitions(libabc-pic PRIVATE ABC_USE_STDINT_H)
if(TARGET libabc)
target_compile_definitions(libabc PRIVATE ABC_USE_STDINT_H)
endif()
endif()

if (MSVC)
# Fixes Windows build: `pthreads-win32` tried to redefine `timespec`.
target_compile_definitions(libabc-pic PRIVATE HAVE_STRUCT_TIMESPEC=1)
if(TARGET libabc)
target_compile_definitions(libabc PRIVATE HAVE_STRUCT_TIMESPEC=1)
endif()
endif()

# Fixes pybing11 build errors when exceptions are not defined.
target_compile_options(abc_wrapper PRIVATE -fexceptions -frtti)
ENDIF(NOT DISABLE_ABC_CEXT)
23 changes: 18 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
"win-arm64": "ARM64",
}

def _parse_env_flag(name: str, default: bool = False) -> bool:
v = os.environ.get(name)
if v is None:
return default
v = v.strip().lower()
return v not in ("", "0", "false", "no", "off")


# Disables building extensions and subdirectories related to ABC
DISABLE_ABC_CEXT = bool(os.environ.get('DISABLE_ABC_CEXT', False))
DISABLE_ABC_CEXT = _parse_env_flag('DISABLE_ABC_CEXT', False)


# A CMakeExtension needs a sourcedir instead of a file list.
# A CMakeExtension needs a source dir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
# If you need multiple extensions, see scikit-build.
class CMakeExtension(Extension):
Expand All @@ -50,7 +58,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")

# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
# VERSION_INFO shows you how to pass a value into the C++ code
# from Python.
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
Expand All @@ -64,7 +72,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

# In this example, we pass in the version to C++. You might not need to.
cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"]
cmake_args += [f"-DVERSION_INFO={self.distribution.get_version()}"]

if DISABLE_ABC_CEXT:
cmake_args += [f"-DDISABLE_ABC_CEXT=ON"]
Expand Down Expand Up @@ -130,7 +138,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
)
subprocess.run(
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
["cmake", "--build", ".", *build_args, "--target", ext.name], cwd=build_temp, check=True
)


Expand All @@ -148,4 +156,9 @@ def build(setup_kwargs):
"ext_modules": ext_modules,
"cmdclass": {"build_ext": CMakeBuild},
"zip_safe": False,

"package_data": {"cirbo": ["data/**/*"]},
# Strange option naming, but it actually disables
# *automatically* detected package data inclusion.
"include_package_data": False,
})
25 changes: 13 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
[project]
name = "cirbo"
version = "0.1.0"
version = "0.1.1"
requires-python = ">= 3.9"
description = "A New Tool for Boolean Circuit Analysis and Synthesis."
authors = [
{name = "Alexander S. Kulikov"},
{name = "Daniil Averkov"},
{name = "Tatiana Belova"},
{name = "Gregory Emdin"},
{name = "Mikhail Goncharov"},
{name = "Viktoriia Krivogornitsyna"},
{name = "Fedor Kurmazov", email = "f.kurmazov.b@gmail.com"},
{name = "Daniil Levtsov"},
{name = "Georgie Levtsov"},
{name = "Vsevolod Vaskin"},
{name = "Aleksey Vorobiev"}
{name = "Cirbo contributors"},
# {name = "Alexander S. Kulikov"},
# {name = "Daniil Averkov"},
# {name = "Tatiana Belova"},
# {name = "Gregory Emdin"},
# {name = "Mikhail Goncharov"},
# {name = "Viktoriia Krivogornitsyna"},
# {name = "Fedor Kurmazov", email = "f.kurmazov.b@gmail.com"},
# {name = "Daniil Levtsov"},
# {name = "Georgie Levtsov"},
# {name = "Vsevolod Vaskin"},
# {name = "Aleksey Vorobiev"}
]
maintainers = [
{name = "Fedor Kurmazov", email = "f.kurmazov.b@gmail.com"}
Expand Down
Loading