ahgamut / superconfigure

wrap autotools configure scripts to build with Cosmopolitan Libc
The Unlicense
177 stars 24 forks source link

Image libraries #29

Closed croqaz closed 5 months ago

croqaz commented 5 months ago

I am adding a bunch of image libraries & freetype. They could be grouped in a new folder, perhaps called image/, for now they are in lib/.

croqaz commented 5 months ago

They don't build yet. When I try to build lib PNG, I get this weird error:

checking how to hardcode library paths into programs... unsupported
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking if awk (mawk) works... yes
checking if we need to force back C standard to C89... no
checking whether struct tm is in sys/time.h or time.h... time.h
checking for C/C++ restrict keyword... __restrict__
checking for pow... yes
checking for clock_gettime... yes
checking for zlibVersion in -lz... no
checking for z_zlibVersion in -lz... no
configure: error: zlib not installed
make: *** [config/common.mk:91: o/lib/libpng/configured.x86_64] Error 1

zlib should be available in Cosmopolitan right? I even added cosmo-repo/compress as a dependency.

ahgamut commented 5 months ago

For using cosmo's zlib you use cosmo-repo/base

croqaz commented 5 months ago

I tried:

$(eval $(call SPECIFY_DEPS,lib/libpng,cosmo-repo/base))

and even:

$(eval $(call SPECIFY_DEPS,lib/libpng,cosmo-repo/base,cosmo-repo/compress))

But the error is exactly the same. So weird.

croqaz commented 5 months ago

If I run this (inside the downloaded libpng folder)

root@DevBox ~/Dev/Superconfig/o/lib/libpng/libpng-1.6.43 pillow* ❯ ./configure --enable-static --disable-shared --disable-tests --disable-tools --without-pic --sysconfdir=/zip/etc --datarootdir=/zip/usr/share CFLAGS="-Os"

...
checking for pow in -lm... yes
checking for clock_gettime... yes
checking for zlibVersion in -lz... yes
checking for feenableexcept in -lm... yes
checking for feenableexcept... yes
...

everything works, and I can run make and it compiles. These are the files at the end:

root@DevBox ~/Dev/Superconfig/o/lib/libpng/libpng-1.6.43 pillow* 6s ❯ ls .libs/
libpng16.a  libpng16.la  libpng16.lai

But I suppose it's finding the global zlib library, not from Cosmopolitan?

ahgamut commented 5 months ago

check the o/lib/libpng/build/x86_64/config.log for libpng, and let me know what the error is? My guess is, it's most likely a header issue, the configure script is looking for something specific.

croqaz commented 5 months ago

I really don't know what to look for. This is the full output of that file: https://gist.github.com/croqaz/7b8da2b2311e1946b932d93de8874224

I'll have to compare it with a non-superconfigure run, maybe I can find out something weird.

ahgamut commented 5 months ago

https://gist.github.com/croqaz/7b8da2b2311e1946b932d93de8874224#file-libpng-config-log-L389-L427

I figured out the issue, it's because we namespaced zlib functions within cosmo to avoid clashes -- if you nm -gC cosmos/x86_64/lib/libz.a, you'll see it has _Cz_zlibVersion, which is what the configure script is looking for as zlibVersion.

There are multiple fixes for this: the simplest (although not particularly elegant) fix we can try right now is patch the ./configure of libpng, which is what I've done in the most recent commit https://github.com/ahgamut/superconfigure/commit/24a4191aac7d20a88b81bb38839fef11b353458e

A better fix IMO would be to avoid the namespacing in the first place, but I'd have to test all the builds and check with @jart if it is actually necessary.

croqaz commented 5 months ago

Thank you very much @ahgamut! I would have never figured it out myself!

ahgamut commented 5 months ago

I remember seeing something like this when building gcc/llvm (because I had to change how zlib interacts with cosmo), so it was easier to guess where the error could be.

If other libraries show a similar error with zlib at the configure stage, we know what to do now :slightly_smiling_face:

croqaz commented 5 months ago

I would like to get giflib in here before I finish the PR. ( I tried to add libavif but there are so many dependencies that I would need a new PR just for that )

I have some issues with it, it's different than the other libraries that I have seen in this repo. They don't use any fancy build system, they have this big Makefile, it's beautiful! But I don't know what's the best way to integrate it.

This is the part that we need, I think: https://sourceforge.net/p/giflib/code/ci/master/tree/Makefile#l112

libgif.a: $(OBJECTS) $(HEADERS)
    $(AR) rcs libgif.a $(OBJECTS)

