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

Workaround for an issue with Cmake builds that happens when cross-compiling using Cmake on macOS x86_64 CPUs with target CPU arm64 #12240

Closed

Conversation

shpala
Copy link
Contributor

@shpala shpala commented Jan 16, 2024

This is a temporary workaround for Cmake bug that only sets the correct CMAKE_SYSTEM_PROCESSOR for cross-compilation when target CMAKE_SYSTEM_NAME differs from CMAKE_HOST_NAME:
https://gitlab.kitware.com/cmake/cmake/-/issues/25640

Fix cross-compilation on macOS x86_64 CPUs with target CPU arm64 by manually setting CMAKE_SYSTEM_PROCESSOR to the cross-compilation target whenever CMAKE_SYSTEM_PROCESSOR doesn't match CMAKE_OSX_ARCHITECTURES after project() call. This is probably a Cmake bug that happens on macOS.
Closes #12239

The issue happens when RocksDB is built using the follwoing command:
cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_PROCESSOR=arm64 ..
The build itself succeeds, but because Cmake wrongly sets CMAKE_SYSTEM_PROCESSOR to x86_64 instead of arm64 and causes crc32c_arm64.cc not to be compiled.
This in turn makes the project fails any linking with RocksDB:

Undefined symbols for architecture arm64:
"crc32c_arm64(unsigned int, unsigned char const*, unsigned long)", referenced from:
rocksdb::crc32c::ExtendARMImpl(unsigned int, char const*, unsigned long) in librocksdb.a(crc32c.cc.o)

@shpala shpala marked this pull request as draft January 16, 2024 21:13
@shpala shpala force-pushed the pavel/fix_macos_cross_compilation branch 2 times, most recently from 2ba5996 to 6c53d16 Compare January 16, 2024 21:22
@shpala shpala marked this pull request as ready for review January 16, 2024 21:24
@shpala shpala force-pushed the pavel/fix_macos_cross_compilation branch 3 times, most recently from 39d6ca8 to c783fc7 Compare January 17, 2024 08:28
@shpala shpala changed the title Fix cross-compilation on macOS x86_64 CPUs with target CPU arm64 Fix cross-compilation using Cmake on macOS x86_64 CPUs with target CPU arm64 Jan 17, 2024
@shpala shpala force-pushed the pavel/fix_macos_cross_compilation branch 3 times, most recently from 71ec716 to 5c23868 Compare January 22, 2024 10:34
@shpala shpala force-pushed the pavel/fix_macos_cross_compilation branch from 5c23868 to 9ee960e Compare January 26, 2024 18:44
@shpala shpala changed the title Fix cross-compilation using Cmake on macOS x86_64 CPUs with target CPU arm64 Workaround for a Cmake bug that happens when cross-compiling using Cmake on macOS x86_64 CPUs with target CPU arm64 Jan 27, 2024
@shpala shpala changed the title Workaround for a Cmake bug that happens when cross-compiling using Cmake on macOS x86_64 CPUs with target CPU arm64 Workaround for an issue with Cmake builds that happens when cross-compiling using Cmake on macOS x86_64 CPUs with target CPU arm64 Jan 30, 2024
@shpala shpala force-pushed the pavel/fix_macos_cross_compilation branch 6 times, most recently from 111752e to 745c8d3 Compare February 28, 2024 12:39
by manually setting CMAKE_SYSTEM_PROCESSOR to the cross-compilation target
whenever CMAKE_SYSTEM_PROCESSOR doesn't match CMAKE_OSX_ARCHITECTURES after project() call.
This is probably a Cmake bug that happens on macOS.
(facebook#12239)
@shpala shpala force-pushed the pavel/fix_macos_cross_compilation branch from 745c8d3 to f96fa2d Compare February 29, 2024 17:33
@facebook-github-bot
Copy link
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@facebook-github-bot
Copy link
Contributor

@pdillinger merged this pull request in 122510d.

kwadhwa18 pushed a commit to kwadhwa18/rocksdb that referenced this pull request Mar 18, 2024
…piling using Cmake on macOS x86_64 CPUs with target CPU arm64 (facebook#12240)

Summary:
This is a temporary workaround for Cmake bug that only sets the correct CMAKE_SYSTEM_PROCESSOR for cross-compilation when target CMAKE_SYSTEM_NAME differs from CMAKE_HOST_NAME:
https://gitlab.kitware.com/cmake/cmake/-/issues/25640

Fix cross-compilation on macOS x86_64 CPUs with target CPU arm64 by manually setting CMAKE_SYSTEM_PROCESSOR to the cross-compilation target whenever CMAKE_SYSTEM_PROCESSOR doesn't match CMAKE_OSX_ARCHITECTURES after project() call. This is probably a Cmake bug that happens on macOS.
Closes facebook#12239

The issue happens when RocksDB is built using the follwoing command:
cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_PROCESSOR=arm64 ..
The build itself succeeds, but because Cmake wrongly sets CMAKE_SYSTEM_PROCESSOR to x86_64 instead of arm64 and causes crc32c_arm64.cc not to be compiled.
This in turn makes the project fails any linking with RocksDB:

```
Undefined symbols for architecture arm64:
"crc32c_arm64(unsigned int, unsigned char const*, unsigned long)", referenced from:
rocksdb::crc32c::ExtendARMImpl(unsigned int, char const*, unsigned long) in librocksdb.a(crc32c.cc.o)
```

Pull Request resolved: facebook#12240

Reviewed By: cbi42

Differential Revision: D54811365

Pulled By: pdillinger

fbshipit-source-id: 0958e3092806dadd2f61d582b7251af13a5f3f06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants