WonderInventions / node-webrtc

node-webrtc is a Node.js Native Addon that provides bindings to WebRTC M98
Other
109 stars 8 forks source link

CentOS 8 & 9 / Amazon Linux / Almalinux 8 / Debian 11 builds #4

Open o0101 opened 10 months ago

o0101 commented 10 months ago

This may be unrelated to your project @duvallj but I just found I needed to try to build on CentOS 9 because:

Trying path /home/pro/BrowserBox/node_modules/@roamhq/wrtc-linux-x64/wrtc.node
Error: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/pro/BrowserBox/node_modules/@roamhq/wrtc-linux-x64/wrtc.node)
    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 Object.<anonymous> (/home/pro/BrowserBox/node_modules/@roamhq/wrtc/lib/binding.js:18:22)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12) {
  code: 'ERR_DLOPEN_FAILED'
}
Uncaught:
Error: Could not find wrtc binary on any of the paths: ../build/wrtc.node,../build/Debug/wrtc.node,../build/Release/wrtc.node,./node_modules/@roamhq/wrtc-linux-x64,./node_modules/@roamhq/wrtc-linux-x64/wrtc.node
    at Object.<anonymous> (/home/pro/BrowserBox/node_modules/@roamhq/wrtc/lib/binding.js:28:9)

I added some error output to binding.js to catch the issue. If search for versions I see:

[pro@vultr BrowserBox]$ strings /usr/lib64/libstdc++.so.6 | grep 'GLIBCXX_3.4'
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29

So my latest CentOS 9 does not have the latest 3.4.30 libstdc++

I know it's not your problem, but do you know anything about this or how to fix it simply? (without a rebuild)?

o0101 commented 10 months ago

Just confirming that this works with a build following the instructions provided:

git clone https://github.com/WonderInventions/node-webrtc
cd node-webrtc
npm i
sudo dnf install -y ninja-build
npm run build
o0101 commented 10 months ago

If you need this CentOS build it's here: https://github.com/dosyago/node-webrtc/releases/tag/v1.0.0

😃😂

o0101 commented 10 months ago

Just a heads up, and a bit of additional detail, I found I needed to use a custom ./lib/binding.js because it seems that the path to try is not resolving correctly, when it involves relative paths (such as ../build/Release/wrtc.node).

So I add:

echo "Copying custom @roamhq/wrtc/lib/binding.js file..." >&2
cp ./config/roamhq-wrtc-lib-binding.js ./node_modules/@roamhq/wrtc/lib/binding.js

To my npm postinstall script set, and use

roamhq-wrtc-lib-binding.js:

'use strict';

const os = require('os');
const Path = require('path');
const paths_to_try = [
  '../build/wrtc.node',
  '../build/Debug/wrtc.node',
  '../build/Release/wrtc.node',
  `./node_modules/@roamhq/wrtc-${os.platform()}-${os.arch()}`,
  `./node_modules/@roamhq/wrtc-${os.platform()}-${os.arch()}/wrtc.node`,
];

let succeeded = false;
for (let path of paths_to_try) {
  path = Path.resolve(path);
  console.log('Trying path', path);
  try {
    module.exports = require(path);
    succeeded = true;
    break;
  } catch (error) {
    console.warn(error);
    ;
  }
}

if (!succeeded) {
  throw new Error(`Could not find wrtc binary on any of the paths: ${paths_to_try}`);
}

Hey @duvallj just wanted to add this! :)

duvallj commented 10 months ago

Interesting, I'm not sure why relative paths weren't working for you? Looks like you may have placed wrtc.node in node_modules/@roamhq/wrtc-linux-x64/, instead of node_modules/@roamhq/wrtc-linux-x64/build like the original script expected? Anyways, thanks for adding onto the issue for others trying to install on CentOS 9, good to know building from source still works well! I only intend to support the latest Debian at the moment.

o0101 commented 10 months ago

Hey @duvallj, I didn't alter the internal @roamhq directories, just the external ../build ones. I'm still on your original @roamhq/wrtc, so any changes within the internal wrtc.node directories aren't from me.

On CentOS, I source the custom wrtc.node from my GitHub releases into $HOME/build/Release, aligning with the wrtc.node path in my $HOME/Project. This discrepancy could be due to the way relative paths are resolved in require(relPath) versus path.resolve(relPath) in my version.

I suspect some paths in the paths_to_try array may not resolve correctly. Even after an npm i, a correct wrtc.node was seemingly invisible until I implemented path.resolve. It's worth a check on your end; it could be an existing issue predating my changes.

