open-quantum-safe / liboqs

C library for prototyping and experimenting with quantum-resistant cryptography
https://openquantumsafe.org/
Other
1.91k stars 465 forks source link

Build liboqs for MacOS M1 (arm64) #1973

Open ivcantero opened 3 weeks ago

ivcantero commented 3 weeks ago

Hi I've tried to build liboqs for arm64 MacOS in a intel MacOS. The main purpose is to build later Chromium for that arm64 architecture, but it will apply to other purposes also. I used the proper parameter -DCMAKE_OSX_ARCHITECTURES=arm64 in the following command: cmake .. -G"Ninja" -DCMAKE_INSTALL_PREFIX=$CHROMIUM_ROOT/third_party/boringssl/src/oqs -DOQS_USE_OPENSSL=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_OSX_ARCHITECTURES=arm64

image

but when I run ninja I'm having errors as if the code wasn't ready to support this arm64 architecture. Code would have to be adapted to be valid for that architecture.

image image image

I think that the problem are these headers shouldn't be used in arm64 architectures according to link:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/include/wmmintrin.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/include/emmintrin.h /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/include/xmmintrin.h

Once removed, other parts of the code have to be changed also to fix code, such as aes128_ni.c or aes256_ni.c Created this Issue as suggested here

SWilson4 commented 3 weeks ago

I'm a little out of my depth when it comes to the intricacies of building the library on a Mac, but perhaps this could this be fixed with an appropriate CMake toolchain file, similarly to the way we handle cross-compiling for ARM on an x86_64 Linux machine?