Closed typelogic closed 3 years ago
While building libidpasslite.dylib
for a macos M1 chip using the homebrew GNU C compiler (gcc-11), we encountered a build issue in the dependency libsodium
. We did not encounter any issue with a macos x86_64 chip using the homebrew GNU C compiler.
I forked in https://github.com/typelogic/libsodium in branch macos_test
and is now able to build libsodium
libraries for macos M1 chip, using the native Apple C compiler.
Digging further, I found that gcc-11 has no support for Apple's M1 chip yet..
Additional work to be done to adjust the idpass-lite build scripts to properly deal with macos M1 and x86_64 chips using Apple's native C/C++ compiler.
I have tested these changes in the MacOS Intel and M1 laptops. These changes are build scripts cmake changes to improve the repository cloning speed and to address MacOS platforms. No C/C++ code changes, except for those related to WITH_JNI
pre-processor improvement macro to decouple it from any Java/JNI header dependencies which is only applicable for Linux and Android but not for a MacOS build. A MacOS laptop (intel, arm) should be able to build a libidpasslite.dylib
without needing Java JNI headers and this is what the WITH_JNI
pre-processor is for.
Issue
This PR are additional changes on top of https://github.com/idpass/idpass-lite/pull/16. The aim as that using a MacBook Air Darwin x86_64 laptop, doing a build by
./build.sh macos
will produce thelibidpasslite.dylib
library.Changes
There were subtle differences in MacOS cmake. The reason for these subtle differences reflects the reality that a build process involves intricate details that already falls outside the reach of cmake. These differences took time to locate and rectify and these didn't manifest any issues during a Linux build. They are described as:
idpasstests
which is dynamically linking againstlibidpasslite.{so, dylib}
should not link to the protobuf generated C++api.pb.cc
andidpaslite.pb.cc
. The Linux build is forgiving on this one, and didn't manifest any anomalies. But inmacos
it spitted out a cryptic error message when executingidpasstest
.CMAKE_STRIP
only needs to be done in a Linux build. Doing it in amacos
build will throw a semi-cryptic build error message.target_link_libraries
inidpasstests
matters. This one was the most difficult to identify. A different order resulted to an unusual protobuf API behavior whereinx.encryptionkey().size()
always returns64
despite thebytes
array is set to an array of length32
. I have no further comment with regards on how to identify in scientific method the correct order a priori, except for the fact that the final built code must be tested and if by reversing the linkage order fixes any observed issues, then that is the needed order. Linkage ordering issues is a known phenomenon.Other simpler changes involved using the
WITH_JNI
variable to decouple the build of the native library to any Javajavac, jni.h
header requirements.In summary, the change files are in:
lib/{src,tests}/CMakeLists.txt
to insert cmake logic to handle the build in a Linux or Mac OS environment.lib/src,tests}/{idpass.cpp, idpasstests.cpp}
to use theWITH_JNI
variable to manage Java couplingmacos
build scripts independencies/scripts/build.{libsodium,dlib,protobuf}.macos.sh
build.sh