Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build system to support latest upstream spt3g #192

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,52 @@ jobs:
arch: x86_64
python: 39
builder: macosx
deploy: 13.0
- os: macos-13
arch: x86_64
python: 310
builder: macosx
deploy: 13.0
- os: macos-13
arch: x86_64
python: 311
builder: macosx
deploy: 13.0

# MacOS arm64
- os: macos-latest
arch: arm64
python: 310
builder: macosx
deploy: 14.0
- os: macos-latest
arch: arm64
python: 311
builder: macosx
deploy: 14.0
env:
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.builder }}_${{ matrix.arch }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.builder }}2014
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.builder }}2014
CIBW_TEST_SKIP: "*-macosx_arm64"
CIBW_BUILD_VERBOSITY: 3
CIBW_ENVIRONMENT_LINUX: "CC=gcc CXX=g++ CFLAGS='-O3 -fPIC' CXXFLAGS='-O3 -fPIC -std=c++14' BOOST_ROOT=/usr/local"
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=13.0 CC=gcc-14 CXX=g++-14 CFLAGS='-O3 -fPIC' CXXFLAGS='-O3 -fPIC -std=c++14' BOOST_ROOT=/usr/local FLAC_ROOT=/usr/local BLAS_LIBRARIES=/usr/local/lib/libscipy_openblas.dylib"
CIBW_ENVIRONMENT_LINUX: >
CC=gcc
CXX=g++
CFLAGS='-O3 -fPIC'
CXXFLAGS='-O3 -fPIC -std=c++17'
BOOST_ROOT=/usr/local
BLAS_LIBRARIES='-L/usr/local/lib -lopenblas -fopenmp -lm -lgfortran'
CIBW_ENVIRONMENT_MACOS: >
MACOSX_DEPLOYMENT_TARGET=${{ matrix.deploy }}
CC=clang
CXX=clang++
CFLAGS='-O3 -fPIC'
CXXFLAGS='-O3 -fPIC -std=c++17 -stdlib=libc++'
BOOST_ROOT=/usr/local
FLAC_ROOT=/usr/local
BLAS_LIBRARIES='/usr/local/lib/libopenblas.dylib'
CIBW_BEFORE_BUILD_LINUX: ./wheels/install_deps_linux.sh
CIBW_BEFORE_BUILD_MACOS: ./wheels/install_deps_osx.sh ${{ matrix.builder }}_${{ matrix.arch }}
CIBW_BEFORE_BUILD_MACOS: ./wheels/install_deps_osx.sh
CIBW_REPAIR_WHEEL_COMMAND_LINUX: ./wheels/repair_wheel_linux.sh {dest_dir} {wheel}
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ./wheels/repair_wheel_macos.sh {dest_dir} {wheel} {delocate_archs}
CIBW_BEFORE_TEST: export OMP_NUM_THREADS=2
Expand All @@ -94,4 +122,4 @@ jobs:

- name: Upload to PyPI
run: |
python -m twine upload wheelhouse/so3g*cp${{ matrix.python }}-${{ matrix.builder }}*.whl
python -m twine upload wheelhouse/so3g*cp${{ matrix.python }}-${{ matrix.builder }}*${{ matrix.arch }}*.whl
37 changes: 33 additions & 4 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,52 @@ jobs:
arch: x86_64
python: 39
builder: macosx
deploy: 13.0
- os: macos-13
arch: x86_64
python: 310
builder: macosx
deploy: 13.0
- os: macos-13
arch: x86_64
python: 311
builder: macosx
deploy: 13.0

# MacOS arm64
- os: macos-latest
arch: arm64
python: 310
builder: macosx
deploy: 14.0
- os: macos-latest
arch: arm64
python: 311
builder: macosx
deploy: 14.0
env:
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.builder }}_${{ matrix.arch }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.builder }}2014
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.builder }}2014
CIBW_BUILD_VERBOSITY: 3
CIBW_ENVIRONMENT_LINUX: "CC=gcc CXX=g++ CFLAGS='-O3 -fPIC' CXXFLAGS='-O3 -fPIC -std=c++14' BOOST_ROOT=/usr/local"
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=13.0 CC=gcc-14 CXX=g++-14 CFLAGS='-O3 -fPIC' CXXFLAGS='-O3 -fPIC -std=c++14' BOOST_ROOT=/usr/local FLAC_ROOT=/usr/local BLAS_LIBRARIES=/usr/local/lib/libscipy_openblas.dylib"
CIBW_ENVIRONMENT_LINUX: >
CC=gcc
CXX=g++
CFLAGS='-O3 -fPIC'
CXXFLAGS='-O3 -fPIC -std=c++17'
BOOST_ROOT=/usr/local
BLAS_LIBRARIES='-L/usr/local/lib -lopenblas -fopenmp -lm -lgfortran'
CIBW_ENVIRONMENT_MACOS: >
MACOSX_DEPLOYMENT_TARGET=${{ matrix.deploy }}
CC=clang
CXX=clang++
CFLAGS='-O3 -fPIC'
CXXFLAGS='-O3 -fPIC -std=c++17 -stdlib=libc++'
BOOST_ROOT=/usr/local
FLAC_ROOT=/usr/local
BLAS_LIBRARIES='/usr/local/lib/libopenblas.dylib'
CIBW_BEFORE_BUILD_LINUX: ./wheels/install_deps_linux.sh
CIBW_BEFORE_BUILD_MACOS: ./wheels/install_deps_osx.sh ${{ matrix.builder }}_${{ matrix.arch }}
CIBW_BEFORE_BUILD_MACOS: ./wheels/install_deps_osx.sh
CIBW_REPAIR_WHEEL_COMMAND_LINUX: ./wheels/repair_wheel_linux.sh {dest_dir} {wheel}
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ./wheels/repair_wheel_macos.sh {dest_dir} {wheel} {delocate_archs}
CIBW_BEFORE_TEST: export OMP_NUM_THREADS=2
Expand Down Expand Up @@ -86,4 +115,4 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: wheels_cp${{ matrix.python }}-${{ matrix.builder }}
path: ./wheelhouse/so3g*cp${{ matrix.python }}-${{ matrix.builder }}*.whl
path: ./wheelhouse/so3g*cp${{ matrix.python }}-${{ matrix.builder }}*${{ matrix.arch }}*.whl
104 changes: 62 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
cmake_minimum_required (VERSION 3.1)
cmake_minimum_required(VERSION 3.17)
project (so3g)

