nodejs-mobile / prebuild-for-nodejs-mobile

CLI tool to compile node.js native modules for mobile
MIT License
15 stars 1 forks source link

Native addon directory structure when building for iOS targets #3

Open kr617 opened 7 months ago

kr617 commented 7 months ago

I'm prototyping a simple C++ addon that will run on iOS devices and simulators (as well as Android devices) as part of a Node application using Node.js for Mobile Apps. When building my addon for iOS with prebuild-for-nodejs-mobile, the tool produces some output that confuses me. Here's an example:

% npx prebuild-for-nodejs-mobile ios-arm64-simulator
Minimum iOS version supported is incorrect (14.0), patching it with "vtool" to become 13.0
BUILT prebuilds/ios-arm64-simulator/dummyaddon.node
% tree prebuilds
prebuilds
└── ios-arm64-simulator
    └── dummyaddon.node
        └── dummyaddon

3 directories, 1 file

I have two questions. First, what is the cause of the "Minimum iOS version" warning and should this concern me?

Second, why does the tool place the final addon inside a directory with a ".node" extension, but the addon itself has no ".node" extension? I tried loading the addon in my Node app (running within an iOS simulator) using variations of the following:

const addon = require('./prebuilds/ios-arm64-simulator/dummyaddon.node');

All of these attempts failed until I finally renamed the inner-most file from "dummyaddon" to "dummyaddon.node" as follows:

const addon = require('./prebuilds/ios-arm64-simulator/dummyaddon.node/dummyaddon.node');

I was then able to successfully call my C++ code from JavaScript.

Why does the tool produce this strange directory structure for iOS builds, rather than a simple .node file as it does for Android builds? Additionally, is there some method to package multiple iOS-related build targets together?

Thanks in advance for any help you can provide!