Skip to content

Commit

Permalink
WIP: Update setup.py on top of branch build-wheel4 (#1044)
Browse files Browse the repository at this point in the history
Updated C standard, intergers.h.in and setup.py
  • Loading branch information
jesper-friis authored Dec 15, 2024
1 parent a665843 commit 3521fe9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 34 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ option(WITH_STATIC_PYTHON "Whether to compile with static python libraries" NO)
# Append our cmake-modules to CMAKE_MODULE_PATH
list(APPEND CMAKE_MODULE_PATH ${dlite_SOURCE_DIR}/cmake)

# Enable C99
set(CMAKE_C_STANDARD 99)
# Select C standard to be consistent with Python. Default to c11
if(WIN32 OR (PYTHON_VERSION AND PYTHON_VERSION VERSION_LESS "3.11"))
set(CMAKE_C_STANDARD 99)
else()
set(CMAKE_C_STANDARD 11)
endif()
message(STATUS "CMAKE_C_STANDARD=${CMAKE_C_STANDARD}")

# Set default cmake configurations
include(SetDefaults)
Expand Down
71 changes: 39 additions & 32 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from setuptools.command.build_ext import build_ext
from setuptools.command.install import install

import numpy as np

if TYPE_CHECKING:
from typing import Union

Expand All @@ -23,10 +25,10 @@
SETUP_DIR = Path(__file__).resolve().parent
SOURCE_DIR = SETUP_DIR.parent

# Set platform-specific CMAKE_ARGS
if platform.system() == "Linux":
dlite_compiled_ext = "_dlite.so"
dlite_compiled_dll_suffix = "*.so"

CMAKE_ARGS = [
"-DWITH_DOC=OFF",
"-DWITH_HDF5=OFF",
Expand All @@ -45,12 +47,11 @@
f"{site.USER_BASE if '--user' in sys.argv else sys.prefix}",
]
)


elif platform.system() == "Windows":
dlite_compiled_ext = "_dlite.pyd"
dlite_compiled_dll_suffix = "*.dll"
is_64bits = sys.maxsize > 2**32
arch = 'x64' if is_64bits else 'x86'
v = sys.version_info
CMAKE_ARGS = [
#"-G", "Visual Studio 15 2017",
Expand All @@ -59,10 +60,9 @@
"-DWITH_HDF5=OFF",
f"-DPYTHON_VERSION={v.major}.{v.minor}",
"-Ddlite_PYTHON_BUILD_REDISTRIBUTABLE_PACKAGE=YES",
f"-DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE={'x64' if is_64bits else 'x86'}",
f"-DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE={arch}",
"-DPython3_FIND_VIRTUALENV=STANDARD",
]

else:
raise NotImplementedError(f"Unsupported platform: {platform.system()}")

Expand Down Expand Up @@ -125,43 +125,50 @@ def build_extension(self, ext: CMakeExtension) -> None:
self.get_ext_fullpath(ext.name)))

environment_cmake_args = os.getenv("CI_BUILD_CMAKE_ARGS", "")
environment_cmake_args = environment_cmake_args.split(",") if environment_cmake_args else []
environment_cmake_args = (
environment_cmake_args.split(",") if environment_cmake_args else []
)

# Remove old CMakeCache if it exists in build directory
cachefile = Path(self.build_temp) / "CMakeCache.txt"
if cachefile.exists():
cachefile.unlink()

# Find cmake executable (using os.path for Python 3.7 compatibility)
stem, fileext = os.path.splitext(sys.executable)
cmake_exe = os.path.join(os.path.dirname(stem), "cmake" + fileext)
if "CMAKE_EXECUTABLE" in os.environ:
cmake_exe = os.environ["CMAKE_EXECUTABLE"]
elif not os.path.exists(cmake_exe):
cmake_exe = shutil.which("cmake" + fileext)

build_type = "Debug" if self.debug else "Release"
cmake_args = [
"cmake",
f"-DCMAKE_CONFIGURATION_TYPES:STRING={build_type}",
cmake_exe,
str(ext.sourcedir),
f"-DCMAKE_CONFIGURATION_TYPES:STRING={build_type}",
f"-DPython3_NumPy_INCLUDE_DIRS={np.get_include()}",
]
cmake_args.extend(CMAKE_ARGS)
cmake_args.extend(environment_cmake_args)

env = os.environ.copy()

try:
subprocess.run(
cmake_args,
cwd=self.build_temp,
env=env,
capture_output=True,
check=True,
)
except subprocess.CalledProcessError as e:
print("stdout:", e.stdout.decode("utf-8"), "\n\nstderr:",
e.stderr.decode("utf-8"))
raise
try:
subprocess.run(
["cmake", "--build", ".", "--config", build_type, "--verbose"],
cwd=self.build_temp,
env=env,
capture_output=True,
check=True,
)
except subprocess.CalledProcessError as e:
print("stdout:", e.stdout.decode("utf-8"), "\n\nstderr:",
e.stderr.decode("utf-8"))
raise
subprocess.run(
cmake_args,
cwd=self.build_temp,
env=env,
#capture_output=True,
check=True,
)

subprocess.run(
["cmake", "--build", ".", "--config", build_type, "--verbose"],
cwd=self.build_temp,
env=env,
#capture_output=True,
check=True,
)

cmake_bdist_dir = Path(self.build_temp) / Path(ext.python_package_dir)
shutil.copytree(
Expand Down
16 changes: 16 additions & 0 deletions src/utils/integers.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,30 @@
#cmakedefine HAVE_STDINT_H
#endif

#ifndef HAVE_UINT8_T
#cmakedefine HAVE_UINT8_T
#endif
#ifndef HAVE_UINT16_T
#cmakedefine HAVE_UINT16_T
#endif
#ifndef HAVE_UINT32_T
#cmakedefine HAVE_UINT32_T
#endif
#ifndef HAVE_UINT64_T
#cmakedefine HAVE_UINT64_T
#endif
#ifndef HAVE_UINT128_T
#cmakedefine HAVE_UINT128_T
#endif
#ifndef HAVE___UINT128_T
#cmakedefine HAVE___UINT128_T
#endif
#ifndef HAVE_INT128_T
#cmakedefine HAVE_INT128_T
#endif
#ifndef HAVE___INT128_T
#cmakedefine HAVE___INT128_T
#endif

#cmakedefine HAVE_LONG_LONG
#cmakedefine HAVE_INTMAX_T
Expand Down

0 comments on commit 3521fe9

Please sign in to comment.