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

can't install uharfbuzz due to cython new version 3 #164

Closed
cyrilus opened this issue Jul 18, 2023 · 4 comments · Fixed by #165
Closed

can't install uharfbuzz due to cython new version 3 #164

cyrilus opened this issue Jul 18, 2023 · 4 comments · Fixed by #165

Comments

@cyrilus
Copy link

cyrilus commented Jul 18, 2023

pip install can't work due to cython 3.0 release
I have try to correct this in my PR
#163

@anthrotype
Copy link
Member

Thanks for reporting this. I just tried on my mac and also wasn't able to build with the latest cython 3.0.
It seems that we are getting errors like "Cannot assign type x to y" in all the places where callback functions are used.
I don't know what might have changed that caused this (I have attached the full error log below).
It's better to pin cython < 3.0 like you did in #163 until we figure out what's happening

$ pip wheel -w dist -v .
Processing /Users/clupo/Github/uharfbuzz
  Running command pip subprocess to install build dependencies
  Collecting setuptools>=36.4
    Using cached setuptools-68.0.0-py3-none-any.whl (804 kB)
  Collecting wheel
    Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
  Collecting setuptools_scm>=2.1
    Using cached setuptools_scm-7.1.0-py3-none-any.whl (43 kB)
  Collecting cython>=0.28.1
    Downloading Cython-3.0.0-py2.py3-none-any.whl (1.2 MB)
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 2.7 MB/s eta 0:00:00
  Collecting packaging>=20.0
    Using cached packaging-23.1-py3-none-any.whl (48 kB)
  Collecting typing-extensions
    Using cached typing_extensions-4.7.1-py3-none-any.whl (33 kB)
  Collecting tomli>=1.0.0
    Using cached tomli-2.0.1-py3-none-any.whl (12 kB)
  Installing collected packages: wheel, typing-extensions, tomli, setuptools, packaging, cython, setuptools_scm
  Successfully installed cython-3.0.0 packaging-23.1 setuptools-68.0.0 setuptools_scm-7.1.0 tomli-2.0.1 typing-extensions-4.7.1 wheel-0.40.0

  [notice] A new release of pip available: 22.2 -> 23.2
  [notice] To update, run: pip install --upgrade pip
  Installing build dependencies ... done
  Running command Getting requirements to build wheel
  warning: src/uharfbuzz/_harfbuzz.pyx:14:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      def guess_segment_properties(self) -> None:
          hb_buffer_guess_segment_properties(self._hb_buffer)

      def set_message_func(self, callback) -> None:
          self._message_callback = callback
          hb_buffer_set_message_func(self._hb_buffer, msgcallback, <void*>callback, NULL)
                                                      ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:371:52: Cannot assign type 'int (hb_buffer_t *, hb_font_t *, const char *, void *) except? -1' to 'hb_buffer_message_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                object  # user_data
                            ], bytes],
                            user_data: object):
          cdef Face inst = cls(None)
          inst._hb_face = hb_face_create_for_tables(
              _reference_table_func, <void*>user_data, NULL)
              ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:487:12: Cannot assign type 'hb_blob_t *(hb_face_t *, hb_tag_t, void *) except *' to 'hb_reference_table_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...

      def draw_glyph_with_pen(self, gid: int, pen):
          global drawfuncs
          if drawfuncs == NULL:
              drawfuncs = hb_draw_funcs_create()
              hb_draw_funcs_set_move_to_func(drawfuncs, _pen_move_to_func, NULL, NULL)
                                                        ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:788:54: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, void *) except *' to 'hb_draw_move_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      def draw_glyph_with_pen(self, gid: int, pen):
          global drawfuncs
          if drawfuncs == NULL:
              drawfuncs = hb_draw_funcs_create()
              hb_draw_funcs_set_move_to_func(drawfuncs, _pen_move_to_func, NULL, NULL)
              hb_draw_funcs_set_line_to_func(drawfuncs, _pen_line_to_func, NULL, NULL)
                                                        ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:789:54: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, void *) except *' to 'hb_draw_line_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          global drawfuncs
          if drawfuncs == NULL:
              drawfuncs = hb_draw_funcs_create()
              hb_draw_funcs_set_move_to_func(drawfuncs, _pen_move_to_func, NULL, NULL)
              hb_draw_funcs_set_line_to_func(drawfuncs, _pen_line_to_func, NULL, NULL)
              hb_draw_funcs_set_cubic_to_func(drawfuncs, _pen_cubic_to_func, NULL, NULL)
                                                         ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:790:55: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, float, float, float, float, void *) except *' to 'hb_draw_cubic_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          if drawfuncs == NULL:
              drawfuncs = hb_draw_funcs_create()
              hb_draw_funcs_set_move_to_func(drawfuncs, _pen_move_to_func, NULL, NULL)
              hb_draw_funcs_set_line_to_func(drawfuncs, _pen_line_to_func, NULL, NULL)
              hb_draw_funcs_set_cubic_to_func(drawfuncs, _pen_cubic_to_func, NULL, NULL)
              hb_draw_funcs_set_quadratic_to_func(drawfuncs, _pen_quadratic_to_func, NULL, NULL)
                                                             ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:791:59: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, float, float, void *) except *' to 'hb_draw_quadratic_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
              drawfuncs = hb_draw_funcs_create()
              hb_draw_funcs_set_move_to_func(drawfuncs, _pen_move_to_func, NULL, NULL)
              hb_draw_funcs_set_line_to_func(drawfuncs, _pen_line_to_func, NULL, NULL)
              hb_draw_funcs_set_cubic_to_func(drawfuncs, _pen_cubic_to_func, NULL, NULL)
              hb_draw_funcs_set_quadratic_to_func(drawfuncs, _pen_quadratic_to_func, NULL, NULL)
              hb_draw_funcs_set_close_path_func(drawfuncs, _pen_close_path_func, NULL, NULL)
                                                           ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:792:57: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, void *) except *' to 'hb_draw_close_path_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                       int,  # gid
                                       object,  # user_data
                                   ], int],  # h_advance
                                   user_data: object = None) -> None:
          hb_font_funcs_set_glyph_h_advance_func(
              self._hb_ffuncs, _glyph_h_advance_func, <void*>user_data, NULL)
                               ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:981:29: Cannot assign type 'hb_position_t (hb_font_t *, void *, hb_codepoint_t, void *) except? -1' to 'hb_font_get_glyph_h_advance_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                       int,  # gid
                                       object,  # user_data
                                   ], int],  # v_advance
                                   user_data: object = None) -> None:
          hb_font_funcs_set_glyph_v_advance_func(
              self._hb_ffuncs, _glyph_v_advance_func, <void*>user_data, NULL)
                               ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:992:29: Cannot assign type 'hb_position_t (hb_font_t *, void *, hb_codepoint_t, void *) except? -1' to 'hb_font_get_glyph_v_advance_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                      int,  # gid
                                      object,  # user_data
                                  ], (int, int, int)],  # success, v_origin_x, v_origin_y
                                  user_data: object = None) -> None:
          hb_font_funcs_set_glyph_v_origin_func(
              self._hb_ffuncs, _glyph_v_origin_func, <void*>user_data, NULL)
                               ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1003:29: Cannot assign type 'hb_bool_t (hb_font_t *, void *, hb_codepoint_t, hb_position_t *, hb_position_t *, void *) except? -1' to 'hb_font_get_glyph_v_origin_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                  int,  # gid
                                  object,  # user_data
                              ], str],  # name
                              user_data: object = None) -> None:
          hb_font_funcs_set_glyph_name_func(
              self._hb_ffuncs, _glyph_name_func, <void*>user_data, NULL)
                               ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1014:29: Cannot assign type 'hb_bool_t (hb_font_t *, void *, hb_codepoint_t, char *, unsigned int, void *) except? -1' to 'hb_font_get_glyph_name_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                     int,  # unicode
                                     object,  # user_data
                                 ], int],  # gid
                                 user_data: object = None) -> None:
          hb_font_funcs_set_nominal_glyph_func(
              self._hb_ffuncs, _nominal_glyph_func, <void*>user_data, NULL)
                               ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1025:29: Cannot assign type 'hb_bool_t (hb_font_t *, void *, hb_codepoint_t, hb_codepoint_t *, void *) except? -1' to 'hb_font_get_nominal_glyph_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                      Font,
                                      object,  # user_data
                                  ], FontExtents],  # extents
                                  user_data: object = None) -> None:
          hb_font_funcs_set_font_h_extents_func(
              self._hb_ffuncs, _font_h_extents_func, <void*>user_data, NULL)
                               ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1035:29: Cannot assign type 'hb_bool_t (hb_font_t *, void *, hb_font_extents_t *, void *) except? -1' to 'hb_font_get_font_h_extents_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                                      Font,
                                      object,  # user_data
                                  ], FontExtents],  # extents
                                  user_data: object = None) -> None:
          hb_font_funcs_set_font_v_extents_func(
              self._hb_ffuncs, _font_v_extents_func, <void*>user_data, NULL)
                               ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1045:29: Cannot assign type 'hb_bool_t (hb_font_t *, void *, hb_font_extents_t *, void *) except? -1' to 'hb_font_get_font_v_extents_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                  user_data_p = <void*>PyCapsule_GetPointer(user_data, NULL)
              else:
                  user_data_p = <void*>user_data
          else:
              self._move_to_func = func
              func_p = _move_to_func
                       ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1316:21: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, void *) except *' to 'hb_draw_move_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                  user_data_p = <void*>PyCapsule_GetPointer(user_data, NULL)
              else:
                  user_data_p = <void*>user_data
          else:
              self._line_to_func = func
              func_p = _line_to_func
                       ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1340:21: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, void *) except *' to 'hb_draw_line_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                  user_data_p = <void*>PyCapsule_GetPointer(user_data, NULL)
              else:
                  user_data_p = <void*>user_data
          else:
              self._cubic_to_func = func
              func_p = _cubic_to_func
                       ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1368:21: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, float, float, float, float, void *) except *' to 'hb_draw_cubic_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                  user_data_p = <void*>PyCapsule_GetPointer(user_data, NULL)
              else:
                  user_data_p = <void*>user_data
          else:
              self._quadratic_to_func = func
              func_p = _quadratic_to_func
                       ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1394:21: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, float, float, float, float, void *) except *' to 'hb_draw_quadratic_to_func_t'

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
                  user_data_p = <void*>PyCapsule_GetPointer(user_data, NULL)
              else:
                  user_data_p = <void*>user_data
          else:
              self._close_path_func = func
              func_p = _close_path_func
                       ^
  ------------------------------------------------------------

  src/uharfbuzz/_harfbuzz.pyx:1416:21: Cannot assign type 'void (hb_draw_funcs_t *, void *, hb_draw_state_t *, void *) except *' to 'hb_draw_close_path_func_t'
  Compiling src/uharfbuzz/_harfbuzz.pyx because it changed.
  Compiling src/uharfbuzz/_harfbuzz_test.pyx because it changed.
  [1/2] Cythonizing src/uharfbuzz/_harfbuzz.pyx
  Traceback (most recent call last):
    File "/Users/clupo/Github/uharfbuzz/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
      main()
    File "/Users/clupo/Github/uharfbuzz/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/Users/clupo/Github/uharfbuzz/.venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/private/var/folders/fd/t86sf39s0_b_vn713l6w1ztc00g3y4/T/pip-build-env-0n0jbm99/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/private/var/folders/fd/t86sf39s0_b_vn713l6w1ztc00g3y4/T/pip-build-env-0n0jbm99/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
      self.run_setup()
    File "/private/var/folders/fd/t86sf39s0_b_vn713l6w1ztc00g3y4/T/pip-build-env-0n0jbm99/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in run_setup
      exec(code, locals())
    File "<string>", line 85, in <module>
    File "/private/var/folders/fd/t86sf39s0_b_vn713l6w1ztc00g3y4/T/pip-build-env-0n0jbm99/overlay/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
      cythonize_one(*args)
    File "/private/var/folders/fd/t86sf39s0_b_vn713l6w1ztc00g3y4/T/pip-build-env-0n0jbm99/overlay/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
      raise CompileError(None, pyx_file)
  Cython.Compiler.Errors.CompileError: src/uharfbuzz/_harfbuzz.pyx
  error: subprocess-exited-with-error

@anthrotype
Copy link
Member

@anthrotype
Copy link
Member

If I set the legacy_implicit_noexcept=True cython compiler directive in setup.py, then the build completes but we get a bunch of warnings about

warning: src/uharfbuzz/_harfbuzz.pyx:60:40: Implicit noexcept declaration is deprecated. Function declaration should contain 'noexcept' keyword.

so it must be related to this change:
https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html?highlight=noexcept#exception-values-and-noexcept

@anthrotype
Copy link
Member

adding 'noexcept' keyword to all the function declarations where we get those warnings also fixes the build, but I am not 100% sure it is always the correct thing to do...

anthrotype added a commit that referenced this issue Jul 18, 2023
Fixes #164

with this change I can build uharbfbuzz also with the latest Cython 3.0.

The 'noexcept' is now required for non-extern cdef functions that are otherwise assumed to propagate exceptions by default in Cython 3. See https://cython.readthedocs.io/en/latest/src/userguide/migrating_to_cy30.html?highlight=noexcept#exception-values-and-noexcept
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

Successfully merging a pull request may close this issue.

2 participants