sodium-friends / sodium-native

Low level bindings for libsodium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't compile on Windows for Electron v9 or Node lower than v12.16 (napi_detach_arraybuffer thing)

vladimiry opened this issue · comments

Using Node v12.14.1.

C:\dev\sodium-native>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  binding.c
c:\dev\sodium-native\binding.c(70): warning C4013: napi_detach_arraybuffer: ??? ???????????; ?????????????? "extern" ? ????????? ???? "int" [C:\dev\sodium-native\build\sodium.vcxproj]
  win_delay_load_hook.cc
     ╤ετΣασ≥±  ßΦßδΦε≥σΩα C:\dev\sodium-native\build\Release\sodium.lib Φ εß·σΩ≥ C:\dev\sodium-native\build\Release\sodium.exp
binding.obj : error LNK2019: ±±√δΩα φα φσ≡ατ≡σ°σφφ√Θ Γφσ°φΦΘ ±Φ∞Γεδ napi_detach_arraybuffer Γ ⌠≤φΩ÷ΦΦ sn_sodium_free [C:\dev\sodium-native\build\sodium.vcxproj]
C:\dev\sodium-native\build\Release\sodium.node : fatal error LNK1120: φσ≡ατ≡σ°σφφ√⌡ Γφσ°φΦ⌡ ²δσ∞σφ≥εΓ: 1 [C:\dev\sodium-native\build\sodium.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:223:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.10240
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\dev\sodium-native
gyp ERR! node -v v12.14.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sodium-native@3.1.1 install: `node-gyp-build "node preinstall.js" "node postinstall.js"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sodium-native@3.1.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2020-05-19T19_29_51_458Z-debug.log

Then if you run npx node-gyp rebuild --target=9.0.0 --arch=x64 --dist-url=https://electronjs.org/headers or npx node-gyp rebuild --target=v10.0.0-nightly.20200223 --arch=x64 --dist-url=https://electronjs.org/headers you get the similar error (these electron version come with node 12.14.1 and 12.15.0). But npx node-gyp rebuild --target=v10.0.0-nightly.20200226 --arch=x64 --dist-url=https://electronjs.org/headers (comes with node v12.16.1) or npx node-gyp rebuild --target=12.16.1 --arch=x64 will work well.

It gets well compiled on Linux and macOS but not on Windows. So I have to revert to 3.0.1 which works since I guess napi_detach_arraybuffer call was not used there yet.

Unrelated to your issue, why are compiling it?

There are two primary reasons. In general (not specifically this project), I've faced many times that prebuilds just don't work well (like built with wrong configurations or on incompatible/too-new-environment--macos-case, etc) so it feels more safe to get it compiled from sources. And the second reason is that for some sort of software I like the dependencies get compiled from sources especially the security related ones. And the side benefit of compiling is that I get the issue noticed and then reported upstream :)

You can work around this by simply compiling against Node latest LTS on your platform.

The n-api build works seamlessly with electron

Thanks, will keep that in mind but sticking to 3.0.1 for now. Would like the issue to remain open.

@vladimiry I don't really think there's anything we can do about this. To me it looks like the header is missing this function definition, which indicates to me that the electron headers were not updated with the most recent minor version headers from node?

It's not only Electron related issue. It doesn't get compiled for node 12.14.1. According to the node docs napi_detach_arraybuffer added since v13.0.0 / v12.16.0. Did you consider adding respective engines.node property in the package.json?

@vladimiry How would the engines field help?

Well, it would explicitly tell me that I should use only specified in the semver range node versions. Right now there is no value defined, I was trying compiling stuff running unsupported node versions which ended up to be time wasting.

We do "feature detection" for the function, but I guess we could include the function prototype so compilers don't misbehave? That could have other bad consequences like a runtime crash if something like electron messes with things

sodium-native/binding.c

Lines 2561 to 2566 in 567aad4

const napi_node_version* version;
assert(napi_get_node_version(env, &version) == napi_ok);
if (version->major > 12 || (version->major == 12 && version->minor >= 16)) {
IS_ARRAY_BUFFER_DETACH_SUPPORTED = 1;
}

Alright, since there is nothing could be done I'm ok closing the issue. The workarounds are clear. I'm moving to electron v10 soon so then will switch to the latest sodium-native version.

Can confirm recent release is well compilable if I use electron v10.

Hello, I am trying to rebuild sodium-native for Electron (using electron-rebuild) and it doesn't work, not in 8.X neither 9.X neither v10-beta2.

× Rebuild Failed

An unhandled error occurred inside electron-rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  binding.c

The important error:

 'sodium/version.h': No such file or directory [C:\Users\user\my_project\node_modules\sodium-native\build\sodium.vcxproj]

I don't know what to do anymore

Try running npm run fetch-libsodium first, see.

@marc2332 Yeah, electron-rebuild does funky stuff. That's why we include prebuilds here so you don't have to rebuild. Is there a specific reason you want to build?

You might be able to use SODIUM_NATIVE_PREBUILD=1 PREBUILDS_ONLY=1 as an environment variable to disable rebuilding sodium-native

@vladimiry I have sodium-native as dependency so there isn't any git repository.

@emilbayes I got the "No native build.." error while using it in electron so I though about rebuildint it for my current version:
imagen

@emilbayes I have set the env variable to 1 as you said but when rebuilding hyperswarm which depends on a dependency that depends on sodium-native it's still being rebuilt and throwring the error, and even If I don't try to rebuild it, it gives me the "Error: no native.."

I normally rebuild it using electron-builder. You could try running npx electron-builder install-app-deps. Before execution this command I used to remove ./node_modules/sodium-native/build, ./node_modules/sodium-native/prebuilds, ./node_modules/sodium-native/lib dirs. I also remove ./node_modules/prebuild-install dir, just to make sure prebuilds won't be downloaded.

@marc2332 that error is from utp-native not sodium?

@vladimiry npx electron-rebuild install-app-deps also fails:
PS C:\Users\mespi\AppData\Roaming.graviton2\plugins\remote> npx electron-rebuild install-app-deps

PS C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote> npx electron-rebuild install-app-deps
× Rebuild Failed

An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@6.1.0
gyp info using node@13.8.0 | win32 | x64
gyp info find Python using Python version 2.7.14 found at "C:\Python27\python.exe"
gyp info find VS using VS2017 (15.9.28307.770) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Python27\python.exe
gyp info spawn args [
gyp info spawn args   'C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\sodium-native\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\mespi\\.electron-gyp\\10.0.0-beta.2\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\mespi\\.electron-gyp\\10.0.0-beta.2',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\mespi\\\\.electron-gyp\\\\10.0.0-beta.2\\\\<(target_arch)\\\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\sodium-native',
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   'C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\sodium-native\\build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
gyp info spawn args [
gyp info spawn args   'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64'
gyp info spawn args ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  binding.c
c:\users\mespi\appdata\roaming\.graviton2\plugins\remote\node_modules\sodium-native\libsodium\src\libsodium\include\sodium.h(5): fatal error C1083: No se puede abrir el archivo incluir: 'sodium/version.h': No such file or directory [C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\sodium-native\build\sodium.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:321:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=10.0.0-beta.2" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\sodium-native
gyp ERR! node -v v13.8.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok

Actually, the error is the same as before, it says it cannot find a file

@mafintosh No, it's about sodium-native, here is the full error:

PS C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote> npm run rebuild

> remote@0.0.1 rebuild C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote
> electron-rebuild -f -w hyperswarm

× Rebuild Failed

An unhandled error occurred inside electron-rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  binding.c
c:\users\mespi\appdata\roaming\.graviton2\plugins\remote\node_modules\sodium-native\libsodium\src\libsodium\include\sodium.h(5): fatal error C1083: No se puede abrir el archivo incluir: 'sodium/version.h': No such file or directory [C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\sodium-native\build\sodium.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:321:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=10.0.0-beta.2" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\sodium-native
gyp ERR! node -v v13.8.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok

Failed with exit code: 1

Error: Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  binding.c
c:\users\mespi\appdata\roaming\.graviton2\plugins\remote\node_modules\sodium-native\libsodium\src\libsodium\include\sodium.h(5): fatal error C1083: No se puede abrir el archivo incluir: 'sodium/version.h': No such file or directory [C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\sodium-native\build\sodium.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:321:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mespi\\AppData\\Roaming\\.graviton2\\plugins\\remote\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=10.0.0-beta.2" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source"
gyp ERR! cwd C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\sodium-native
gyp ERR! node -v v13.8.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok
Failed with exit code: 1
    at SafeSubscriber._error (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\spawn-rx\lib\src\index.js:267:84)
    at SafeSubscriber.__tryOrUnsub (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:205:16)
    at SafeSubscriber.error (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:156:26)
    at Subscriber._error (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:92:26)
    at Subscriber.error (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:72:18)
    at MapSubscriber.Subscriber._error (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:92:26)
    at MapSubscriber.Subscriber.error (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:72:18)
    at SafeSubscriber._next (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\spawn-rx\lib\src\index.js:242:65)
    at SafeSubscriber.__tryOrUnsub (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:205:16)
    at SafeSubscriber.next (C:\Users\mespi\AppData\Roaming\.graviton2\plugins\remote\node_modules\rxjs\internal\Subscriber.js:143:22)
npm ERR! code ELIFECYCLE
npm ERR! errno 4294967295
npm ERR! remote@0.0.1 rebuild: electron-rebuild -f -w hyperswarm
npm ERR! Exit status 4294967295
npm ERR!
npm ERR! Failed at the remote@0.0.1 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mespi\AppData\Roaming\npm-cache\_logs\2020-06-08T09_06_48_249Z-debug.log

Maybe is because I have Visual Studio 2017 and not 2019? I installed it via windows-build-tools

@marc2332 can you check this file is there? c:\users\mespi\appdata\roaming\.graviton2\plugins\remote\node_modules\sodium-native\libsodium\src\libsodium\sodium\version.h

Can you also check which version of libsodium it is installing?

I also think electron-builder is skipping the preinstall and postinstall scripts in your case. That's why you don't have the version.h file and hence it can't compile

@emilbayes The version.c file exists:

imagen

The installed version of sodium-native is 3.1.1 (image from it's package.json):

imagen

version.c is not the file it is looking for. version.h is what it is missing. That file is made as part of preinstall

Oh! I missread the the h. You are right it's missing. I see not "preinstall" script, you mean "prebuild"?
imagen

@marc2332 Sorry, it runs as part of install:

"install": "node-gyp-build \"node preinstall.js\" \"node postinstall.js\"",

Okay, I first ran a nmp install in sodium-native to be sure and then the npm run install:
imagen
It only took 1.5s and there is no version.h

It's because when you run it like that it finds the prebuild and skips installation. This will not help with your electron issue, as running it like that will pick up your node version and not your electron version. The issue here is with electron-build