-
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.
Installing the package requires CMake and a C compiler to build the library. The testing runs on a custom Docker image that includes the dependencies.
- Loading branch information
1 parent
6dccb53
commit 2a7badf
Showing
7 changed files
with
130 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ name: build-docker-image | |
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
# Use Ubuntu as the base image | ||
FROM ubuntu:latest AS base | ||
FROM alpine:latest AS base | ||
|
||
# Install build-essential, cmake, and OpenBLAS | ||
RUN apt-get update && \ | ||
apt-get install -y build-essential cmake libopenblas-dev | ||
RUN apk update && \ | ||
apk add --no-cache build-base cmake openblas-dev python3 |
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
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,77 @@ | ||
import os | ||
import pathlib as pl | ||
import platform | ||
import subprocess | ||
import sys | ||
|
||
from setuptools import Extension, setup | ||
from setuptools.command.build_ext import build_ext | ||
|
||
|
||
class CMakeExtension(Extension): | ||
def __init__(self, name, source_dir=""): | ||
Extension.__init__(self, name, sources=[]) | ||
self.source_dir = pl.Path(source_dir).absolute() | ||
|
||
|
||
class CMakeBuild(build_ext): | ||
def run(self): | ||
try: | ||
subprocess.check_output(["cmake", "--version"]) | ||
except subprocess.CalledProcessError as err: | ||
raise RuntimeError( | ||
"CMake must be installed to build the following extensions: " | ||
+ ", ".join(e.name for e in self.extensions) | ||
) from err | ||
|
||
for ext in self.extensions: | ||
self.build_extension(ext) | ||
|
||
def build_extension(self, ext: CMakeExtension): | ||
ext_dir = pl.Path(self.get_ext_fullpath(ext.name)).parent.absolute() | ||
|
||
cmake_args = ["-DPYTHON_EXECUTABLE=" + sys.executable] | ||
|
||
cfg = "Debug" if self.debug else "Release" | ||
build_args = ["--config", cfg] | ||
|
||
if platform.system() == "Windows": | ||
cmake_args += [f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={ext_dir}"] | ||
if sys.maxsize > 2**32: | ||
# We are on a Win 64-bit system | ||
cmake_args += ["-A", "x64"] | ||
build_args += ["--", "/m"] | ||
else: | ||
# These flags are passed as-is to the underlying build tool (make) | ||
build_args += ["--", "-j2"] | ||
|
||
env = os.environ.copy() | ||
env["CXXFLAGS"] = '{} -DVERSION_INFO="{}"'.format( | ||
env.get("CXXFLAGS", ""), self.distribution.get_version() | ||
) | ||
|
||
build_dir = pl.Path(self.build_temp) | ||
build_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
try: | ||
subprocess.check_call( | ||
["cmake", "-S", ext.source_dir.as_posix(), "-B", "."] + cmake_args, | ||
cwd=build_dir, | ||
env=env, | ||
) | ||
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_dir) | ||
except subprocess.CalledProcessError as err: | ||
raise RuntimeError(f"CMake error: {err}") from err | ||
|
||
|
||
setup( | ||
name="cleedpy", | ||
ext_modules=[ | ||
CMakeExtension( | ||
"cleed", (pl.Path(__file__).parent / "cleedpy" / "cleed").as_posix() | ||
) | ||
], | ||
cmdclass={"build_ext": CMakeBuild}, | ||
# The following includes *any* library file found in the package directory | ||
package_data={"cleedpy": ["**/*.dylib", "**/*.so", "**/*.dll"]}, | ||
) |