8000 DOC: Address build system review I · numpy/numpy@36041a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36041a0

Browse files
HaoZekergommersbilderbuchimelissawm
committed
DOC: Address build system review I
Co-authored-by: Ralf Gommers <ralf.gommers@gmail.com> Co-authored-by: Christoph Buchner <bilderbuchi@phononoia.at> Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
1 parent a5bc4c1 commit 36041a0

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

doc/source/f2py/buildtools/cmake.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ learning curve is steeper since CMake syntax is not pythonic and is closer to
1010

1111
However, the trade-off is enhanced flexibility and support for most architectures
1212
and compilers. An introduction to the syntax is out of scope for this document,
13-
but the `official CMake Tutorials`_ are a fantastic resource.
13+
but this `extensive CMake collection`_ of resources is great.
1414

1515
.. note::
1616

@@ -57,4 +57,4 @@ with the ``cython`` information.
5757
This is particularly useful where an existing toolchain already exists and
5858
``scikit-build`` or other additional ``python`` dependencies are discouraged.
5959

60-
.. _official CMake Tutorials: https://cmake.org/cmake/help/latest/guide/tutorial/index.html
60+
.. _extensive CMake collection: https://cliutils.gitlab.io/modern-cmake/

doc/source/f2py/buildtools/index.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Fortran 77 programs
5353
arrays.
5454

5555
Fortran 90 programs
56-
- Input file ``blah.f``
56+
- Input file ``blah.f90``
5757
- Generates:
5858

5959
+ ``blahmodule.c``
@@ -75,6 +75,10 @@ Signature files
7575
their contents; which shifts the burden of checking for generated files onto
7676
the build system.
7777

78+
.. note::
79+
80+
The signature file output situation is being reconsidered in `issue 20385`_ .
81+
7882

7983
In theory keeping the above requirements in hand, any build system can be
8084
adapted to generate ``f2py`` extension modules. Here we will cover a subset of
@@ -94,3 +98,5 @@ Build Systems
9498
meson
9599
cmake
96100
skbuild
101+
102+
.. _`issue 20385`: https://github.com/numpy/numpy/issues/20385

doc/source/f2py/buildtools/meson.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ examples from :ref:`f2py-getting-started` section:
3131
.. literalinclude:: ./../code/meson.build
3232
:language: meson
3333

34-
.. note::
35-
36-
* The ``fortranobject.{c,h}`` files have to be included in the manner shown,
37-
by referencing the ``.c`` file and adding to the include directories.
38-
* The warning level is lower than that of a build set up with ``meson init``
39-
4034
At this point the build will complete, but the import will fail:
4135

4236
.. code-block:: bash

doc/source/f2py/buildtools/skbuild.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Using via ``scikit-build``
55
============================
66

77
``scikit-build`` provides two separate concepts geared towards the users of Python extension modules.
8-
1. A ``setuptools`` replacement
8+
9+
1. A ``setuptools`` replacement (legacy behaviour)
910
2. A series of ``cmake`` modules with definitions which help building Python extensions
1011

1112
.. note::
@@ -53,6 +54,13 @@ The resulting extension can be built and loaded in the standard workflow.
5354
``setuptools`` replacement
5455
^^^^^^^^^^^^^^^^^^^^^^^^^^^
5556

57+
.. note::
58+
59+
**As of November 2021**
60+
61+
The behavior described here of driving the ``cmake`` build of a module is
62+
considered to be legacy behaviour and should not be depended on.
63+
5664
The utility of ``scikit-build`` lies in being able to drive the generation of
5765
more than extension modules, in particular a common usage pattern is the
5866
generation of Python distributables (for example for PyPI).
@@ -62,13 +70,15 @@ The workflow with ``scikit-build`` straightforwardly supports such packaging req
6270
.. literalinclude:: ./../code/setup_skbuild.py
6371
:language: python
6472

65-
Along with a commiserate ``pyproject.toml``
73+
Along with a commensurate ``pyproject.toml``
6674

6775
.. literalinclude:: ./../code/pyproj_skbuild.toml
6876
:language: toml
6977

7078
Together these can build the extension using ``cmake`` in tandem with other
71-
standard ``setuptools`` outputs.
79+
standard ``setuptools`` outputs. Running ``cmake`` through ``setup.py`` is
80+
mostly used when it is necessary to integrate with extension modules not built
81+
with ``cmake``.
7282

7383
.. code:: bash
7484

doc/source/f2py/code/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### setup project ###
2-
cmake_minimum_required(VERSION 3.17.3)
2+
cmake_minimum_required(VERSION 3.17.3) # 3.17 > for Python3_SOABI
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44

55
project(fibby
@@ -41,25 +41,31 @@ message(STATUS ${Python3_INCLUDE_DIRS})
4141
message(STATUS ${F2PY_INCLUDE_DIR})
4242
message(STATUS ${Python3_NumPy_INCLUDE_DIRS})
4343

44+
# Vars
45+
set(f2py_module_name "fibby")
46+
set(fortran_src_file "${CMAKE_SOURCE_DIR}/fib1.f")
47+
set(f2py_module_c "${f2py_module_name}module.c")
48+
set(generated_module_file "${f2py_module_name}${Python3_SOABI}")
49+
4450
# Generate sources
4551
add_custom_target(
4652
genpyf
47-
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}module.c"
53+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_c}"
4854
)
4955
add_custom_command(
50-
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}module.c"
56+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_c}"
5157
COMMAND ${Python3_EXECUTABLE} -m "numpy.f2py"
52-
"${CMAKE_SOURCE_DIR}/fib1.f"
58+
"${fortran_src_file}"
5359
-m "fibby"
5460
--lower # Important
5561
DEPENDS fib1.f # Fortran source
5662
)
5763

5864
# Set up target
5965
add_library(${CMAKE_PROJECT_NAME} SHARED
60-
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}module.c" # Generated
66+
"${CMAKE_CURRENT_BINARY_DIR}/${f2py_module_c}" # Generated
6167
"${F2PY_INCLUDE_DIR}/fortranobject.c" # From NumPy
62-
fib1.f # Fortran source(s)
68+
"${fortran_src_file}" # Fortran source(s)
6369
)
6470

6571
# Depend on sources

0 commit comments

Comments
 (0)
0