-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3aefe0
commit bd2dc38
Showing
18 changed files
with
8,957 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required(VERSION 3.30) | ||
project(gkls) | ||
set(CMAKE_CXX_STANDARD 23) | ||
set(CMAKE_CXX_FLAGS "-fPIC -O3") | ||
|
||
find_package(Python REQUIRED COMPONENTS Development) | ||
|
||
file(GLOB_RECURSE SRC_FILES src/*.cc) | ||
|
||
include_directories(include ${Python_INCLUDE_DIRS}) | ||
|
||
message(STATUS "Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}") | ||
message(STATUS "Python_LIBRARIES: ${Python_LIBRARIES}") | ||
|
||
add_library(${EXT_NAME} SHARED ${SRC_FILES} ${CYTHON_CPP_FILE}) | ||
|
||
link_libraries(${EXT_NAME} ${Python_LIBRARIES}) | ||
|
||
add_executable(example src/example.cc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
import platform | ||
import shutil | ||
from pathlib import Path | ||
from subprocess import check_call | ||
|
||
from setuptools import Extension | ||
from setuptools.command.build_ext import build_ext | ||
|
||
|
||
def create_directory(path: Path): | ||
if path.exists(): | ||
shutil.rmtree(path) | ||
path.mkdir(exist_ok=True, parents=True) | ||
return path | ||
|
||
|
||
class GKLSBuildExtension(Extension): | ||
def __init__(self, name: str, version: str): | ||
super().__init__(name, sources=[]) | ||
# Source dir should be at the root directory | ||
self.source_dir = Path(__file__).parent.absolute() | ||
self.version = version | ||
|
||
|
||
class GKLSBuild(build_ext): | ||
def run(self): | ||
try: | ||
check_call(["cmake", "--version"]) | ||
except OSError: | ||
raise RuntimeError("CMake must be installed") | ||
|
||
if platform.system() not in ("Windows", "Linux", "Darwin"): | ||
raise RuntimeError(f"Unsupported os: {platform.system()}") | ||
|
||
for ext in self.extensions: | ||
if isinstance(ext, GKLSBuildExtension): | ||
self.build_extension(ext) | ||
|
||
@property | ||
def config(self): | ||
return "Debug" if self.debug else "Release" | ||
|
||
def build_extension(self, ext: Extension): | ||
ext_dir = Path(self.get_ext_fullpath(ext.name)).parent.absolute() | ||
create_directory(ext_dir) | ||
|
||
pkg_name = "gkls" | ||
ext_suffix = os.popen("python3-config --extension-suffix").read().strip() | ||
lib_name = pkg_name + ext_suffix | ||
ext_name = ".".join((lib_name).split(".")[:-1]) | ||
lib_ext_dir = Path(f"{ext_dir}/{lib_name}") | ||
|
||
# Compile the Cython file | ||
os.system(f"cython --cplus -3 {pkg_name}.pyx -o {pkg_name}.cc") | ||
|
||
# Compile the C++ files | ||
os.system( | ||
"cd build " | ||
f"&& cmake -DEXT_NAME={ext_name} -DCYTHON_CPP_FILE={pkg_name}.cc .. " | ||
"&& make -j " | ||
f"&& mv lib{lib_name} {lib_ext_dir} " | ||
) |
Oops, something went wrong.