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

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

Open
andyneff opened this issue Dec 3, 2024 · 9 comments
Open

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

andyneff opened this issue Dec 3, 2024 · 9 comments

Comments

@andyneff
Copy link
Contributor

andyneff commented Dec 3, 2024

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"

@jmr
Copy link
Member

jmr commented Dec 4, 2024

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

s2geometry/src/s2/s1angle.h:139 is

friend constexpr bool operator==(S1Angle x, S1Angle y);

It's probably the "Remove some old SWIG workarounds" part of 755fe37. Older swig didn't understand constexpr.

Works for me with swig 4.2.1. Can you check the swig versions on the working/non-working systems?

@andyneff
Copy link
Contributor Author

andyneff commented Dec 4, 2024

Versions I've tried:

  • 4.0.2 - Works (quay.io/pypa/manylinux_2_28_x86_64)
  • 4.1.0 - Fails (python:3.13)
  • 4.1.1 - Fails (Windows 11 via choco)

@andyneff
Copy link
Contributor Author

andyneff commented Dec 4, 2024

Just learned pypi has swig.

All failures are the same error.

  • 4.0.2 on Windows 11 failed
  • 4.2.1 on Windows 11 works
  • 4.3.0 on Windows 11 works
  • 4.0.2 on python:3.13 fails
  • 4.2.1 on python:3.13 works
  • 4.0.2 on quay.io/pypa/manylinux_2_28_x86_64 fails. My guess is the 4.0.2 I installed from the package manager must have had some patch that made things not fail.
  • 4.2.1 on quay.io/pypa/manylinux_2_28_x86_64 works

@andyneff
Copy link
Contributor Author

andyneff commented Dec 4, 2024

After #390, I could make an edit to the README either saying we need swig 4.2, or remove mentioning SWIG completely, because python -m build will automatically download swig via pip.

@jmr
Copy link
Member

jmr commented Dec 4, 2024

Swig 4.2 is only ~1 year old, a bit too new to depend on based on the versions you're seeing. I'll add the constexpr workarounds back.

@jmr jmr changed the title Error: Syntax error in input(3) when building on some OSes Swig error: Syntax error in input(3) with swig < 4.2 Dec 4, 2024
@jmr
Copy link
Member

jmr commented Dec 5, 2024

or remove mentioning SWIG completely, because python -m build will automatically download swig via pip.

What controls the version of swig that will be downloaded?

@b4rdos
Copy link

b4rdos commented Dec 5, 2024

I think the requires section of the [build-system] should help to define the version to use.

@andyneff
Copy link
Contributor Author

andyneff commented Dec 5, 2024

Right. With no version specified, it will download the latest available from pypi with is currently 4.3.0. (With the option of adding a constraint in the future. E.g. 4.4.0 breaks compatibility, so you can say swig<4.4)

@jmr
Copy link
Member

jmr commented Dec 5, 2024

That sounds easier. Let's wait until python -m build is working, then update the instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants