Skip to content
Closed
35 changes: 16 additions & 19 deletions tools/ports/freetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,47 @@

import os

TAG = 'version_1'
HASH = '0d0b1280ba0501ad0a23cf1daa1f86821c722218b59432734d3087a89acd22aabd5c3e5e1269700dcd41e87073046e906060f167c032eb91a3ac8c5808a02783'
TAG = '2-12-1'
HASH = '3ef3e47752b7c3cd158c738d7e0194f1c9f97ac85c754b02be6ee0f7999c3c19050f713d1e975f5310a4689337463e7b54450ef62e02c3f09864f4c6b13740d9'


def needed(settings):
return settings.USE_FREETYPE


def get(ports, settings, shared):
ports.fetch_project('freetype', 'https://github.com/emscripten-ports/FreeType/archive/' + TAG + '.zip', 'FreeType-' + TAG, sha512hash=HASH)
ports.fetch_project('freetype', 'https://github.com/freetype/freetype/archive/refs/tags/VER-' + TAG + '.zip', 'FreeType-' + TAG, sha512hash=HASH)

def create(final):
source_path = os.path.join(ports.get_dir(), 'freetype', 'FreeType-' + TAG)
source_path = os.path.join(ports.get_dir(), 'freetype', 'freetype-VER-' + TAG)
ports.write_file(os.path.join(source_path, 'include/ftconfig.h'), ftconf_h)
ports.install_header_dir(os.path.join(source_path, 'include'),
target=os.path.join('freetype2'))

with open(os.path.join(source_path, 'include', 'freetype', 'config', 'ftoption.h'), 'a') as ftheader:
ftheader.write('#define FT_CONFIG_OPTION_SYSTEM_ZLIB')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you don't need these two lines since you added FT_CONFIG_OPTION_SYSTEM_ZLIB to the config below?

Copy link
Contributor Author

@HCLJason HCLJason Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those might be dead lines. I tried without the highlighted lines, and I got a bunch of duplicate symbol errors when linking.

I'm trying out a build without the config options in the zconf file now.

wasm-ld: error: duplicate symbol: get_crc_table
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libfreetype.a(ftgzip.c.o)
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a(crc32.c.o)

wasm-ld: error: duplicate symbol: crc32_z
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libfreetype.a(ftgzip.c.o)
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a(crc32.c.o)

wasm-ld: error: duplicate symbol: crc32_combine_op
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libfreetype.a(ftgzip.c.o)
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a(crc32.c.o)

wasm-ld: error: duplicate symbol: inflateResetKeep
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libfreetype.a(ftgzip.c.o)
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a(inflate.c.o)

wasm-ld: error: duplicate symbol: inflateInit_
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libfreetype.a(ftgzip.c.o)
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a(inflate.c.o)

wasm-ld: error: duplicate symbol: inflateSyncPoint
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libfreetype.a(ftgzip.c.o)
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a(inflate.c.o)

wasm-ld: error: duplicate symbol: inflateUndermine
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libfreetype.a(ftgzip.c.o)
>>> defined in /local/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libz.a(inflate.c.o)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the lines from ftconf.h and leaving this line works.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the difference between ftconf.h and ftoption.h? It seems unfortunate to have to patch a shipping header like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ftconf.h looks like a dead link. ftoption.h is referenced a lot, but there's nothing that uses ftconf.h. I'm trying out a build without ftconf.h to see if that breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the ftconfig.h write and file and it built cleanly, so we should be able to remove that entirely.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of stuff in that existing config file. How do we know we are not changing the configuration by removing it? Does freetype no longer use ftconfig.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double-checked for ftconfig.h and that's actually used in the build, so I reverted that.

The build failure is freetype depending on zlib happening first. How do I denote a dependency?

I tried using the dependency logic referenced in tools/system_libs by adding it to freetype.py, but it didn't seem to work. I see that there's tools/deps_info.py, but that doesn't have any port->port dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add deps = ['zlib'] to this file I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change made.


