mapbox / mapbox/node-pre-gyp

Cross compilation on mac for windows

Open
#672 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.2k
Forks
271
Avg merge
23h 40m
Merged PRs (30d)
2

Description

### **Question**

How to build for windows on mac?

I'm mimicking the build process of [node-sqlite3](https://github.com/TryGhost/node-sqlite3) in my project to bundle [this minimal example](https://nodeaddons.com/cross-platform-addons-with-node-pre-gyp/), a `now()` function.

Node-sqlite3 build output works correctly on windows even if it's generated on mac. But my program won't. What am I missing?

### **My code and logs**

Here's my code
```
// main.js
const binary = require('@mapbox/node-pre-gyp');
const path = require('path');
const binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json')));
console.log('binding_path', binding_path);
const binding = require(binding_path);
module.exports = exports = binding;
```

```
// binding.gyp
{
"targets": [
{
"target_name": "<(module_name)",
"sources": [ "native-rt.cc" ],
"conditions":[
["OS=='linux'", {
"sources": [ "native-rt_linux.cc" ]
}],
["OS=='mac'", {
"sources": [ "native-rt_mac.cc" ]
}],
["OS=='win'", {
"sources": [ "native-rt_win.cc" ]
}]
],
"include_dirs" : [
"/dev/null || (rm -rf "/path/to/project/node_modules/sqlite3/lib/binding/napi-v6-win32-unknown-x64/node_sqlite3.node" && cp -af "Release/node_sqlite3.node" "/path/to/project/node_modules/sqlite3/lib/binding/napi-v6-win32-unknown-x64/node_sqlite3.node")
touch Release/obj.target/action_after_build.stamp

errorOut=node-pre-gyp info it worked if it ends with ok
node-pre-gyp verb cli [
node-pre-gyp verb cli '/path/to/user/.nvm/versions/node/v16.16.0/bin/node',
node-pre-gyp verb cli '/path/to/project/node_modules/sqlite3/node_modules/.bin/node-pre-gyp',
node-pre-gyp verb cli 'install',
node-pre-gyp verb cli '--fallback-to-build',
node-pre-gyp verb cli '--verbose'
node-pre-gyp verb cli ]
node-pre-gyp info using node-pre-gyp@1.0.9
node-pre-gyp info using node@16.16.0 | darwin | x64
node-pre-gyp verb command install [ 'napi_build_version=6' ]
node-pre-gyp http GET https://github.com/TryGhost/node-sqlite3/releases/download/v5.0.10/napi-v6-win32-unknown-x64.tar.gz
node-pre-gyp http download proxy agent configured using: "http://127.0.0.1:7890/"
node-pre-gyp ERR! install request to https://github.com/TryGhost/node-sqlite3/releases/download/v5.0.10/napi-v6-win32-unknown-x64.tar.gz failed, reason: Client network socket disconnected before secure TLS connection was established
node-pre-gyp WARN Pre-built binaries not installable for sqlite3@5.0.10 and electron@19.0.9 (electron-v19.0 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error request to https://github.com/TryGhost/node-sqlite3/releases/download/v5.0.10/napi-v6-win32-unknown-x64.tar.gz failed, reason: Client network socket disconnected before secure TLS connection was established
node-pre-gyp verb command build [ 'rebuild', 'napi_build_version=6' ]
gyp info it worked if it ends with ok
gyp info using node-gyp@8.4.1
gyp info using node@16.16.0 | darwin | x64
gyp info ok
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli '/path/to/user/.nvm/versions/node/v16.16.0/bin/node',
gyp verb cli '/path/to/project/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli 'configure',
gyp verb cli '--fallback-to-build',
gyp verb cli '--loglevel=verbose',
gyp verb cli '--module=/path/to/project/node_modules/sqlite3/lib/binding/napi-v6-win32-unknown-x64/node_sqlite3.node',
gyp verb cli '--module_name=node_sqlite3',
gyp verb cli '--module_path=/path/to/project/node_modules/sqlite3/lib/binding/napi-v6-win32-unknown-x64',
gyp verb cli '--napi_version=8',
gyp verb cli '--node_abi_napi=napi',
gyp verb cli '--napi_build_version=6',
gyp verb cli '--node_napi_label=napi-v6'
gyp verb cli ]
gyp info using node-gyp@8.4.1
gyp info using node@16.16.0 | darwin | x64
gyp verb command configure []
gyp verb download using dist-url https://electronjs.org/headers
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - executable path is "/path/to/user/.pyenv/versions/3.7.5/bin/python3"
gyp verb find Python - executing "/path/to/user/.pyenv/versions/3.7.5/bin/python3" to get version
gyp verb find Python - version is "3.7.5"
gyp info find Python using Python version 3.7.5 found at "/path/to/user/.pyenv/versions/3.7.5/bin/python3"
gyp verb get node dir compiling against --target node version: 19.0.9
gyp verb command install [ '19.0.9' ]
gyp verb download using dist-url https://electronjs.org/headers
gyp verb install input version string "19.0.9"
gyp verb install installing version: 19.0.9
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 19.0.9
gyp verb build dir attempting to create "build" dir: /path/to/project/node_modules/sqlite3/build
gyp verb build dir "build" dir needed to be created? Yes
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /path/to/project/node_modules/sqlite3/build/config.gypi
gyp verb config.gypi checking for gypi file: /path/to/project/node_modules/sqlite3/config.gypi
gyp verb common.gypi checking for gypi file: /path/to/project/node_modules/sqlite3/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
gyp info spawn /path/to/user/.pyenv/versions/3.7.5/bin/python3
gyp info spawn args [
gyp info spawn args '/path/to/project/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/path/to/project/node_modules/sqlite3/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/path/to/project/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/path/to/user/.electron-gyp/19.0.9/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/path/to/user/.electron-gyp/19.0.9',
gyp info spawn args '-Dnode_gyp_dir=/path/to/project/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/path/to/user/.electron-gyp/19.0.9/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/path/to/project/node_modules/sqlite3',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info ok
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli '/path/to/user/.nvm/versions/node/v16.16.0/bin/node',
gyp verb cli '/path/to/project/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli 'build',
gyp verb cli '--fallback-to-build',
gyp verb cli '--loglevel=verbose',
gyp verb cli '--module=/path/to/project/node_modules/sqlite3/lib/binding/napi-v6-win32-unknown-x64/node_sqlite3.node',
gyp verb cli '--module_name=node_sqlite3',
gyp verb cli '--module_path=/path/to/project/node_modules/sqlite3/lib/binding/napi-v6-win32-unknown-x64',
gyp verb cli '--napi_version=8',
gyp verb cli '--node_abi_napi=napi',
gyp verb cli '--napi_build_version=6',
gyp verb cli '--node_napi_label=napi-v6'
gyp verb cli ]
gyp info using node-gyp@8.4.1
gyp info using node@16.16.0 | darwin | x64
gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /path/to/user/.electron-gyp/19.0.9
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
../src/backup.cc:179:9: warning: unused variable 'status' [-Wunused-variable]
int status = napi_create_async_work(
^
../src/backup.cc:252:5: warning: unused variable 'status' [-Wunused-variable]
BACKUP_BEGIN(Step);
^
../src/macros.h:182:9: note: expanded from macro 'BACKUP_BEGIN'
int status = napi_create_async_work( \
^
../src/backup.cc:319:5: warning: unused variable 'status' [-Wunused-variable]
BACKUP_BEGIN(Finish);
^
../src/macros.h:182:9: note: expanded from macro 'BACKUP_BEGIN'
int status = napi_create_async_work( \
^
3 warnings generated.
../src/database.cc:155:9: warning: unused variable 'status' [-Wunused-variable]
int status = napi_create_async_work(
^
../src/database.cc:249:9: warning: unused variable 'status' [-Wunused-variable]
int status = napi_create_async_work(
^
../src/database.cc:562:9: warning: unused variable 'status' [-Wunused-variable]
int status = napi_create_async_work(
^
../src/database.cc:671:9: warning: unused variable 'status' [-Wunused-variable]
int status = napi_create_async_work(
^
4 warnings generated.
../src/statement.cc:122:9: warning: unused variable 'status' [-Wunused-variable]
int status = napi_create_async_work(
^
../src/statement.cc:350:5: warning: unused variable 'status' [-Wunused-variable]
STATEMENT_BEGIN(Bind);
^
../src/macros.h:146:9: note: expanded from macro 'STATEMENT_BEGIN'
int status = napi_create_async_work( \
^
../src/statement.cc:402:5: warning: unused variable 'status' [-Wunused-variable]
STATEMENT_BEGIN(Get);
^
../src/macros.h:146:9: note: expanded from macro 'STATEMENT_BEGIN'
int status = napi_create_async_work( \
^
../src/statement.cc:474:5: warning: unused variable 'status' [-Wunused-variable]
STATEMENT_BEGIN(Run);
^
../src/macros.h:146:9: note: expanded from macro 'STATEMENT_BEGIN'
int status = napi_create_async_work( \
^
../src/statement.cc:544:5: warning: unused variable 'status' [-Wunused-variable]
STATEMENT_BEGIN(All);
^
../src/macros.h:146:9: note: expanded from macro 'STATEMENT_BEGIN'
int status = napi_create_async_work( \
^
../src/statement.cc:645:5: warning: unused variable 'status' [-Wunused-variable]
STATEMENT_BEGIN(Each);
^
../src/macros.h:146:9: note: expanded from macro 'STATEMENT_BEGIN'
int status = napi_create_async_work( \
^
../src/statement.cc:772:5: warning: unused variable 'status' [-Wunused-variable]
STATEMENT_BEGIN(Reset);
^
../src/macros.h:146:9: note: expanded from macro 'STATEMENT_BEGIN'
int status = napi_create_async_work( \
^
7 warnings generated.
ld: warning: object file (Release/sqlite3.a(sqlite3.o)) was built for newer macOS version (10.13) than being linked (10.7)
gyp info ok
node-pre-gyp info ok

```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with main.js and binding.gyp, then compare their platform conditions and build output with the included node-sqlite3 fallback-build log. Identify why the generated .node file is rejected as an invalid Win32 application; done means the addon built on macOS loads successfully on Windows.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, javascript, nodejs
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.