Skip to content

Commit

Permalink
use EnvironmentInfo to set environment for msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
jfolz committed Sep 3, 2024
1 parent aaf4ba8 commit f5e3fff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
23 changes: 18 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ classifiers = [
"License :: OSI Approved :: MIT License",
]
requires-python = ">=3.9"
license = {file = "LICENSE"}
authors = [
{name = "Joachim Folz", email = "joachim.folz@dfki.de"},
license = { file = "LICENSE" }
authors = [{ name = "Joachim Folz", email = "joachim.folz@dfki.de" }]
keywords = [
"the",
"fastest",
"JPEG",
"encoding",
"decoding",
"package",
"in",
"town",
]
keywords = ["the", "fastest", "JPEG", "encoding", "decoding", "package", "in", "town"]
dynamic = ["dependencies", "version"]

[project.urls]
Expand All @@ -21,7 +28,13 @@ Source = "https://gitlab.com/jfolz/simplejpeg"
Tracker = "https://gitlab.com/jfolz/simplejpeg/issues"

[build-system]
requires = ["setuptools>=50.0.3", "wheel", "cmake>=3.6.3", "cython~=3.0.0", "numpy>=2.0.0"]
requires = [
"setuptools>=74.1.0",
"wheel",
"cmake>=3.6.3",
"cython~=3.0.0",
"numpy>=2.0.0",
]
build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
Expand Down
31 changes: 19 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __repr__(self):
# build output dir is machine-specific
BUILD_DIR = 'build_' + '_'.join(platform.architecture())
IS64BIT = sys.maxsize > 2**32
ARCH = 'x64' if IS64BIT else 'x86'
ARCH = platform.machine()
if PLATFORM == 'darwin':
# From pybind cmake example:
# https://github.com/pybind/cmake_example/blob/0e3d4496b4eb1ca904c2f2f5278c5f375f035097/setup.py#L100
Expand Down Expand Up @@ -87,20 +87,25 @@ def make_type():
raise RuntimeError('Platform not supported: %s, %s' % (PLATFORM, ARCH))


def update_env_msvc():
from setuptools.msvc import EnvironmentInfo
env = EnvironmentInfo(ARCH).return_env()
for key, value in env.items():
os.environ[key.upper()] = value


class cmake_build_ext(build_ext):
def build_extensions(self):
# force initialize the compiler
try:
self.compiler.initialize()
except AttributeError:
print("setuptools compiler does not need initialization")
def run(self):
flags = []
if PLATFORM == 'darwin':
if ARCHFLAGS:
flags.append("-DCMAKE_OSX_ARCHITECTURES=" + ";".join(ARCHFLAGS))
if PLATFORM == 'windows':
update_env_msvc()
self.build_cmake_dependency(YASM_DIR, [
'-DBUILD_SHARED_LIBS=OFF'
])

cflags = ''
if PLATFORM == 'linux':
# make GCC put functions and data in separate sections
Expand All @@ -118,7 +123,7 @@ def build_extensions(self):
'-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
])
# build extensions
super().build_extensions()
super().run()

def build_cmake_dependency(self, path, options):
cur_dir = pt.abspath(os.curdir)
Expand All @@ -128,16 +133,18 @@ def build_cmake_dependency(self, path, options):
os.makedirs(build_dir)
os.chdir(build_dir)
config = 'Debug' if self.debug else 'Release'
cmake = os.path.join(CMAKE_BIN_DIR, 'cmake')
self.compiler.spawn([
cmake = pt.join(CMAKE_BIN_DIR, 'cmake')
subprocess.check_call([
cmake,
'-G' + make_type(), '-Wno-dev',
'-DCMAKE_BUILD_TYPE=' + config,
*options,
pt.join(path)
])
], stdout=sys.stdout, stderr=sys.stderr)
if not self.dry_run:
self.compiler.spawn([cmake, '--build', '.', '--config', config])
subprocess.check_call([
cmake, '--build', '.', '--config', config
], stdout=sys.stdout, stderr=sys.stderr)
os.chdir(cur_dir)


Expand Down

0 comments on commit f5e3fff

Please sign in to comment.