M-CreativeLab / nodejs-android

The Node.js for JSAR runtime
Other
1 stars 1 forks source link

How to compile shared library as a macos universal binary #1

Open yorkie opened 1 year ago

yorkie commented 1 year ago

MacOS Universay Binary is a format which is possible for running both on Intel and Apple chips, which is produced by the following command:

$ lipo -create -output libnode_universal.dylib libnode_x86.dylib libnode_arm64.dylib

Before the above merge, we need to compile a binary at M1/M2 macbook:

export CC_host="cc -arch x86_64" 
export CXX_host="c++ -arch x86_64"
export CC_target="cc -arch x86_64" 
export CXX_target="c++ -arch x86_64"

CC="cc -arch x86_64" CXX="c++ -arch x86_64" ./configure \
    --dest-cpu=x86_64 \
    --tag=$(TAG) \
    --with-intl=none \
    --without-inspector \
    --shared

arch -x86_64 make -j10

At MacOS, use arch to convert the target architecture such as x86_64, then do run ./configure && make command.

yorkie commented 1 year ago

This is not an issue about compiling on android, but a note about how to compile a shared library for your macOS users who might be using x86 software, for example, using Unity Editor(Intel) to load your native plugins.