Is it possible to compile mediasoup binary statically linked?

Storyline- I was using mediasoup go which use medisoup bin to span new worker in my project everything was good so far. There was no problem running localy in ubuntu server then I deployed my go service which uses mediasoup binary to container and it didn’t worked because I was using alpine/scratch image.
After some debugging and getting helped from some devs from telegram I found that the libs which mediasoup bin requires is not available in alpine/scratch image. A developer Andrey Kartashov suggested that If it is possible then recompile with statically linked binary.

So I am wondering If it is possible then can we compile with statically linked binary so that I can also run on alpine/scratch?

I don’t know alot about this so I asked here.

It is definitely possible, in fact Rust version of the library already builds completely static library version of mediasoup, so if you target musl in Rust binary you can get completely static Rust binary with everything necessary inside of it and that works fine.

But for that you’ll need to tweak mediasoup/mediasoup-worker.gyp at v3 · versatica/mediasoup · GitHub (and on macOS you’ll have to link C++ standard library manually like it is done in Rust).

Since mediasoup go is not official it shouldn’t be a big deal to do some tweaks to the build instructions.

As a simpler approach you should still be able to install some dependencies in Alpine image and get things running, in most realistic cases a few MBs of image size have no impact on anything (practically speaking).

In most cases tough Alpine is not saving any space at all and you would be better off starting with build-deps that will likely be shared with some of the images you use anyway, thus not contributing any extra space. But that of course if the only concern was space, not some other aspects.

Thanks. Right now I don’t know what to change but will figure it out. I am not a c++ guy but still I hope I can find some help from internet.

I don’t understand since it is already in mediasoup official repository then what do I need to change?

Then why don’t just publish binary on github? That will be more easy and there can people have different binaries for their requirements.

Which means more work for us (mediasoup developers), since we’ll have to build and publish binaries for all platforms.

Rust version doesn’t build a executable, it builds static library, so that is where the difference is. You should be able to build the library the same way and provide a tiny bit of C/C++ to make static binary out of it.

The reason it doesn’t work on image built from scratch is dependency on dynamically loaded system libraries:

nazar-pc@nazar-pc:/w/g/mediasoup> ldd worker/out/Release/mediasoup-worker
	linux-vdso.so.1 (0x00007fff8c9e5000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fce549f0000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fce5480e000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fce546bf000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fce546a4000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fce54682000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fce54498000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fce551ba000)

BTW, did you try to build it under Alpine image and then move to scratch/alpine as opposed to building under Ubuntu/Debian and moving to another linux distro?

No. I should try this. I will let you know how it goes.