Fix SWIGWORDSIZE64 incorrectly set on macOS, breaking arm64 builds#295
Open
Tuguberk wants to merge 2 commits into
Open
Fix SWIGWORDSIZE64 incorrectly set on macOS, breaking arm64 builds#295Tuguberk wants to merge 2 commits into
Tuguberk wants to merge 2 commits into
Conversation
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>
8fcd3f7 to
5dbfaf2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Building
fastdds_pythonon macOS arm64 (Apple Silicon) fails with type mismatch errors in the SWIG-generated wrapper:Root cause
CMakeLists.txtsetsSWIGWORDSIZE64for all UNIX 64-bit platforms:When
SWIGWORDSIZE64is defined, SWIG'sstdint.imapsuint64_ttounsigned long:On Linux x86_64 and aarch64, the system
<cstdint>also definesuint64_tasunsigned long— soSWIGWORDSIZE64is correct there.On macOS (including arm64), the system
<cstdint>definesuint64_tasunsigned 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 forstd::vector<uint64_t>.Fix
Exclude Apple platforms from the
SWIGWORDSIZE64definition. On macOS, SWIG's fallback (unsigned long long) correctly matches the system type.Testing
colcon build --packages-select fastdds_pythonpython3 -c "import fastdds; print(fastdds.DomainParticipantFactory)"