# build
srcs = ['src/autofit/autofit.c',
'src/base/ftadvanc.c',
'src/base/ftbase.c',
'src/base/ftbbox.c',
'src/base/ftbdf.c',
'src/base/ftbitmap.c',
'src/base/ftcalc.c',
'src/base/ftcid.c',
'src/base/ftdbgmem.c',
'src/base/ftdebug.c',
'src/base/ftfntfmt.c',
'src/base/ftfstype.c',
'src/base/ftgasp.c',
'src/base/ftgloadr.c',
'src/base/ftglyph.c',
'src/base/ftgxval.c',
'src/base/ftinit.c',
'src/base/ftlcdfil.c',
'src/base/ftmm.c',
'src/base/ftobjs.c',
'src/base/ftotval.c',
'src/base/ftoutln.c',
'src/base/ftpatent.c',
'src/base/ftpfr.c',
'src/base/ftrfork.c',
'src/base/ftsnames.c',
'src/base/ftstream.c',
'src/base/ftstroke.c',
'src/base/ftsynth.c',
'src/base/ftsystem.c',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I use builds/unix/ftsystem.c, the compile is missing the fcntl.h header. It looks like we'll need to pull the #undef HAVE_FCNTL_H from the config file.

/local/emsdk/upstream/emscripten/cache/ports/freetype/freetype-VER-2-12-1/builds/unix/ftsystem.c:258:12: error: call to undeclared function 'open'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    file = open( filepathname, O_RDONLY );
           ^
/local/emsdk/upstream/emscripten/cache/ports/freetype/freetype-VER-2-12-1/builds/unix/ftsystem.c:258:32: error: use of undeclared identifier 'O_RDONLY'
    file = open( filepathname, O_RDONLY );
                               ^
/local/emsdk/upstream/emscripten/cache/ports/freetype/freetype-VER-2-12-1/builds/unix/ftsystem.c:341:22: error: call to undeclared function 'read'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        read_count = read( file,
                     ^
/local/emsdk/upstream/emscripten/cache/ports/freetype/freetype-VER-2-12-1/builds/unix/ftsystem.c:341:22: note: did you mean 'fread'?
/local/emsdk/upstream/emscripten/cache/sysroot/include/stdio.h:106:8: note: 'fread' declared here
size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
       ^
/local/emsdk/upstream/emscripten/cache/ports/freetype/freetype-VER-2-12-1/builds/unix/ftsystem.c:362:5: error: call to undeclared function 'close'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    close( file );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some testing. All 3 settings for HAVE_FCNTL_H had build failures with builds/unix/ftsystem.c.

Copy link
Contributor

@ericoporto ericoporto Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check HAVE_UNISTD_H too? It was the only other thing of notice reverse engineering the cmake files...

The methods from the error are here: https://github.com/emscripten-core/emscripten/blob/e05e72d9c49fe15578e73934ce525a894d1b712a/system/lib/libc/musl/include/unistd.h

Copy link
Contributor Author

@HCLJason HCLJason Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried #define HAVE_UNISTD_H and HAVE_STDINT_H in the ftconfig.h, and it doesn't work with any of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be working if I put them in ftoption.h, however.

Copy link
Contributor

@ericoporto ericoporto Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revising CMake, the full ftconfig.h file should be:

#ifndef FTCONFIG_H_
#define FTCONFIG_H_

#include <ft2build.h>
#include FT_CONFIG_OPTIONS_H
#include FT_CONFIG_STANDARD_LIBRARY_H

#define HAVE_UNISTD_H 1
#define HAVE_FCNTL_H 1

#include <freetype/config/integer-types.h>
#include <freetype/config/public-macros.h>
#include <freetype/config/mac-support.h>

#endif /* FTCONFIG_H_ */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where the ftconfig.h file in the build script comes from. I looked at the files from 2.6.1 and didn't get anywhere. It doesn't look like the other header files were inlined.

I tried this, and HAVE_UNISTD_H and HAVE_FCNTL_H don't seem to work from ftconfig.h. I'm going to put them back into ftoption.h and see what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving them in ftoption.h seems to work.

'src/base/fttrigon.c',
'src/base/ftsynth.c',
'src/base/fttype1.c',
'src/base/ftutil.c',
'src/base/ftwinfnt.c',
'src/bdf/bdf.c',
'src/bzip2/ftbzip2.c',
Expand All @@ -67,10 +58,12 @@ def create(final):
'src/pfr/pfr.c',
'src/psaux/psaux.c',
'src/pshinter/pshinter.c',
'src/psnames/psmodule.c',
'src/psnames/psnames.c',
'src/raster/raster.c',
'src/sdf/sdf.c',
'src/sfnt/sfnt.c',
'src/smooth/smooth.c',
'src/svg/ftsvg.c',
'src/truetype/truetype.c',
'src/type1/type1.c',
'src/type42/type42.c',
Expand Down Expand Up @@ -153,6 +146,10 @@ def show():

FT_BEGIN_HEADER

/* Requires system zlib */
#define FT_REQUIRE_ZLIB
#define FT_CONFIG_OPTION_SYSTEM_ZLIB


/*************************************************************************/
/* */
Expand Down