Build from source for NodeJS on Windows 10, following the Readme.
If I take all the steps described, I can build from source.
When I install OpenSSL with vcpkg as suggested, I can't find the libeay32.lib and ssleay32.lib files. It seems OpenSSL 1.1 changed the names, the files I can see are libcrypto.lib and libssl.lib. This comment mentions the same.
Because of this, the build fails with
LINK : fatal error LNK1104: cannot open file 'C:\src\vcpkg\installed\x64-windows-static\lib\libeay32.lib' [C:\Users\tomas\Documents\realm-js\build\realm.vcxproj]
I think either Realm should update its internals to use OpenSSL 1.1 and/or the Readme should be updated so building from source works.
Install OpenSSL with vcpkg (vcpkg install openssl:x64-windows-static) and explore the folder .\packages\openssl-windows_x64-windows-static\lib.
Yes if you really need to do that, then you need to checkout your vcpkg repo to the point before OpenSSL was updated to 1.1. Then you will be able to follow the readme and build from source.
We will be releasing a new major version of Realm that will be using OpenSSL 1.1 in the near future.
Great to hear OpenSSL 1.1 will be part of a new major release!
Thanks for the suggestion, I can confirm everything works when I checkout the 2019.12 release of vcpkg, perhaps others might find this useful:
git clone https://github.com/Microsoft/vcpkg
git checkout tags/2019.12 -b 2019.12
continue with other commands from the readme...
As for why I was doing this in the first place: I was trying to use Realm together with the latest Electron (8.2.1) and, unfortunately, Realm only provides prebuilt binaries for 8.1.1.
I didn't have the problem with another native library, it seems because they use prebuild instead of node-pre-gyp. I know Electron is not officially supported but I saw an open issue with this subject so I'm just curious: is this on the roadmap for the near future, too?
You should not need to build from the source. You should just install the latest Realm in your project. Can you share the commands and the output you are using to do that, so we can better understand whats going on.
I'm using electron-builder in my project to build native dependencies. This is (shortened) output of yarn electron-builder install-app-deps in my project (which uses Realm 5.0.3 and Electron 8.2.0):
• electron-builder version=22.4.1
• rebuilding native dependency name=realm version=5.0.3
• execute command command='C:\Program Files\nodejs\node.exe' 'C:\Program Files (x86)\Yarn\bin\yarn.js' run install
workingDirectory=C:\Users\tomas\Documents\...\node_modules\realm
⨯ cannot execute cause=exit status 1
out=$ node-pre-gyp install --fallback-to-build -j 8
...
LINK : fatal error LNK1181: cannot open input file 'C:\src\vcpkg\installed\x64-windows-static\lib\libeay32.lib' [C:\Users\tomas\Documents\...\node_modules\realm\build\realm.vcxproj]
Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\tomas\Documents\...\node-gyp\bin\node-gyp.js build --fallback-to-build --jobs=8 --module=C:\Users\tomas\Documents\...\node_modules\realm\compiled\electron-v8.2_win32_x64\realm.node --module_name=realm --module_path=C:\Users\tomas\Documents\...node_modules\realm\compiled\electron-v8.2_win32_x64 --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v8.2' (1)
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
errorOut=warning package.json: License should be a valid SPDX license expression
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using [email protected]
node-pre-gyp info using [email protected] | win32 | x64
node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp http GET https://static.realm.io/node-pre-gyp/5.0.3/realm-v5.0.3-electron-v8.2-win32-x64.tar.gz
node-pre-gyp http 404 https://static.realm.io/node-pre-gyp/5.0.3/realm-v5.0.3-electron-v8.2-win32-x64.tar.gz
node-pre-gyp WARN Tried to download(404): https://static.realm.io/node-pre-gyp/5.0.3/realm-v5.0.3-electron-v8.2-win32-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (electron-v8.2 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp http 404 status code downloading tarball https://static.realm.io/node-pre-gyp/5.0.3/realm-v5.0.3-electron-v8.2-win32-x64.tar.gz
It can be seen node-gyp tries to download prebuilt binaries first but because they are not available for my Electron version, it fallbacks to building from source. And that's where it used to fail (before I checked out the 2019.12 version of vcpkg).
I think I need to build from source, if I want to be able to use the latest Electron version and not be dependent on the one which you provide prebuilt binaries for.
Thanks this will be helpful.
Technically since Realm JS v5 is now using N-API the binary is compatible with all future versions and should be working for your version of Electron as well. We still need to make the changes to ship a single binary for all versions. Then the local builds should be a thing of the past.
Thanks for reporting this. I will close the issue since it seems resolved for now.
Most helpful comment
Thanks this will be helpful.
Technically since Realm JS v5 is now using N-API the binary is compatible with all future versions and should be working for your version of Electron as well. We still need to make the changes to ship a single binary for all versions. Then the local builds should be a thing of the past.
Thanks for reporting this. I will close the issue since it seems resolved for now.