Closed sindresorhus closed 6 years ago
What would I need to do, to provide a static binary for Linux or Windows? Would I be able to pull this off without any knowledge about building static binaries? :D
No idea. That's why it's still an open issue and "help wanted".
This is tricky as every linux distribution seems to store the libs at different locations:
For example in gentoo it is /usr/lib/libng16.a
on ubuntu 16.04 it is /usr/lib/x86_64-linux-gnu/libpng16.a
. And not sure if you want to keep a list of files for each distro?
In case you want to create the new static binary in this repository with ubuntu 16.04 this would be the diff:
diff --git a/lib/install.js b/lib/install.js
index ce9fb6d..925c1fe 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -15,6 +15,8 @@ bin.run(['-version'], err => {
let cfgExtras = '';
if (process.platform === 'darwin') {
cfgExtras = 'libpng_LIBS=\'/usr/local/lib/libpng16.a -lz\' --enable-static';
+ } else if (process.platform === 'linux') {
+ cfgExtras = 'libpng_LIBS=\'/usr/lib/x86_64-linux-gnu/libpng16.a /usr/lib/x86_64-linux-gnu/libz.a\' --enable-static';
}
const cfg = [
@danez on debian 8, i cannot locate libpng16
, only libpng12
as for the location of libpng, we can use find /usr -name libpng*.a
to find out and pass it over to configure command?
I guess libpng12
is okay as the configure script of mozjpeg explicitly checks for it.
https://github.com/mozilla/mozjpeg/blob/master/configure.ac#L109..L112
@danez can we use CI to build static library and upload them to github release? because asking user to install autoconf, make and other stuff is a lot. that should be a last resort only.
or maybe use prebuildify-ci
to build and download them and put them to vendor like currently?
By default this package will try to download and use one of the precompiled binaries anyway I think, the compiling is only a fallback.
this package will try to download and use one of the precompiled binaries anyway
I dont think it does.
It only checks if the binary is good (running -version
) and compile if it fails.
one question: if we static link it with libpng12
, will it work on system without libpng12
? will it work with libpng16
?
Has checking for the cjpeg
binary been considered?
And if not, then downloading the various tarballs (automake
, autoconf
, nasm
, et. al) from locked version sources to compile dependencies without sudo
in order to build cjpeg
locally, and then performing cleanup such that only the cjpeg
binary remains?
Depending on the Linux platform and available perl
, it might also need to be compiled from source which could add significant time to the build - but most machines should at least have perl5 w/ standard libraries available.
An easier route being that the user should (if they have sudo
access) run the following?
Red Hat/Fedora/CentOS/Amazon Linux
yum install autoconf automake libtool nasm
Ubuntu
sudo apt-get install autoconf libtool nasm
And in regards to libpng, why not do the same, compile from source locally such that one is not trying to find a lib that may or may not exist?
You can even just download the binary pre-compiled. http://rpm.pbone.net/index.php3/stat/3/srodzaj/2/search/libpng-1.6.3
I've done so for macOS (https://github.com/imagemin/mozjpeg-bin/commit/3d422cb6b14fc9d3e19cdee211dac9cd5e5e4e05), but would be nice to have a static binary for Linux and Windows too, if possible.
See: https://github.com/mozilla/mozjpeg/issues/245