include(local.cmake OPTIONAL)

# cmake policies -- best to keep these in sync with spt3g!
if(POLICY CMP0060) # Suppress cmake stripping full paths from libraries in some cases
cmake_policy(SET CMP0060 NEW)
endif()
cmake_policy(SET CMP0012 NEW) # Allow use of true in boolean expressions
if(POLICY CMP0042) # Enable RPATH on OSX
cmake_policy(SET CMP0042 NEW)
# Don't warn about removal of FindBoost in cmake 3.30+
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()

# Default to Release because we want that -O3. This is what spt3g_software does too.
Expand All @@ -18,12 +15,20 @@ if(NOT CMAKE_BUILD_TYPE)
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif(NOT CMAKE_BUILD_TYPE)

# Require C++ 17 (aligned with spt3g)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# We are building libraries that will eventually be linked into shared
# modules. All code should be built with PIC.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# For this to be found, make sure the spt3g build directory can be
# searched; i.e. -DCMAKE_PREFIX_PATH=/path/to/spt3g_software/build
find_package(Spt3g REQUIRED)

find_package(PythonInterp 3)
find_package(PythonLibs 3)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
find_package(FLAC)
find_package(GSL)

Expand All @@ -36,22 +41,26 @@ else()
endif()

# Determine the location of site-packages.
execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)

# Numpy include directory?
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.get_include())"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"import numpy; print(numpy.get_include())"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)

include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR} )
include_directories(${NUMPY_INCLUDE_DIR})

