ezra-bible-app / node-sword-interface

JavaScript (N-API) interface to SWORD library
GNU General Public License v2.0
22 stars 2 forks source link

Support building on M1 Macs. #32

Closed swils closed 2 years ago

swils commented 2 years ago

Homebrew on ARM architectures puts its packages under /opt/homebrew rather than /usr/local/opt. This was handled by using pkg-config. We also had to add an extra path to PKG_CONFIG_PATH. This is only for ARM; on Intel Macs, the default path for pkg-config seemed to work fine.

Fixes #31.

tobias-klein commented 2 years ago

Thank you for your efforts @swils!

When running this on my Mac mini based on macOS 12.6 and Xcode 13.3.1 and node 14.17.5 I get the following error messages, indicating that this does not fly automatically on an Intel Mac.

tobi@MacMini node-sword-interface % npm run build

> node-sword-interface@0.253.0 build /Users/tobi/Dev/node-sword-interface
> node-gyp rebuild

Package icu-uc was not found in the pkg-config search path.
Perhaps you should add the directory containing `icu-uc.pc'
to the PKG_CONFIG_PATH environment variable
No package 'icu-uc' found
Package icu-io was not found in the pkg-config search path.
Perhaps you should add the directory containing `icu-io.pc'
to the PKG_CONFIG_PATH environment variable
No package 'icu-io' found
Package icu-i18n was not found in the pkg-config search path.
Perhaps you should add the directory containing `icu-i18n.pc'
to the PKG_CONFIG_PATH environment variable
No package 'icu-i18n' found
gyp: Call to 'PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig" pkg-config --libs icu-uc icu-io icu-i18n' returned exit status 1 while in binding.gyp. while trying to load binding.gyp

Once I added the path /usr/local/opt/icu4c/lib/pkgconfig to the PKG_CONFIG_PATH in binding.gyp, it started working!

tobi@MacMini node-sword-interface % git diff
diff --git a/binding.gyp b/binding.gyp
index 3765448..49b5685 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -113,7 +113,7 @@
                 "libraries": [
                     '<(module_root_dir)/sword_build/libsword.a',
                     '<!@(pkg-config --libs libcurl)',
-                    '<!@(PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig" pkg-config --libs icu-uc icu-io icu-i18n)'
+                    '<!@(PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig" pkg-config --libs icu-uc icu-io icu-i18n)'
                 ],
                 "dependencies": [
                     "<!(node -p \"require('node-addon-api').gyp\")", 

Would you mind adding that change? :)

swils commented 2 years ago

Ok added it. (It did work on my own old Intel Mac but apparently there's more to it.)

tobias-klein commented 2 years ago

Excellent! Thanks for your contribution! I just tagged 0.254.0 and pushed it to npmjs!

swils commented 2 years ago

Thx for your help!

FYI: I'm looking whether I can include your very nice interface in my VSCode extension. But it would have to become a platform-specific extension with multiple builds per release... so I'm first seeing how that would work out in practice.