Skip to content

Fix SWIGWORDSIZE64 incorrectly set on macOS, breaking arm64 builds#295

Open
Tuguberk wants to merge 2 commits into
eProsima:masterfrom
Tuguberk:fix/macos-arm64-swig-wordsize
Open

Fix SWIGWORDSIZE64 incorrectly set on macOS, breaking arm64 builds#295
Tuguberk wants to merge 2 commits into
eProsima:masterfrom
Tuguberk:fix/macos-arm64-swig-wordsize

Conversation

@Tuguberk
Copy link
Copy Markdown

Problem

Building fastdds_python on macOS arm64 (Apple Silicon) fails with type mismatch errors in the SWIG-generated wrapper:

fastddsPYTHON_wrap.cxx: error: cannot initialize return object of type
  'std::vector<unsigned long, std::allocator<unsigned long>> *'
  with an rvalue of type 'std::vector<unsigned long long> *'

Root cause

CMakeLists.txt sets SWIGWORDSIZE64 for all UNIX 64-bit platforms:

if(UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8)
    set_property(TARGET ${PROJECT_NAME} PROPERTY
        SWIG_COMPILE_DEFINITIONS SWIGWORDSIZE64)
endif()

When SWIGWORDSIZE64 is defined, SWIG's stdint.i maps uint64_t to unsigned long:

#if defined(SWIGWORDSIZE64)
typedef unsigned long int uint64_t;   // what SWIG assumes
#else
typedef unsigned long long int uint64_t;

On Linux x86_64 and aarch64, the system <cstdint> also defines uint64_t as unsigned long — so SWIGWORDSIZE64 is correct there.

On macOS (including arm64), the system <cstdint> defines uint64_t as unsigned long long. Because macOS is also a 64-bit UNIX system, the condition was true, causing a mismatch between SWIG's assumed type and the compiler's actual type for std::vector<uint64_t>.

Fix

Exclude Apple platforms from the SWIGWORDSIZE64 definition. On macOS, SWIG's fallback (unsigned long long) correctly matches the system type.

if(UNIX AND NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8)

Testing

  • Platform: macOS 15 Sequoia, Apple Silicon (arm64)
  • Toolchain: SWIG 4.4.1, Apple Clang 17, Python 3.13
  • FastDDS: v3.4.0 (fastdds_python v2.4.0)
  • Full build succeeds: colcon build --packages-select fastdds_python
  • Import verified: python3 -c "import fastdds; print(fastdds.DomainParticipantFactory)"

MiguelCompany and others added 2 commits November 4, 2025 14:12
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
On macOS (including Apple Silicon arm64), the system defines uint64_t
as `unsigned long long` in <cstdint>. However, SWIG's stdint.i maps
uint64_t to `unsigned long` when SWIGWORDSIZE64 is defined.

The previous condition `UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8` evaluates
to true on macOS because macOS is a POSIX-compliant 64-bit OS. This
causes SWIG to define uint64_t as `unsigned long`, while the compiler
sees it as `unsigned long long`, producing type mismatch errors in the
generated fastddsPYTHON_wrap.cxx:

  error: cannot initialize return object of type
    'std::vector<unsigned long> *'
    with an rvalue of type 'std::vector<unsigned long long> *'

The fix excludes Apple platforms from setting SWIGWORDSIZE64. On Linux
x86_64 and aarch64, uint64_t is `unsigned long`, so SWIGWORDSIZE64
remains correct there. On macOS, SWIG's fallback (unsigned long long)
matches the system definition.

Tested on macOS 15 (Sequoia) with Apple Silicon (arm64), SWIG 4.4.1,
Clang 17, FastDDS 3.4.0.

Signed-off-by: Tuguberk <akbulut.tugberk@gmail.com>
@Tuguberk Tuguberk force-pushed the fix/macos-arm64-swig-wordsize branch from 8fcd3f7 to 5dbfaf2 Compare May 12, 2026 10:48
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 this pull request may close these issues.

2 participants