I understand Debian is sufficient for you, so I'll handle my own builds for other systems. I may document issues as a reference for others, but I'll avoid overloading your issue tracker—just tell me if that's not okay.

Regarding the paths_to_try issue, it could be a non-issue, but it caught my attention during experimentation. It might be something to verify for broader consistency.

Sorry for the info dump—you're likely swamped. Appreciate your time reading this!

o0101 commented 9 months ago

I just added a Debian 11 build over at: https://github.com/dosyago/node-webrtc/releases/tag/v1.0.0

full build script:

#!/bin/bash

sudo apt install ninja-build cmake build-essential python pkg-config clang++
git clone https://github.com/dosyago/node-webrtc.git
cd node-webrtc
npm i
npm run build
o0101 commented 9 months ago

I just added builds for CentOS 8 and Almalinux 8 over at: https://github.com/dosyago/node-webrtc/releases/tag/v1.0.0

Full build script:

#!/bin/bash

sudo dnf install cmake gcc gcc-c++ python39 pkgconf-pkg-config clang
pip3 install --user ninja
sudo ln -s $(which python3.9) /bin/python
git clone https://github.com/dosyago/node-webrtc
cd node-webrtc
npm i
npm run build

At: https://github.com/BrowserBox/BrowserBox/blob/boss/build-scripts/roamhq-wrtc/almalinux-8-build.sh

pr0g commented 4 months ago

Hi @o0101,

I believe I've run into the same problem trying to get wrtc to work on Amazon Linux using AWS Lambda.

I had the same issue reported as you that the wrtc binary could not be found:

"errorMessage": "Could not find wrtc binary on any of the paths: ../build-linux-x64/wrtc.node,../build-linux-x64/Debug/wrtc.node,../build-linux-x64/Release/wrtc.node,@roamhq/wrtc-linux-x64"

@roamhq/wrtc-linux-x64 definitely contains wrtc.node (path is src/node_modules/@roamhq/wrtc-linux-x64/wrtc.node). I borrowed your script (roamhq-wrtc-lib-binding.js) and confirmed that wrtc could then be found, but unfortunately I get another problem where I see:

/lib64/libc.so.6: version 'GLIBC_2.34' not found (required by /var/task/node_modules/@roamhq/wrtc-linux-x64/wrtc.node)

This is using Amazon Linux 2 (Node 18), I tried switching to Node 20 (Amazon Linux 2023, see Lambda runtimes) but then I get a slightly different error again which is:

/lib64/libstdc++.so.6: version 'GLIBCXX_3.4.30' not found (required by /var/task/node_modules/@roamhq/wrtc-linux-x64/wrtc.node)

I don't suppose you have any idea to workaround this issue? Would building wrtc.node from source be an option? If you have any ideas/thoughts I'd be very grateful to hear!

Thanks!

o0101 commented 4 months ago

Hello @pr0g,

Oh that doesn't sound good that you've encountered that! Yes, that can be a tricky and annoying issue to face.

Hmmm, let me see. I think what I did to get around this was indeed to build from source. Sounds like you have the right idea! If you try that you might find some of the 'build-related' scripts I've left in comments above may be helpful -- but I can't guaruntee their correctness! So if you use them it might be best to treat them as a guide! :)

Another thing that helps is if you fix your app to use a particular major release of Node. Say Node v20. The more recent node releases don't always have up to date wrtc builds available.

Hope that helps! Anyway, best of luck with it! Not sure if I'll be able to provide much other help aside from that as I'm kind of busy but wish you all the best with it!!! :)

pr0g commented 4 months ago

Hi @o0101, thanks very much for getting back to me about this, I'll take a look at the build related scripts you mentioned!

I did go down the route of trying to build from source, but unfortunately hit another stumbling block (see my comment here, it hasn't been a great day 😅). Is this something you encountered? I'm wondering if there's a workaround to build this repo in the environment I'm using (Amazon Linux 2023 and Node 20, though Node 18 should be fine too).

No worries if you don't get a chance to reply, I'll try and circle back to this in a bit. I'm essentially trying to upgrade us from an old version of Node WebRTC (see https://github.com/revu-design/node-webrtc) using Node 16 which is preventing us from performing other important upgrades.

Thanks again!

duvallj commented 4 months ago

I should probably use an older environment for building Linux binaries yeah... gosh darn GLIBC errors

Also, I'm still confused as to why AWS Lambda doesn't like the node_modules, but I've included a fix that hopefully works (just pushed), and will be in the next release (soon!)

o0101 commented 4 months ago

Hey @pr0g like I said I'm not doing more on this here. But if you want to do some consulting you can reach out to us as sales@dosyago.com we can try to help you figure it out that way! :)