It generates the libgif.a file in o/lib/giflib/build/x86_64 or whatever Arch is current. Then they want to run GNU coreutils install command to copy the final files to the install location. I don't think we have the "install" binary and I don't think we need it, we just need to copy that file in the cosmos lib... Not sure what's the cleanest way to do that.

I made this new file for the build: https://github.com/croqaz/superconfigure/blob/62fa806d60e76905697552fc1580e0e56743bc05/lib/giflib/build-wrapper

ahgamut commented 5 months ago

The build process for libgif seems a bit like lz4 or berry, where the only configuration changes need to be at the top of the Makefile.

Either option: you can write a separate config-wrapper or install-wrapper that calls the library correctly, or you can just write a minimal.diff that updates the PREFIX/INSTALL values in the Makefile.

croqaz commented 5 months ago

Managed to compile Python + Pillow several times. I can't make Gif work in Pillow for the life of me. Also I'm giving up Webp in Pillow. However that doesn't affect this PR, the libraries seem to be fine. I can see the .a files for all the libraries above in `cosmos/64/lib/` and all the .h files for all except giflib... not sure yet why. I think the PR is ready to merge. We are now closer to compile something like ImageMagick or Gimp or Krita in the future.

croqaz commented 5 months ago

OH this is the Python + Pillow fat binary: https://crlf.link/cosmos/pillow.com

croqaz commented 5 months ago

@ahgamut would you accept a PR for Python + Pillow in this repo? My current implementation is not complete, I would like to get gif, webp and imagingmath working, but it's some of work and I need a tiny bit of help with the compilation errors.

ahgamut commented 5 months ago

I think Python+Pillow can be a separate PR (perhaps we can add it to pypack1, or a separate target called pypack3). I'll merge this PR if all the image libraries are building.

ahgamut commented 5 months ago

does make install not work for giflib?

croqaz commented 5 months ago

I think Python+Pillow can be a separate PR (perhaps we can add it to pypack1, or a separate target called pypack3). I'll merge this PR if all the image libraries are building.

OH absolutely it should be another PR. The question was if you would accept it. I understand that YES.

does make install not work for giflib?

https://sourceforge.net/p/giflib/code/ci/master/tree/Makefile#l140 -- Install will try to build everything including docs, all binaries and so on. There's also a library called libutil.a that's hard to trace where it comes from once we add it to COSMOS/lib so I wouldn't build it. I just copied the lib file and the headers instead. Not sure if it's a good idea.

ahgamut commented 5 months ago

does make install add any .pc files? those tend to be used by pkg-config when building other things that might search for giflib.

croqaz commented 5 months ago

does make install add any .pc files? those tend to be used by pkg-config when building other things that might search for giflib.

This is the output of make install (run without Cosmopolitan):

make install
make -C doc
make[1]: Entering directory '/root/Dev/Superconfig/o/lib/giflib-5.2.2/doc'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/root/Dev/Superconfig/o/lib/giflib-5.2.2/doc'
install -d "/usr/local/bin"
install gif2rgb gifbuild giffix giftext giftool gifclrmp "/usr/local/bin"
install -d "/usr/local/include"
install -m 644 gif_lib.h "/usr/local/include"
install -d "/usr/local/lib"
install -m 644 libgif.a "/usr/local/lib/libgif.a"
install -m 755 libgif.so "/usr/local/lib/libgif.so.7.2.0"
ln -sf libgif.so.7.2.0 "/usr/local/lib/libgif.so.7"
ln -sf libgif.so.7 "/usr/local/lib/libgif.so"
install -d "/usr/local/share/man/man1"
install -m 644 doc/gif2rgb.xml doc/gifbuild.xml doc/gifclrmp.xml doc/giffix.xml doc/giflib.xml doc/giftext.xml doc/giftool.xml "/usr/local/share/man/man1"

It doesn't generate any .pc files anywhere.

ahgamut commented 5 months ago

@croqaz now that https://github.com/jart/cosmopolitan/pull/1142 has been merged, can you confirm that all the libraries in this PR build without error?

croqaz commented 5 months ago

Merged latest superconfigure, cloned latest cosmopolitan, I can confirm that all the libraries here are still compiling.

ahgamut commented 5 months ago

Thank you!

croqaz commented 5 months ago

I wish we had a small test suite, so we could check that something actually builds. A green checkmark for our peace of mind. But maybe it's not super needed for this repo, it would require a ton of building, a lot of CPU.