diff --git a/.gitignore b/.gitignore index bf81ea1960d063d96d7918882b1bab47d4ad2af0..473e0e348315eb4b4cc98afc4e9a60832546e0e6 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build*/ bin*/ logs/ +dist/ CMakeLists.txt.user* *.autosave *.creator @@ -25,4 +26,5 @@ ehthumbs.db ehthumbs_vista.db $RECYCLE.BIN/ *.stackdump -[Dd]esktop.ini \ No newline at end of file +[Dd]esktop.ini +*.egg-info \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 6c51653c1a03a663601c9d49afbcd898f7fc86b9..0000000000000000000000000000000000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,10 +0,0 @@ -stages: - - build - -PythonBuild: - stage: build - artifacts: - untracked: true - script: - - apt-get update && apt-get install python3 -y - - bash build.sh \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..6b6dafb3887ce357d7ccfa0bed03d87f92c03250 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,77 @@ +cmake_minimum_required(VERSION 3.8) + +project( + "B-ASIC" + VERSION 0.0.1 + DESCRIPTION "Better ASIC Toolbox for python3" + LANGUAGES C CXX +) + +find_package(fmt 6.1.2 REQUIRED) +find_package(pybind11 CONFIG REQUIRED) + +set(LIBRARY_NAME "b_asic") +set(TARGET_NAME "_${LIBRARY_NAME}") +if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) + include(GNUInstallDirs) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}") +endif() + +add_library( + "${TARGET_NAME}" MODULE + "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp" +) +add_library( + "${TARGET_NAME}:${TARGET_NAME}" + ALIAS "${TARGET_NAME}" +) + +set_target_properties( + "${TARGET_NAME}" + PROPERTIES + PREFIX "" +) + +target_include_directories( + "${TARGET_NAME}" + PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/src" +) + +target_compile_features( + "${TARGET_NAME}" + PRIVATE + cxx_std_17 +) +target_compile_options( + "${TARGET_NAME}" + PRIVATE + $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>: + -W -Wall -Wextra -Werror -Wno-psabi -fvisibility=hidden + $<$<CONFIG:Debug>:-g> + $<$<NOT:$<CONFIG:Debug>>:-O3> + > + $<$<CXX_COMPILER_ID:MSVC>: + /W3 /WX /permissive- /utf-8 + $<$<CONFIG:Debug>:/Od> + $<$<NOT:$<CONFIG:Debug>>:/Ot> + > +) + +target_link_libraries( + "${TARGET_NAME}" + PRIVATE + fmt::fmt-header-only + pybind11::module +) + +add_custom_target( + copy_python_files ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_NAME}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" + COMMENT "Copying python files to ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" +) +add_custom_target( + copy_misc_files ALL + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/README.md" "${CMAKE_CURRENT_LIST_DIR}/LICENSE" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" + COMMENT "Copying misc. files to ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" +) \ No newline at end of file diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100755 index 0000000000000000000000000000000000000000..89a500ee6df5f4e18b01ae79fa57a7daf0ecc53d --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include README.md +include LICENSE +recursive-include src *.cpp *.h diff --git a/README.md b/README.md old mode 100644 new mode 100755 index f126999b47d9a015add1400c4ec887e1c8e0a9e7..78df523e985472cd9048408e8d202f021a8fba67 --- a/README.md +++ b/README.md @@ -1,3 +1,79 @@ -<img src="https://files.slack.com/files-pri/TSHPRJY83-FTTRW9MQ8/b-asic-logo-opaque.png" width="318" height="100"> -<br> -<h3>The leading company in circuit design<h3> \ No newline at end of file +<img src="logo.png" width="278" height="100"> + +# B-ASIC - Better ASIC Toolbox +B-ASIC is an ASIC toolbox for Python 3 that simplifies circuit design and optimization. + +## Prerequisites +The following packages are required in order to build the library: +* cmake 3.8+ + * gcc 7+/clang 7+/msvc 16+ + * fmtlib 6.1.2+ + * pybind11 2.3.0+ +* python 3.6+ + * setuptools + * wheel + * pybind11 + +## Development +How to build and debug the library during development. + +### Using CMake directly +How to build using CMake. + +#### Configuring +In `B-ASIC`: +``` +mkdir build +cd build +cmake .. +``` + +#### Building (Debug) +In `B-ASIC/build`: +``` +cmake --build . +``` +The output gets written to `B-ASIC/build/lib`. + +#### Building (Release) +In `B-ASIC/build`: +``` +cmake --build . --config Release +``` +The output gets written to `B-ASIC/build/lib`. + +### Using setuptools to create a package +How to create a package using setuptools. + +#### Setup (Binary distribution) +In `B-ASIC`: +``` +python3 setup.py bdist_wheel +``` +The output gets written to `B-ASIC/dist`. + +#### Setup (Source distribution) +In `B-ASIC`: +``` +python3 setup.py sdist +``` +The output gets written to `B-ASIC/dist`. + +## Usage +How to build and use the library as a user. + +### Installation +``` +python3 -m pip install b_asic +``` + +### Importing +``` +python3 +>>> import b_asic as asic +>>> help(asic) +``` + +## License +B-ASIC is distributed under the MIT license. +See the included LICENSE file for more information. \ No newline at end of file diff --git a/b_asic/__init__.py b/b_asic/__init__.py new file mode 100755 index 0000000000000000000000000000000000000000..598e2cbf9f3cc107bcf21255f907c492993b98c0 --- /dev/null +++ b/b_asic/__init__.py @@ -0,0 +1,6 @@ +"""Better ASIC Toolbox""" +from _b_asic import * + +def mul(a, b): + """A function that multiplies two numbers""" + return a * b diff --git a/build.sh b/build.sh deleted file mode 100644 index 1015ced245f71f0f85cad0da8ae562acb0d7a550..0000000000000000000000000000000000000000 --- a/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! bin/sh -for n in `find . -name "*.py"` -do - python3 $n -done \ No newline at end of file diff --git a/helloworld.py b/helloworld.py deleted file mode 100644 index 6d95fe97a12449aa7e3cf570dea13203d07571b9..0000000000000000000000000000000000000000 --- a/helloworld.py +++ /dev/null @@ -1 +0,0 @@ -print("Hello world") \ No newline at end of file diff --git a/logo.png b/logo.png new file mode 100755 index 0000000000000000000000000000000000000000..b1bd78fe7eb8a737ac8153576078d61492c2e9a3 Binary files /dev/null and b/logo.png differ diff --git a/setup.py b/setup.py new file mode 100755 index 0000000000000000000000000000000000000000..aa6d7a6c41247b4a4151d27d2e221c6d328851c6 --- /dev/null +++ b/setup.py @@ -0,0 +1,75 @@ +import os +import sys +import shutil +import subprocess +import setuptools +from setuptools import Extension +from setuptools.command.build_ext import build_ext + +CMAKE_EXE = os.environ.get('CMAKE_EXE', shutil.which('cmake')) + +class CMakeExtension(Extension): + def __init__(self, name, sourcedir = ""): + super().__init__(name, sources=[]) + self.sourcedir = os.path.abspath(sourcedir) + +class CMakeBuild(build_ext): + def build_extension(self, ext): + if not isinstance(ext, CMakeExtension): + return super().build_extension(ext) + + if not CMAKE_EXE: + raise RuntimeError(f"Cannot build extension {ext.name}: CMake executable not found! Set the CMAKE_EXE environment variable or update your path.") + + cmake_build_type = "Debug" if self.debug else "Release" + cmake_output_dir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) + cmake_configure_argv = [ + CMAKE_EXE, ext.sourcedir, + "-DCMAKE_BUILD_TYPE=" + cmake_build_type, + "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + cmake_output_dir, + "-DPYTHON_EXECUTABLE=" + sys.executable, + ] + cmake_build_argv = [ + CMAKE_EXE, "--build", ".", + "--config", cmake_build_type + ] + + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + + env = os.environ.copy() + + print(f"=== Configuring {ext.name} ===") + print(f"Temp dir: {self.build_temp}") + print(f"Output dir: {cmake_output_dir}") + subprocess.check_call(cmake_configure_argv, cwd=self.build_temp, env=env) + + print(f"=== Building {ext.name} ===") + print(f"Temp dir: {self.build_temp}") + print(f"Output dir: {cmake_output_dir}") + print(f"Build type: {cmake_build_type}") + subprocess.check_call(cmake_build_argv, cwd=self.build_temp, env=env) + + print() + +setuptools.setup( + name = "b-asic", + version = "0.0.1", + author = "Adam Jakobsson, Angus Lothian, Arvid Westerlund, Felix Goding, Ivar Härnqvist, Jacob Wahlman, Kevin Scott, Rasmus Karlsson", + author_email = "adaja901@student.liu.se, anglo547@student.liu.se, arvwe160@student.liu.se, felgo673@student.liu.se, ivaha717@student.liu.se, jacwa448@student.liu.se, kevsc634@student.liu.se, raska119@student.liu.se", + description = "Better ASIC Toolbox", + long_description = open("README.md", "r").read(), + long_description_content_type = "text/markdown", + url = "https://gitlab.liu.se/PUM_TDDD96/B-ASIC", + classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + python_requires = ">=3.6", + install_requires = ["pybind11>=2.3.0"], + packages = ["b_asic"], + ext_modules = [CMakeExtension("b_asic")], + cmdclass = {"build_ext": CMakeBuild}, + zip_safe = False +) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c3184d1b4ad3d640d64afca23af783aca8da9faa --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,21 @@ +#include <pybind11/pybind11.h> + +namespace py = pybind11; + +namespace asic { + +int add(int a, int b) { + return a + b; +} + +int sub(int a, int b) { + return a - b; +} + +} // namespace asic + +PYBIND11_MODULE(_b_asic, m) { + m.doc() = "Better ASIC Toolbox Extension Module"; + m.def("add", &asic::add, "A function which adds two numbers", py::arg("a"), py::arg("b")); + m.def("sub", &asic::sub, "A function which subtracts two numbers", py::arg("a"), py::arg("b")); +} \ No newline at end of file diff --git a/testbuild.py b/testbuild.py deleted file mode 100644 index 48f3864fd2ece1e61288431bed56d327b7396b73..0000000000000000000000000000000000000000 --- a/testbuild.py +++ /dev/null @@ -1 +0,0 @@ -print("Worked to build this file") \ No newline at end of file