#
# Define the so3g build target. This is a shared library.
# Define the libso3g build target. This is an internal library that holds all the
# linking dependencies.
#

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY so3g)
add_library(so3g SHARED
src/main.cxx

add_library(so3g OBJECT
src/test.cxx
src/hkagg.cxx
src/G3Ndarray.cxx
Expand All @@ -69,32 +78,24 @@ add_library(so3g SHARED
src/array_ops.cxx
)

# We could disable the lib prefix on the output library... but let's not.
#set_target_properties(so3g PROPERTIES PREFIX "")
# Disable boost python auto_ptr warnings
target_compile_definitions(so3g PUBLIC BOOST_NO_AUTO_PTR)

# Make a list of .py files for the library.
file(GLOB MY_PYTHONS
"${CMAKE_CURRENT_SOURCE_DIR}/python/*.py")
file(GLOB MY_PYTHONS_HK
"${CMAKE_CURRENT_SOURCE_DIR}/python/hk/*.py")
file(GLOB MY_PYTHONS_PROJ
"${CMAKE_CURRENT_SOURCE_DIR}/python/proj/*.py")
file(GLOB MY_PYTHONS_SMURF
"${CMAKE_CURRENT_SOURCE_DIR}/python/smurf/*.py")
# Link to the core spt3g library
target_link_libraries(so3g PUBLIC spt3g::core)

# Provide list of libs to link against.
target_link_libraries(so3g spt3g::core)
# Link GSL
# Link to GSL
target_include_directories(so3g PRIVATE ${GSL_INCLUDE_DIR})
target_link_libraries(so3g ${GSL_LIBRARIES})
target_link_libraries(so3g PUBLIC ${GSL_LIBRARIES})

# You probably want to select openblas, so pass -DBLA_VENDOR=OpenBLAS
# Link to BLAS. You probably want to select openblas, so pass
# -DBLA_VENDOR=OpenBLAS
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message("-- BLAS found: ${BLAS_LIBRARIES}")
target_link_libraries(so3g ${BLAS_LIBRARIES})
target_link_libraries(so3g PUBLIC ${BLAS_LIBRARIES})

# The BLAS library may or may not include the cblas_ bindings.
# The BLAS library may or may not include the cblas_* bindings.
# This variable set is needed by check_function_exists; starting in
# cmake v3.18 you can say BLAS::BLAS instead of the lib path...
set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
Expand All @@ -103,27 +104,46 @@ if(BLAS_FOUND)
message("-- cblas bindings are included in the BLAS library")
else()
message("-- cblas bindings not found in BLAS; adding cblas.")
target_link_libraries(so3g cblas)
target_link_libraries(so3g PUBLIC cblas)
endif()

# On MacOS with clang linking to the Accelerate framework, the cblas
# headers are not always found. Handle this case.
# headers are not always found. Handle this case. Also note that the
# Accelerate framework has documented numerical problems- consider using
# a better BLAS/LAPACK implementation.
if(BLAS_Accelerate_LIBRARY)
#string(REGEX REPLACE "^(.*)/System/Library/Frameworks/Accelerate.framework" "\\1" FRAMEWORK_INCLUDE "${BLAS_Accelerate_LIBRARY}")
#target_compile_options(so3g PRIVATE -F ${FRAMEWORK_INCLUDE})
target_include_directories(so3g PRIVATE ${BLAS_Accelerate_LIBRARY}/Versions/A/Frameworks/vecLib.framework/Headers)
endif()
endif(BLAS_FOUND)

# This custom target generates _version.h, in the build tree. That is all.
add_custom_target(so3g-version
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/version_h.py
SO3G_VERSION_STRING ${CMAKE_CURRENT_BINARY_DIR}/_version.h
SOURCES version_h.py
)
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/version_h.py
SO3G_VERSION_STRING ${CMAKE_CURRENT_BINARY_DIR}/_version.h
SOURCES version_h.py
)

add_dependencies(so3g so3g-version)

# Add the Python interface module
Python_add_library(_libso3g MODULE WITH_SOABI src/main.cxx)
set_target_properties(_libso3g PROPERTIES PREFIX "")
target_link_libraries(_libso3g PUBLIC so3g)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
#set_target_properties(_libso3g PROPERTIES LINK_FLAGS "-Wl,--no-as-needed")
target_link_options(_libso3g PUBLIC "LINKER:--no-as-needed")
endif()

# Make a list of .py files for the library.
file(GLOB MY_PYTHONS
"${CMAKE_CURRENT_SOURCE_DIR}/python/*.py")
file(GLOB MY_PYTHONS_HK
"${CMAKE_CURRENT_SOURCE_DIR}/python/hk/*.py")
file(GLOB MY_PYTHONS_PROJ
"${CMAKE_CURRENT_SOURCE_DIR}/python/proj/*.py")
file(GLOB MY_PYTHONS_SMURF
"${CMAKE_CURRENT_SOURCE_DIR}/python/smurf/*.py")

# Define the install rules.

if(DEFINED PYTHON_INSTALL_DEST)
Expand All @@ -134,7 +154,7 @@ else()
set(INSTALL_DEST ${PYTHON_SITE_PACKAGES}/so3g)
endif()

install(TARGETS so3g
install(TARGETS _libso3g
DESTINATION ${INSTALL_DEST})

install(FILES ${MY_PYTHONS}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# A containerized so3g installation.

# Build on spt3g base image
FROM simonsobs/spt3g:0.3-289-g4bd3275
FROM simonsobs/spt3g:0.4-41-g654392d

# Set locale
ENV LANG C.UTF-8
Expand Down
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[build-system]
requires = [
"cmake>=3.17",
"setuptools>=61",
"setuptools_scm[toml]>=6.3",
"setuptools-git-versioning>=2.0,<3",
"wheel",
"numpy<2",
]
build-backend = "setuptools.build_meta"

[project]
name = "so3g"
readme = "README.rst"
description = "Tools for Simons Observatory work with spt3g_software"
urls = {source = "https://github.com/simonsobs/so3g"}
license = {file = "LICENSE"}
requires-python = ">=3.8"
dependencies = [
"numpy<2",
"scipy",
"astropy",
"matplotlib",
"scipy",
"ephem",
"pytz",
"pyaml",
"sqlalchemy",
"pysqlite3-wheels",
"tqdm",
"qpoint",
]
dynamic=["version"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Topic :: Scientific/Engineering :: Astronomy",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

[tool.setuptools_scm]

[tool.cibuildwheel]
12 changes: 7 additions & 5 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
from . import spt3g
from spt3g import core as spt3g_core

# Our library is called libso3g.{suffix}, but will load into module
# namespace so3g.
from .load_pybindings import load_pybindings
load_pybindings([__path__[0] + '/libso3g'], name='so3g')
# Load all symbols from our compiled extension.
from . import _libso3g as libso3g
# # Our library is called libso3g.{suffix}, but will load into module
# # namespace so3g.
# from .load_pybindings import load_pybindings
# load_pybindings([__path__[0] + '/libso3g'], name='so3g')

# Version is computed by versioneer.
__version__ = version()
__version__ = libso3g.version()

if os.getenv('DOCS_BUILD') != '1':
# Instance configuration.
Expand Down
Loading
Loading