Skip to content

macOS wheel fails to import - simdutf symbols not found at runtime #607

@edgarrmondragon

Description

@edgarrmondragon

Describe the bug

The library installs fine on Apple Silicon, but fails to on import:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import mssql_python
  File "/Users/personal/.cache/uv/archive-v0/c7DXyj30MtrFYthL/lib/python3.14/site-packages/mssql_python/__init__.py", line 14, in <module>
    from .helpers import Settings, get_settings, _settings, _settings_lock
  File "/Users/personal/.cache/uv/archive-v0/c7DXyj30MtrFYthL/lib/python3.14/site-packages/mssql_python/helpers.py", line 11, in <module>
    from mssql_python import ddbc_bindings
  File "/Users/personal/.cache/uv/archive-v0/c7DXyj30MtrFYthL/lib/python3.14/site-packages/mssql_python/ddbc_bindings.py", line 129, in <module>
    module = importlib.util.module_from_spec(spec)
ImportError: dlopen(/Users/personal/.cache/uv/archive-v0/c7DXyj30MtrFYthL/lib/python3.14/site-packages/mssql_python/ddbc_bindings.cp314-universal2.so, 0x0002): symbol not found in flat namespace '__ZN7simdutf40convert_utf16le_to_utf8_with_replacementEPKDsmPc'

To reproduce

Just import mssql_python fails:

uvx -p 3.14 --with mssql-python python -c 'import mssql_python'

Expected behavior

No errors on import.

Further technical details

Python version: 3.14
SQL Server version: SQL Server 2022 (mcr.microsoft.com/mssql/server:2022-latest)
Operating system: macOS 26.5

Additional context

I believe the root cause is that mssql_python/pybind/CMakeLists.txt tries find_package(...) before falling back to FetchContent.

find_package(simdutf CONFIG QUIET)
if(NOT simdutf_FOUND)
include(FetchContent)

Now, I think on the Azure Pipelines macOS-14 build runner, Homebrew has simdutf pre-installed, so find_package succeeds and links it as a dynamic library (/usr/local/opt/simdutf/lib/libsimdutf.34.dylib). That Homebrew path is baked into the x86_64 slice of the universal2 .so. I'm on Apple Silicon, so I think that suffers from a different problem, perhaps additionally that -undefined dynamic_lookup is passed to the linker:

set_target_properties(ddbc_bindings PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")

From the universal macOS .whl downloaded from PyPI:

otool -L dist/mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so

mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so (architecture x86_64):
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.120.2)
        /usr/local/opt/simdutf/lib/libsimdutf.34.dylib (compatibility version 34.0.0, current version 34.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1700.255.5)

mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so (architecture arm64):
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.120.2)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1700.255.5)

and the simdutf symbol is undefined in both arch slices:

$ nm -u mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so | rg simdutf
__ZN7simdutf40convert_utf16le_to_utf8_with_replacementEPKDsmPc

I can confirm that

- find_package(simdutf CONFIG QUIET)
-
- if(NOT simdutf_FOUND)
-     include(FetchContent)
-     message(STATUS "simdutf not found via find_package; downloading v8.2.0 source archive with FetchContent")
-     ...
-     FetchContent_MakeAvailable(simdutf)
- endif()
+ include(FetchContent)
+ message(STATUS "Downloading simdutf v8.2.0 source archive with FetchContent")
+ ...
+ FetchContent_MakeAvailable(simdutf)

does end up building a working wheel:

otool -L dist/mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so

dist/mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so (architecture x86_64):
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 2100.43.0)

dist/mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so (architecture arm64):
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1356.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 2100.43.0)
$ nm -u dist/mssql_python-1.8.0-cp314-cp314-macosx_15_0_universal2/mssql_python/ddbc_bindings.cp314-universal2.so | rg simdutf
<no output>

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginADOtriage doneIssues that are triaged by dev team and are in investigation.

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions