Skip to content

Swig error: Syntax error in input(3) with swig < 4.2 #400

Open
@andyneff

Description

@andyneff

I was able to build successfully on master on the docker image quay.io/pypa/manylinux_2_28_x86_64 (CentOS/Alma/RHEL 8 based), but image python:3.13 (Debian based) errors on one of the swig steps. Reverting to tag v0.11.1 fixed the problem.

I also saw the same failures when building with VS2022 on Windows 11

This seems to have broken some where between commits 7940c9f (works) and 755fe37 (gets the error)

Version

$ git rev-parse HEAD
778502a21eb9c6e813df72ce9518acfdfeb8e966

Compile Error

Linux

[107/109] Swig compile s2.i for python
FAILED: python/CMakeFiles/s2geometry.dir/s2PYTHON_wrap.cxx python/s2.py /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python/CMakeFiles/s2geometry.dir/s2PYTHON_wrap.cxx /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python/s2.py
cd /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python && /tmp/build-env-omsxz4wu/lib/python3.13/site-packages/cmake/data/bin/cmake -E make_directory /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python/CMakeFiles/s2geometry.dir /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python/CMakeFiles/s2geometry.dir && /tmp/build-env-omsxz4wu/lib/python3.13/site-packages/cmake/data/bin/cmake -E env SWIG_LIB=/usr/share/swig4.0 /usr/bin/swig4.0 -python -DSWIGWORDSIZE64 -module s2geometry -outdir /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python -c++ -interface _s2geometry -I/usr/include -I/usr/local/include/python3.13 -I/s2geometry/src -o /s2geometry/build/temp.linux-x86_64-cpython-313_SwigBindings/python/CMakeFiles/s2geometry.dir/s2PYTHON_wrap.cxx /s2geometry/src/python/s2.i
/s2geometry/src/s2/util/coding/coder.h:54: Warning 362: operator= ignored
/s2geometry/src/s2/s1angle.h:139: Error: Syntax error in input(3).

Windows

[107/109] Swig compile s2.i for python
FAILED: python/CMakeFiles/s2geometry.dir/s2PYTHON_wrap.cxx python/s2.py C:/Users/andy/src/s2geometry/build/temp.win-amd64-cpython-311/Release_SwigBindings/python/CMakeFiles/s2geometry.dir/s2PYTHON_wrap.cxx C:/Users/andy/src/s2geometry/build/temp.win-amd64-cpython-311/Release_SwigBindings/python/s2.py
C:\WINDOWS\system32\cmd.exe /C "cd /D C:\Users\andy\src\s2geometry\build\temp.win-amd64-cpython-311\Release_SwigBindings\python && C:\Users\andy\AppData\Local\Temp\build-env-8i_fir_m\Lib\site-packages\cmake\data\bin\cmake.exe -E make_directory C:/Users/andy/src/s2geometry/build/temp.win-amd64-cpython-311/Release_SwigBindings/python/CMakeFiles/s2geometry.dir C:/Users/andy/src/s2geometry/build/temp.win-amd64-cpython-311/Release_SwigBindings/python C:/Users/andy/src/s2geometry/build/temp.win-amd64-cpython-311/Release_SwigBindings/python/CMakeFiles/s2geometry.dir && C:\Users\andy\AppData\Local\Temp\build-env-8i_fir_m\Lib\site-packages\cmake\data\bin\cmake.exe -E env SWIG_LIB=C:/ProgramData/chocolatey/lib/swig/tools/install/swigwin-4.1.1/Lib C:/ProgramData/chocolatey/bin/swig.exe -python -module s2geometry -outdir C:/Users/andy/src/s2geometry/build/temp.win-amd64-cpython-311/Release_SwigBindings/python -c++ -interface _s2geometry "-IC:/Program Files/OpenSSL-Win64/include" -IC:/Python311/include -IC:/Users/andy/src/s2geometry/src -o C:/Users/andy/src/s2geometry/build/temp.win-amd64-cpython-311/Release_SwigBindings/python/CMakeFiles/s2geometry.dir/s2PYTHON_wrap.cxx C:/Users/andy/src/s2geometry/src/python/s2.i"
C:\Users\andy\src\s2geometry\src\s2\util\coding\coder.h(54) : Warning 362: operator= ignored
C:\Users\andy\src\s2geometry\src\s2\s1angle.h(139) : Error: Syntax error in input(3).

Linux env

docker run -it --rm python:3.13 bash

apt-get update
apt-get install -y swig

python -m venv /venv
pip install cmake_build_extension wheel build -qq

git clone https://github.com/abseil/abseil-cpp.git /absl -b 20240722.0
cd /absl
cmake -B /absl/build \
      -DCMAKE_PREFIX_PATH=/usr/local \
      -DCMAKE_INSTALL_PREFIX=/usr/local \
      -DABSL_ENABLE_INSTALL=ON \
      -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
      -DBUILD_TESTING=OFF \
      -DCMAKE_CXX_STANDARD=20 \
      -DABSL_BUILD_TESTING=OFF; \
cmake --build /absl/build --target install

git clone https://github.com/google/s2geometry /s2geometry
cd /s2geometry
python -m build --wheel . "-C--global-option=build_ext" "-C--global-option=-DBUILD_TESTS=OFF;CMAKE_CXX_STANDARD=20"

Windows env

choco install openssl swig

python -m venv %USERPROFILE%\venv
%USERPROFILE%\venv\Scripts\activate.bat
pip install build cmake_build_extension wheel build

git clone https://github.com/abseil/abseil-cpp.git %USERPROFILE%\src\absl -b 20240722.0
cd %USERPROFILE%\absl
cmake -B %USERPROFILE%\src\absl\build -DCMAKE_PREFIX_PATH=%USERPROFILE%\src\absl\install -DCMAKE_INSTALL_PREFIX=%USERPROFILE%\src\absl\install -DABSL_ENABLE_INSTALL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_STANDARD=20 -DBUILD_TESTING=OFF -DABSL_BUILD_TESTING=OFF
cmake --build %USERPROFILE%\src\absl\build --config Release --target install

git clone https://github.com/google/s2geometry %USERPROFILE%\src\s2geometry
cd %USERPROFILE%\src\s2geometry
python -m build --wheel . "-C--global-option=build_ext" "-C--global-option=-DBUILD_TESTS=OFF;CMAKE_CXX_STANDARD=20;CMAKE_PREFIX_PATH=%USERPROFILE%\src\absl\install"

Same errors when using C++17

Using C++14 errored with:

/s2geometry/src/s2/util/math/vector.h:103:8: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  103 |     if constexpr (I >= 0 && I < SIZE) return AsD().Data()[I];

So either my gcc is picky, or the README is out of date when it says says "A C++ compiler with C++14 support"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions