Skip to content

Commit

Permalink
Add a script to download and build fftw3
Browse files Browse the repository at this point in the history
This script is used to build the macOS wheel
  • Loading branch information
claudiodsf committed May 21, 2024
1 parent b907fc8 commit fa36d2a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ RELEASE-VERSION

# IDE
.vscode

# FFTW3 files
fftw3/
fftw-3.*/
fftw-3.*.tar.gz
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ Based on original code from [NIMH MEG Core Facility].

[NIMH MEG Core Facility]: https://kurage.nimh.nih.gov/meglab/Meg/Stockwell.

(c) 2021-2023 Claudio Satriano <satriano@ipgp.fr>
(c) 2021-2024 Claudio Satriano <satriano@ipgp.fr>

## unreleased

- Remove support for Python 3.6 and 3.7
- Add support for Python 3.11 and 3.12
- Support for Numpy 2.0!
- Added a script to download and compile FFTW3

## v1.1 - 2023-06-05

Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,22 @@ On Windows, install the [Microsoft C++ Build Tools].
To compile Stockwell, you will need to have [FFTW]
installed.

If you use [Anaconda]&nbsp;(Linux, macOS, Windows):
On Linux and macOS, you can download and compile FFTW from source using
the script `get_fftw3.sh`

conda install fftw
Alternatively, you can install FFTW using your package manager:

If you use Homebrew (macOS)
- If you use [Anaconda]&nbsp;(Linux, macOS, Windows):

brew install fftw
conda install fftw

If you use `apt` (Debian or Ubuntu)
- If you use Homebrew (macOS)

sudo apt install libfftw3-dev
brew install fftw

- If you use `apt` (Debian or Ubuntu)

sudo apt install libfftw3-dev

#### Install the Python package from source

Expand Down
32 changes: 32 additions & 0 deletions get_fftw3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Download and build the FFTW3 library
#
# This script is part of the Stockwell project.
#
# :copyright:
# 2024 Claudio Satriano <satriano@ipgp.fr>
#
# :license:
# GNU General Public License v3.0 or later.
# (https://www.gnu.org/licenses/gpl-3.0.html)

# exit on error
set -e

# Get the script directory and move to it
scriptdir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
cd "$scriptdir"

# remove any existing FFTW3 package and directory
rm -rf fftw-3.3.10.tar.gz fftw-3.3.10 fftw3

# Download the FFTW3 library and unpack it
curl -O http://www.fftw.org/fftw-3.3.10.tar.gz
tar -xzf fftw-3.3.10.tar.gz
mkdir -p fftw3

# Build the FFTW3 library
cd fftw-3.3.10
./configure --prefix="$scriptdir/fftw3" --enable-threads
make -s
make -s install
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ select = "*-musllinux*"
before-all = "apk add fftw-dev"

[tool.cibuildwheel.macos]
before-all = 'brew install fftw'
before-build = '{package}/get_fftw.sh'

[tool.cibuildwheel.windows]
before-all = '%CONDA%\Scripts\conda.exe install fftw'
Expand Down
42 changes: 24 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,30 @@

include_dirs_st = []
library_dirs_st = []
# Search Homebrew fftw3 on macOS
if 'HOMEBREW_PREFIX' in os.environ:
include_dirs_st.append(
os.path.join(os.environ['HOMEBREW_PREFIX'], 'include'))
library_dirs_st.append(
os.path.join(os.environ['HOMEBREW_PREFIX'], 'lib'))
# This seems necessary only for Windows
if 'CONDA_PREFIX' in os.environ:
include_dirs_st.append(
os.path.join(os.environ['CONDA_PREFIX'], 'Library', 'include'))
library_dirs_st.append(
os.path.join(os.environ['CONDA_PREFIX'], 'Library', 'lib'))
# This is needed for Miniconda on GitHub-hosted Windows runner
if 'CONDA' in os.environ:
include_dirs_st.append(
os.path.join(os.environ['CONDA'], 'Library', 'include'))
library_dirs_st.append(
os.path.join(os.environ['CONDA'], 'Library', 'lib'))
# First search for fftw3 in the current directory
# (i.e., installed using the script "get_fftw3.sh")
if os.path.exists('fftw3'):
include_dirs_st.append('fftw3/include')
library_dirs_st.append('fftw3/lib')
else:
# Search Homebrew fftw3 on macOS
if 'HOMEBREW_PREFIX' in os.environ:
include_dirs_st.append(
os.path.join(os.environ['HOMEBREW_PREFIX'], 'include'))
library_dirs_st.append(
os.path.join(os.environ['HOMEBREW_PREFIX'], 'lib'))
# Search for a version of fftw3 provided by Conda
if 'CONDA_PREFIX' in os.environ:
include_dirs_st.append(
os.path.join(os.environ['CONDA_PREFIX'], 'Library', 'include'))
library_dirs_st.append(
os.path.join(os.environ['CONDA_PREFIX'], 'Library', 'lib'))
# This is needed for Miniconda on GitHub-hosted Windows runner
if 'CONDA' in os.environ:
include_dirs_st.append(
os.path.join(os.environ['CONDA'], 'Library', 'include'))
library_dirs_st.append(
os.path.join(os.environ['CONDA'], 'Library', 'lib'))

ext_modules = [
Extension(
Expand Down

0 comments on commit fa36d2a

Please sign in to comment.