blaind/ttf2mesh-rs

Windows build broken

Opened this issue · 1 comments

This issue is for building the project on Windows. Currently, the build fails on Windows.

Steps to reproduce:

  1. Create a new project with cargo new ttf2mesh-test
  2. Run cargo add ttf2mesh
  3. Run cargo build

The following is the output of the build:

   Compiling ttf2mesh-sys v0.1.2
The following warnings were emitted during compilation:

warning: ttf2mesh/ttf2mesh.c:1672:50: error: 'PATH_MAX' undeclared here (not in a function)
warning:  1672 | static void replace_tilda_to_home_path(char path[PATH_MAX])
warning:       |                                                  ^~~~~~~~
warning: ttf2mesh/ttf2mesh.c: In function 'replace_tilda_to_home_path':
warning: ttf2mesh/ttf2mesh.c:1680:23: error: 'PATH_MAX' undeclared (first use in this function)
warning:  1680 |     if (hlen + plen > PATH_MAX) return;
warning:       |                       ^~~~~~~~
warning: ttf2mesh/ttf2mesh.c:1680:23: note: each undeclared identifier is reported only once for each function it appears in
warning: ttf2mesh/ttf2mesh.c:1672:45: warning: unused parameter 'path' [-Wunused-parameter]
warning:  1672 | static void replace_tilda_to_home_path(char path[PATH_MAX])
warning:       |                                        ~~~~~^~~~~~~~~~~~~~
warning: ttf2mesh/ttf2mesh.c: In function 'make_full_path':
warning: ttf2mesh/ttf2mesh.c:1695:36: error: type of formal parameter 1 is incomplete
warning:  1695 |         replace_tilda_to_home_path(fullpath);
warning:       |                                    ^~~~~~~~
warning: ttf2mesh/ttf2mesh.c:1699:31: error: 'PATH_SEP' undeclared (first use in this function)
warning:  1699 |     if (fullpath[flen - 1] != PATH_SEP)
warning:       |                               ^~~~~~~~
warning: ttf2mesh/ttf2mesh.c:1701:31: error: 'PATH_MAX' undeclared (first use in this function)
warning:  1701 |         if (flen + dlen + 2 > PATH_MAX) return false;
warning:       |                               ^~~~~~~~
warning: ttf2mesh/ttf2mesh.c: In function 'ttf_list_fonts':
warning: ttf2mesh/ttf2mesh.c:1876:19: error: 'PATH_MAX' undeclared (first use in this function)
warning:  1876 |     char fullpath[PATH_MAX];
warning:       |                   ^~~~~~~~
warning: ttf2mesh/ttf2mesh.c:1888:15: warning: implicit declaration of function 'load_fonts_from_dir' [-Wimplicit-function-declaration]
warning:  1888 |         res = load_fonts_from_dir(res, &count, &cap, directories[i], fullpath, 5, mask);
warning:       |               ^~~~~~~~~~~~~~~~~~~
warning: ttf2mesh/ttf2mesh.c:1876:10: warning: unused variable 'fullpath' [-Wunused-variable]
warning:  1876 |     char fullpath[PATH_MAX];
warning:       |          ^~~~~~~~
warning: ttf2mesh/ttf2mesh.c: In function 'ttf_list_system_fonts':
warning: ttf2mesh/ttf2mesh.c:1913:40: warning: ISO C forbids empty initializer braces [-Wpedantic]
warning:  1913 |     static const char *directories[] = {
warning:       |                                        ^
warning: ttf2mesh/ttf2mesh.c:1913:24: error: zero or negative size array 'directories'
warning:  1913 |     static const char *directories[] = {
warning:       |                        ^~~~~~~~~~~
warning: At top level:
warning: ttf2mesh/ttf2mesh.c:1740:13: warning: 'check_by_mask' defined but not used [-Wunused-function]
warning:  1740 | static bool check_by_mask(const char *file_name, const char *mask)
warning:       |             ^~~~~~~~~~~~~
warning: ttf2mesh/ttf2mesh.c:1711:13: warning: 'check_font_ext' defined but not used [-Wunused-function]
warning:  1711 | static bool check_font_ext(const char *file_name)
warning:       |             ^~~~~~~~~~~~~~
warning: ttf2mesh/ttf2mesh.c:1686:13: warning: 'make_full_path' defined but not used [-Wunused-function]
warning:  1686 | static bool make_full_path(char *fullpath, const char *part)
warning:       |             ^~~~~~~~~~~~~~

error: failed to run custom build command for `ttf2mesh-sys v0.1.2`

Caused by:
  process didn't exit successfully: `X:\src\ttf2mesh-test\target\debug\build\ttf2mesh-sys-8db95062a5c5a949\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-changed=wrapper.h
  cargo:rerun-if-changed=ttf2mesh/ttf2mesh.c
  cargo:rerun-if-changed=./ttf2mesh/ttf2mesh.h
  cargo:rerun-if-changed=X:/msys64/mingw64/lib/clang/15.0.5/include/stddef.h
  cargo:rerun-if-changed=X:/msys64/mingw64/lib/clang/15.0.5/include/__stddef_max_align_t.h
  cargo:rerun-if-changed=X:/msys64/mingw64/lib/clang/15.0.5/include/stdint.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/stdint.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/crtdefs.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/corecrt.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/_mingw.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/_mingw_mac.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/_mingw_secapi.h
  cargo:rerun-if-changed=X:/msys64/mingw64/lib/clang/15.0.5/include/vadefs.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/vadefs.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/_mingw.h
  cargo:rerun-if-changed=X:/msys64/mingw64/include/sdks/_mingw_ddk.h
  cargo:rerun-if-changed=X:/msys64/mingw64/lib/clang/15.0.5/include/stddef.h
  cargo:rerun-if-changed=X:/msys64/mingw64/lib/clang/15.0.5/include/stdbool.h
  cargo:rerun-if-changed=X:/msys64/mingw64/lib/clang/15.0.5/include/stdarg.h
  TARGET = Some("x86_64-pc-windows-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-pc-windows-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-pc-windows-gnu
  CC_x86_64-pc-windows-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_pc_windows_gnu
  CC_x86_64_pc_windows_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-gnu
  CFLAGS_x86_64-pc-windows-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_gnu
  CFLAGS_x86_64_pc_windows_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "gcc.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-gdwarf-2" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-pedantic" "-std=c99" "-D_POSIX_C_SOURCE=199309L" "-o" "X:\\src\\ttf2mesh-test\\target\\debug\\build\\ttf2mesh-sys-e6bba4b24ad3792b\\out\\ttf2mesh/ttf2mesh.o" "-c" "ttf2mesh/ttf2mesh.c"
  cargo:warning=ttf2mesh/ttf2mesh.c:1672:50: error: 'PATH_MAX' undeclared here (not in a function)
  cargo:warning= 1672 | static void replace_tilda_to_home_path(char path[PATH_MAX])
  cargo:warning=      |                                                  ^~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c: In function 'replace_tilda_to_home_path':
  cargo:warning=ttf2mesh/ttf2mesh.c:1680:23: error: 'PATH_MAX' undeclared (first use in this function)
  cargo:warning= 1680 |     if (hlen + plen > PATH_MAX) return;
  cargo:warning=      |                       ^~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c:1680:23: note: each undeclared identifier is reported only once for each function it appears in
  cargo:warning=ttf2mesh/ttf2mesh.c:1672:45: warning: unused parameter 'path' [-Wunused-parameter]
  cargo:warning= 1672 | static void replace_tilda_to_home_path(char path[PATH_MAX])
  cargo:warning=      |                                        ~~~~~^~~~~~~~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c: In function 'make_full_path':
  cargo:warning=ttf2mesh/ttf2mesh.c:1695:36: error: type of formal parameter 1 is incomplete
  cargo:warning= 1695 |         replace_tilda_to_home_path(fullpath);
  cargo:warning=      |                                    ^~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c:1699:31: error: 'PATH_SEP' undeclared (first use in this function)
  cargo:warning= 1699 |     if (fullpath[flen - 1] != PATH_SEP)
  cargo:warning=      |                               ^~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c:1701:31: error: 'PATH_MAX' undeclared (first use in this function)
  cargo:warning= 1701 |         if (flen + dlen + 2 > PATH_MAX) return false;
  cargo:warning=      |                               ^~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c: In function 'ttf_list_fonts':
  cargo:warning=ttf2mesh/ttf2mesh.c:1876:19: error: 'PATH_MAX' undeclared (first use in this function)
  cargo:warning= 1876 |     char fullpath[PATH_MAX];
  cargo:warning=      |                   ^~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c:1888:15: warning: implicit declaration of function 'load_fonts_from_dir' [-Wimplicit-function-declaration]
  cargo:warning= 1888 |         res = load_fonts_from_dir(res, &count, &cap, directories[i], fullpath, 5, mask);
  cargo:warning=      |               ^~~~~~~~~~~~~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c:1876:10: warning: unused variable 'fullpath' [-Wunused-variable]
  cargo:warning= 1876 |     char fullpath[PATH_MAX];
  cargo:warning=      |          ^~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c: In function 'ttf_list_system_fonts':
  cargo:warning=ttf2mesh/ttf2mesh.c:1913:40: warning: ISO C forbids empty initializer braces [-Wpedantic]
  cargo:warning= 1913 |     static const char *directories[] = {
  cargo:warning=      |                                        ^
  cargo:warning=ttf2mesh/ttf2mesh.c:1913:24: error: zero or negative size array 'directories'
  cargo:warning= 1913 |     static const char *directories[] = {
  cargo:warning=      |                        ^~~~~~~~~~~
  cargo:warning=At top level:
  cargo:warning=ttf2mesh/ttf2mesh.c:1740:13: warning: 'check_by_mask' defined but not used [-Wunused-function]
  cargo:warning= 1740 | static bool check_by_mask(const char *file_name, const char *mask)
  cargo:warning=      |             ^~~~~~~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c:1711:13: warning: 'check_font_ext' defined but not used [-Wunused-function]
  cargo:warning= 1711 | static bool check_font_ext(const char *file_name)
  cargo:warning=      |             ^~~~~~~~~~~~~~
  cargo:warning=ttf2mesh/ttf2mesh.c:1686:13: warning: 'make_full_path' defined but not used [-Wunused-function]
  cargo:warning= 1686 | static bool make_full_path(char *fullpath, const char *part)
  cargo:warning=      |             ^~~~~~~~~~~~~~
  exit code: 1

  --- stderr
  Failed to run rustfmt: cannot find binary path (non-fatal, continuing)


  error occurred: Command "gcc.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-gdwarf-2" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-pedantic" "-std=c99" "-D_POSIX_C_SOURCE=199309L" "-o" "X:\\src\\ttf2mesh-test\\target\\debug\\build\\ttf2mesh-sys-e6bba4b24ad3792b\\out\\ttf2mesh/ttf2mesh.o" "-c" "ttf2mesh/ttf2mesh.c" with args "gcc.exe" did not execute successfully (status code exit code: 1).

Aside from the obvious that the prerequisite apt-get install build-essential patch can't be run on Windows, it seems to append /ttf2mesh.o to the target path, which won't work on Windows.

Investigation should be done to see what Windows equivalents there are to build-essential and patch. It seems possible considering the base ttf2mesh project this is based on has a Windows build.

Hello! It look like preprocessing error. In Windows the macro code below must be processed. To do this, the compiler must have at least one of the __WINNT__, _WIN32, _WIN64 flags. I suggest checking for the presence of one of these flags.

#elif defined(__WINNT__) || defined(_WIN32) || defined(_WIN64)
#   define TTF_WINDOWS
#   define _CRT_SECURE_NO_WARNINGS
#   define PATH_SEP '\\'
#   define PATH_MAX MAX_PATH
#   include <windows.h>
#endif

Also wondering if there are any issues compiling other sources with installed mingw version?