Closed marcus-pousette closed 5 months ago
Thanks for reporting. I don't really understand from the log, are you trying to compile it?
I am just installing this lib as transient dependency, and fail to do so in this environment
I have Ubuntu 20.04. I installed openssl 3.0.10
I can run the tests and can install as dependency without any problem.
openssl is statically linked so I don't think it is related to node-datachannel
binary.
What is the difference?
Could you please try with a new project? Here is my output
murat@murat-pc:~/js/temp/test$ npm init -y
Wrote to /home/murat/js/temp/test/package.json:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
murat@murat-pc:~/js/temp/test$ npm install node-datachannel
added 1 package, and audited 60 packages in 2s
7 packages are looking for funding
run `npm fund` for details
1 moderate severity vulnerability
To address all issues, run:
npm audit fix
Run `npm audit` for details.
murat@murat-pc:~/js/temp/test$ openssl version
OpenSSL 3.0.10 1 Aug 2023 (Library: OpenSSL 3.0.10 1 Aug 2023)
murat@murat-pc:~/js/temp/test$ node node_modules/node-datachannel/test/connectivity.js
2023-08-21 23:41:14.520 DEBUG [42850] [rtc::impl::Init::doInit@110] Global initialization
...
Peer1 Received Msg: Hello From Peer2
Peer2 Received Msg: Hello from Peer1
Ubuntu 20 works for me aswell, however with v 22 (I am using 22.04). It does not work longer work since it no longer ships OpenSSL 1.1 which this lib seems to require (not 3)
You mean it is working also for you with 20.04 + OpenSSL 3? I tested with OpenSSL 3.0.10
It succeds to install on Ubuntu 20 out of box without installing OpenSSL 3 because Ubuntu 20 already ships OpenSSL 1.1 (?).
It fails to install on Ubuntu 22 out of the box.
The problem is not related to Ubuntu 20 or 22.04 The problem is about the CPU architecture. You are using aarch64, I missed that. Only for this arch it is built as shared library with openssl 1.1
Please check note on README
Please note that; For Linux-arm64 platform we need OpenSSL to be installed locally.
I got an error while trying to link it statically https://github.com/murat-dogan/node-datachannel/blob/9e35a2040a569e61ba98231cd37e9232b95bf656/CMakeLists.txt#L24
Since I didn't have an aarch64 CPU I couldn't investigate more. Maybe you can.
I'm getting the same error on arm64 Debian bookworm:
$ uname -a
Linux c09371f5f1bd 5.10.76-linuxkit #1 SMP PREEMPT Mon Nov 8 11:22:26 UTC 2021 aarch64 GNU/Linux
$ cat /etc/debian_version
12.5
$ node -e "import('node-datachannel')"
node:internal/modules/cjs/loader:1319
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: libcrypto.so.1.1: cannot open shared object file: No such file or directory
at Module._extensions..node (node:internal/modules/cjs/loader:1319:18)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
at file:///node_modules/node-datachannel/lib/index.js:5:25
at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:428:15) {
code: 'ERR_DLOPEN_FAILED'
}
Node.js v20.5.1
Installing the libssl1.1 package from bullseye seems to be an effective workaround.
Hello,
As I replied here https://github.com/murat-dogan/node-datachannel/issues/178#issuecomment-1688914544; For arm64 openssl linked as a shared library. Unfortunately we need the right version to run.
Please Check here; https://github.com/murat-dogan/node-datachannel/blob/c8197e28b39fd81f55818c0301995414fa877ff9/CMakeLists.txt#L27
I dont have a arm64 PC so I can not test more. If anyone can find a solution for that I will be happy to merge it.
FYI i'm on an M1 mac and I just started seeing this error with https://github.com/ipfs/helia-http-gateway. the dockerfile is at https://github.com/ipfs/helia-http-gateway/blob/main/Dockerfile and the error i get is:
╰─ ✔ ❯ docker run -it -p $PORT:8080 -e DEBUG="helia-http-gateway*" -e USE_LIBP2P="false" helia-http-gateway:local
node:internal/modules/cjs/loader:1473
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: libcrypto.so.1.1: cannot open shared object file: No such file or directory
at Module._extensions..node (node:internal/modules/cjs/loader:1473:18)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at file:///app/node_modules/node-datachannel/lib/index.js:5:25
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12) {
code: 'ERR_DLOPEN_FAILED'
}
Node.js v20.11.1
I was able to change the "CMD" so that I could get into the container and investigate.
root@e79fb6c50eba:/app# fdfind ".*libcrypto\..*" /usr/lib
/usr/lib/aarch64-linux-gnu/libcrypto.a
/usr/lib/aarch64-linux-gnu/libcrypto.so
/usr/lib/aarch64-linux-gnu/libcrypto.so.3
/usr/lib/aarch64-linux-gnu/pkgconfig/libcrypto.pc
root@e79fb6c50eba:/app# node dist/src/index.js
node:internal/modules/cjs/loader:1473
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: libcrypto.so.1.1: cannot open shared object file: No such file or directory
at Module._extensions..node (node:internal/modules/cjs/loader:1473:18)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at file:///app/node_modules/node-datachannel/lib/index.js:5:25
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12) {
code: 'ERR_DLOPEN_FAILED'
}
Node.js v20.11.1
Now i'm working on a way to get libcrypto.so.1.1 installed on a newer version of debian
I dont have a arm64 PC so I can not test more. If anyone can find a solution for that I will be happy to merge it.
@murat-dogan i'd be interested in helping figure out a way to not fallback to openssl1.1 for M1 builds. Can you guide me a little bit on what the process would look like?
I cloned the repo and ran npm i && npm run build
and things build fine locally. Attached are build and test logs:
I modified CMakeLists.txt as follows:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f29c3b..ed2b086 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,10 +24,10 @@ endif()
# /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC
# ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): in function `sha1_block_armv8':
# (.text+0x1240): dangerous relocation: unsupported relocation
-if(NOT ${NODE_ARCH} STREQUAL "arm64")
- set(OPENSSL_USE_STATIC_LIBS TRUE)
- find_package(OpenSSL REQUIRED)
-endif()
+#if(NOT ${NODE_ARCH} STREQUAL "arm64")
+set(OPENSSL_USE_STATIC_LIBS TRUE)
+find_package(OpenSSL REQUIRED)
+#endif()
include(FetchContent)
and got the following build log output with rm -rf build prebuilds tmp && npm run build &> build-log-edited.txt
. it seems to build fine?
I'm happy to help if you have time to provide some guidance :)
@SgtPooki Thank you.
What I see from logs is you have OpenSSL v3 installed. So It will build also with it happily.
-- Found OpenSSL: /opt/homebrew/Cellar/openssl@3/3.2.1/lib/libcrypto.dylib (found suitable version "3.2.1", minimum required is "1.1.0")
-- Found PCAP: pcap
-- Found OpenSSL: /opt/homebrew/Cellar/openssl@3/3.2.1/lib/libcrypto.dylib (found version "3.2.1")
But the problem is we are building it as dynamically linked against OpenSSL. From cmake file we need to modify these lines (as you did); https://github.com/murat-dogan/node-datachannel/blob/a07715d4a13c89e1a79b0bad54b2490beb999ce5/CMakeLists.txt#L27-L30
To be sure I created a new branch with required changes. So Just clone the branch and try to build it.
https://github.com/murat-dogan/node-datachannel/tree/arm64-static-openssl
This is github ci file I am using; https://github.com/murat-dogan/node-datachannel/blob/arm64-static-openssl/.github/workflows/build-mac-m1.yml
I tried to build it with actions, it also built somehow :)
Could you please check the result and actions? https://github.com/murat-dogan/node-datachannel/actions
Could you download the binary and test it? https://github.com/murat-dogan/node-datachannel/releases/tag/v0.5.6-dev
$> ldd node_datachannel.node
This command should also give the dynamic library list on Mac.
This is the result for linux. It must be something like that.
murat@murat-ThinkBook:~/js/node-datachannel/build/Release$ ldd node_datachannel.node
linux-vdso.so.1 (0x00007fffa1b15000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8756a00000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8757861000)
I think i may try to build in the docker container for helia-http-gateway since i can repro the failure state more easily with that. Thanks for the guidance. I will try later tonight or tomorrow morning
$> ldd node_datachannel.node
for both of the below, I first executed wget https://github.com/murat-dogan/node-datachannel/releases/download/v0.5.6-dev/node-datachannel-v0.5.6-dev-napi-v8-darwin-arm64.tar.gz
and then extracted it.
When I run ldd
inside the docker image, I get:
root@bcf0b3696f76:/app/tmp# ldd build/Release/node_datachannel.node
not a dynamic executable
macos doesn't have ldd
but I searched around and apparently otool -L
does similar?
╰─ ✘ 1 ❯ otool -L build/Release/node_datachannel.node
build/Release/node_datachannel.node:
@rpath/node_datachannel.node (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
Trying to install the package from the branch you provided results in the following error:
root@bcf0b3696f76:/app# npm i murat-dogan/node-datachannel#arm64-static-openssl
npm ERR! code 2
npm ERR! git dep preparation failed
npm ERR! command /usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/root/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! > node-datachannel@0.5.6-dev install
npm ERR! > prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)
npm ERR!
npm ERR!
npm ERR! up to date, audited 734 packages in 1s
npm ERR!
npm ERR! 83 packages are looking for funding
npm ERR! run `npm fund` for details
npm ERR!
npm ERR! 12 vulnerabilities (1 low, 6 moderate, 4 high, 1 critical)
npm ERR!
npm ERR! To address issues that do not require attention, run:
npm ERR! npm audit fix
npm ERR!
npm ERR! To address all issues (including breaking changes), run:
npm ERR! npm audit fix --force
npm ERR!
npm ERR! Run `npm audit` for details.
npm ERR!
npm ERR! > node-datachannel@0.5.6-dev _prebuild
npm ERR! > prebuild -r napi --backend cmake-js
npm ERR!
npm ERR! [
npm ERR! '/usr/local/bin/node',
npm ERR! '/root/.npm/_cacache/tmp/git-clone6KYpo7/node_modules/.bin/cmake-js',
npm ERR! 'rebuild',
npm ERR! '--arch=arm64',
npm ERR! '--CDnapi_build_version=8'
npm ERR! ]
npm ERR! Not searching for unused variables given on the command line.
npm ERR! -- The C compiler identification is GNU 12.2.0
npm ERR! -- The CXX compiler identification is GNU 12.2.0
npm ERR! -- Detecting C compiler ABI info
npm ERR! -- Detecting C compiler ABI info - done
npm ERR! -- Check for working C compiler: /usr/bin/cc - skipped
npm ERR! -- Detecting C compile features
npm ERR! -- Detecting C compile features - done
npm ERR! -- Detecting CXX compiler ABI info
npm ERR! -- Detecting CXX compiler ABI info - done
npm ERR! -- Check for working CXX compiler: /usr/bin/c++ - skipped
npm ERR! -- Detecting CXX compile features
npm ERR! -- Detecting CXX compile features - done
npm ERR! -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
npm ERR! -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
npm ERR! -- Found Threads: TRUE
npm ERR! -- Configuring incomplete, errors occurred!
npm ERR! See also "/root/.npm/_cacache/tmp/git-clone6KYpo7/build/CMakeFiles/CMakeOutput.log".
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm ERR! npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm ERR! npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm ERR! npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm ERR! prebuild-install warn install No prebuilt binaries found (target=8 runtime=napi arch=arm64 libc= platform=linux)
npm ERR! npm WARN config production Use `--omit=dev` instead.
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! prebuild info begin Prebuild version 12.0.0
npm ERR! prebuild info build Preparing to prebuild node-datachannel@0.5.6-dev for napi 8 on linux-arm64 using cmake-js
npm ERR! info TOOL Using Unix Makefiles generator.
npm ERR! info DIST Downloading distribution files to: /root/.cmake-js/node-arm64/v20.11.1
npm ERR! http DIST - https://nodejs.org/dist/v20.11.1/SHASUMS256.txt
npm ERR! http DIST - https://nodejs.org/dist/v20.11.1/node-v20.11.1-headers.tar.gz
npm ERR! info CMD CLEAN
npm ERR! info RUN [
npm ERR! info RUN 'cmake',
npm ERR! info RUN '-E',
npm ERR! info RUN 'remove_directory',
npm ERR! info RUN '/root/.npm/_cacache/tmp/git-clone6KYpo7/build'
npm ERR! info RUN ]
npm ERR! info CMD CONFIGURE
npm ERR! info RUN [
npm ERR! info RUN 'cmake',
npm ERR! info RUN '/root/.npm/_cacache/tmp/git-clone6KYpo7',
npm ERR! info RUN '--no-warn-unused-cli',
npm ERR! info RUN '-G',
npm ERR! info RUN 'Unix Makefiles',
npm ERR! info RUN '-DCMAKE_JS_VERSION=6.3.2',
npm ERR! info RUN '-DCMAKE_BUILD_TYPE=Release',
npm ERR! info RUN '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/root/.npm/_cacache/tmp/git-clone6KYpo7/build/Release',
npm ERR! info RUN '-DCMAKE_JS_INC=/root/.cmake-js/node-arm64/v20.11.1/include/node',
npm ERR! info RUN '-DCMAKE_JS_SRC=',
npm ERR! info RUN '-DNODE_RUNTIME=node',
npm ERR! info RUN '-DNODE_RUNTIMEVERSION=20.11.1',
npm ERR! info RUN '-DNODE_ARCH=arm64',
npm ERR! info RUN '-Dnapi_build_version=8'
npm ERR! info RUN ]
npm ERR! CMake Error at /usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
npm ERR! Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
npm ERR! system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)
npm ERR! Call Stack (most recent call first):
npm ERR! /usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
npm ERR! /usr/share/cmake-3.25/Modules/FindOpenSSL.cmake:613 (find_package_handle_standard_args)
npm ERR! CMakeLists.txt:24 (find_package)
npm ERR!
npm ERR!
npm ERR! ERR! OMG Process terminated: 1
npm ERR! prebuild ERR! build Error: Failed to build cmake with exit code 1
npm ERR! prebuild ERR! build at ChildProcess.<anonymous> (/root/.npm/_cacache/tmp/git-clone6KYpo7/node_modules/prebuild/cmakebuild.js:32:19)
npm ERR! prebuild ERR! build at ChildProcess.emit (node:events:518:28)
npm ERR! prebuild ERR! build at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! npm ERR! code 2
npm ERR! npm ERR! path /root/.npm/_cacache/tmp/git-clone6KYpo7
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-19T03_19_34_817Z-debug-0.log
npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-19T03_19_31_550Z-debug-0.log
so i ran apt-get install libssl-dev
and tried again. it stalled for a while (presumed it's building), but it didn't throw any errors. node node_modules/node-datachannel/test/connectivity.js
also succeeded.
I think it's fixed as long as libssl-dev
is installed?
running docker build . --platform linux/arm64 --tag helia-http-gateway:local-arm64
builds successfully with the following changes to my package.json:
diff --git a/package.json b/package.json
index 7b171e0..00a2756 100644
--- a/package.json
+++ b/package.json
@@ -124,5 +124,8 @@
"patch-package": "^8.0.0",
"typescript": "5.x",
"wait-on": "^7.1.0"
+ },
+ "overrides": {
+ "node-datachannel": "github:murat-dogan/node-datachannel#arm64-static-openssl"
}
}
and it runs successfully with docker run -it -p 8080:8080 -e DEBUG="helia-http-gateway*" helia-http-gateway:local-arm64
I pushed these changes up to https://github.com/ipfs/helia-http-gateway/tree/test-node-datachannel if you need it for any reason.
Note that this is on a debian based box.. I can test on ubuntu 22 LTS as well if desired.
it's working in Ubuntu22 as well. Seems like things work fine? Let me know if you need anything else
Could you please check the result and actions? murat-dogan/node-datachannel/actions
You can probably remove the following
and replace with openssl3.0 install? but this may break users who currently depend on openssl1.0 and don't have openssl3.0 installed? (i.e. BREAKING_CHANGE
)
You could build a basic docker image that looks similar to the one I tested ubuntu22 with(see below) and run in your CI with something like: https://github.com/ipfs/helia-http-gateway/blob/da4c8609e143880e367c5483b200de1c1adfad5e/.github/workflows/docker.yml#L40-L49
To build it manually: docker build . --platform linux/arm64 --tag node-datachannel:test -f minimal.Dockerfile
To run it: docker run -it node-datachannel:test
# minimal.Dockerfile
FROM --platform=$BUILDPLATFORM ubuntu:22.04 as builder
RUN apt update
RUN apt install -y build-essential
RUN apt install -y cmake libssl-dev
RUN apt install -y wget curl
ENV NODE_MAJOR 20
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash -
RUN apt-get install -y nodejs
WORKDIR /app
RUN apt install -y git
ENV PKG_JSON '{ }'
RUN echo $PKG_JSON > package.json
# node-datachannel@0.5.5 fails on npm install with Error: libcrypto.so.1.1: cannot open shared object file: No such file or directory
# RUN npm i --save node-datachannel@0.5.5
RUN npm i --save github:murat-dogan/node-datachannel#arm64-static-openssl
CMD [ "node", "node_modules/node-datachannel/test/connectivity.js" ]
We have 2 different situations/problems here. Let's divide this into 2 issues to not cause confusion.
Mac M1 OpenSSL static build - #229
Linux arm64 OpenSSL static build - #230
Could you please follow up there?
@marcus-pousette Could you please try the new binary? https://github.com/murat-dogan/node-datachannel/releases/download/v0.5.6-dev/node-datachannel-v0.5.6-dev-napi-v8-linux-arm64.tar.gz
Ubuntu 22.04.2 LTS (GNU/Linux 5.19.0-1025-aws aarch64) Node v19.9.0
But when I run
yields
Why do I need openssl-1.1.1 ?