XapaJIaMnu / translateLocally

Fast and secure translation on your local machine, powered by marian and Bergamot.
MIT License
501 stars 28 forks source link

macOS Univeral binary for Intel & Apple Silicon #129

Open jelmervdl opened 1 year ago

jelmervdl commented 1 year ago

I've been trying to make a universal binary for x86 and M1/2 hardware so we can distribute just one app for all of macOS. This issue is here for tracking findings.

Getting rid of CMAKE_BUILD_ARCH is necessary. Right now I'm stuck on cpuinfo not supporting it, because it does assume it is being built for a single architecture.

Command (and many changes to the CMake files so not entirely useful on its own):

cmake .. \
  -DGIT_SUBMODULE=Off \
  -DCMAKE_SYSTEM_NAME=Darwin \
  -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
  -DSPM_ENABLE_TCMALLOC=Off \
  -DSSPLIT_USE_INTERNAL_PCRE2=On \
  -DBUILD_EXTERNAL_LIBARCHIVE=On \
  -DICU_ROOT_DIR=(brew --prefix icu4c) \
  -DCMAKE_PREFIX_PATH=/Users/jelmer/Qt/6.2.2/macos \
&& ../cmake/fix_ruy_build.sh ../ ./ \
&& make -j8 translateLocally.dmg

Issues: https://github.com/loongson/cpuinfo/blob/5d5348e000f91baa9849d7b30b22fce8a77ae3da/CMakeLists.txt#L167-L169

https://github.com/loongson/cpuinfo/blob/5d5348e000f91baa9849d7b30b22fce8a77ae3da/CMakeLists.txt#L55-L57

XapaJIaMnu commented 1 year ago

What if we have a separate binary? Would that be too bad? How is usually Apple software distributed?

jelmervdl commented 1 year ago

Usually universal binary. You never really have to choose which chipset you have when downloading stuff. Only open source stuff makes you choose. OBS would be a popular example. So it is not unheard of.

Apple itself is moving towards shipping stripped & pre-optimised binaries through their App Store but that's all automated and not really relevant for us right now.

XapaJIaMnu commented 1 year ago

So, should we open an issue on cpuinfo? What do we use cpuinfo for anyways? Setting the right cmake flags? Our usecase is to compile for generic architecture...

jelmervdl commented 1 year ago

ruy and fbgemm embed cpuinfo. I am able to compile an intel-only or arm-only version now.

My intuition now is that cpuinfo will probably need quite a bit of refactoring to support mutlicpu compilation (because they rely on cmake for defining cpu features…)

XapaJIaMnu commented 1 year ago

We can get rid of fbgemm since their models aren't compatible with multiple architecture... But not ruy... Maybe with onednn later..?

jelmervdl commented 1 year ago

Maybe indeed. My suggestion right now is to just deal with it at a later stage, and distribute an Apple Silicon build separately right now.