Skip to content

Commit

Permalink
Add support for targeting ARM/ARM64
Browse files Browse the repository at this point in the history
- Update LLVM to 10.0.0.
- Update MinGW-w64 to the latest master version for the LLVM builds.
- Build Rust within MXE instead of using the Rust Docker image.
- Do not compile binaries with -ffast-math.
  • Loading branch information
kleisauke committed Apr 25, 2020
1 parent 3d23030 commit a5eb868
Show file tree
Hide file tree
Showing 40 changed files with 1,774 additions and 176 deletions.
15 changes: 15 additions & 0 deletions 8.9/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@ target="${2:-x86_64-w64-mingw32.shared.win32}"
# This ensures that it will not suddenly break a build.
# Note: Must be regularly updated.
revision="169c1da1e70307258cf763cd41f50a18071587c2"
initialize=false

if [ -f "$mxe_dir/Makefile" ]; then
echo "Skip cloning, MXE already exists at $mxe_dir"
cd $mxe_dir && git fetch
else
git clone https://github.com/mxe/mxe && cd $mxe_dir
initialize=true
fi

curr_revision=$(git rev-parse HEAD)

# Is our branch up-to-date?
if [ ! "$curr_revision" = "$revision" ]; then
git pull && git reset --hard $revision
initialize=true
fi

if [ "$initialize" = true ] ; then
# Patch MXE to support the ARM/ARM64 targets
git apply $work_dir/plugins/llvm-mingw/patches/mxe-fixes.patch
fi

# The 'plugins' variable controls which plugins are in use.
Expand Down Expand Up @@ -75,6 +83,13 @@ make meson-wrapper gendef vips-$deps \
MXE_PLUGIN_DIRS="$plugins" \
MXE_TARGETS=$target.$deps

# Build and bundle llvm-mingw tests
if [ "$LLVM" = "true" ]; then
make test-llvm-mingw \
MXE_PLUGIN_DIRS="$plugins" \
MXE_TARGETS=$target.$deps
fi

cd $work_dir

# Packaging
Expand Down
7 changes: 2 additions & 5 deletions 8.9/libde265.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ define $(PKG)_BUILD
(cd '$(SOURCE_DIR)' && $(PATCH) -p1 -u) < $(realpath $(dir $(lastword $(libde265_PATCHES))))/libde265-mingw-std-threads.patch)

cd '$(BUILD_DIR)' && $(TARGET)-cmake '$(SOURCE_DIR)' \
-DCMAKE_C_FLAGS="$(CFLAGS) -msse4.1" \
$(if $(findstring win32,$(TARGET)), \
-DCMAKE_CXX_FLAGS='$(CXXFLAGS) -msse4.1 -I$(PREFIX)/$(TARGET)/include/mingw-std-threads' \
$(else), \
-DCMAKE_CXX_FLAGS='$(CXXFLAGS) -msse4.1') \
-DDISABLE_SSE=OFF
-DCMAKE_CXX_FLAGS='$(CXXFLAGS) -I$(PREFIX)/$(TARGET)/include/mingw-std-threads') \
-DDISABLE_SIMD=OFF
$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)'
$(MAKE) -C '$(BUILD_DIR)' -j 1 install
endef
3 changes: 3 additions & 0 deletions 8.9/libexif.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ define $(PKG)_UPDATE
endef

define $(PKG)_BUILD
# configure script is ancient so regenerate
cd '$(SOURCE_DIR)' && autoreconf -fi

cd '$(BUILD_DIR)' && $(SOURCE_DIR)/configure \
$(MXE_CONFIGURE_OPTS)
$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' $(MXE_DISABLE_PROGRAMS)
Expand Down
92 changes: 64 additions & 28 deletions 8.9/overrides.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mingw-w64-headers_CONFIGURE_OPTS=--prefix='$(PREFIX)/$(TARGET)/mingw'
common_CONFIGURE_OPTS=--prefix='$(PREFIX)/$(TARGET)/mingw' \
--with-sysroot='$(PREFIX)/$(TARGET)/mingw' \
CPPFLAGS='-I$(PREFIX)/$(TARGET)/mingw/include' \
CFLAGS='-I$(PREFIX)/$(TARGET)/mingw/include' \
CXXFLAGS='-I$(PREFIX)/$(TARGET)/mingw/include' \
CFLAGS='-I$(PREFIX)/$(TARGET)/mingw/include -s -O3' \
CXXFLAGS='-I$(PREFIX)/$(TARGET)/mingw/include -s -O3' \
LDFLAGS='-L$(PREFIX)/$(TARGET)/mingw/lib' \
RCFLAGS='-I$(PREFIX)/$(TARGET)/mingw/include'

Expand Down Expand Up @@ -49,17 +49,31 @@ define gcc_BUILD_i686-w64-mingw32
endef

define llvm-mingw_BUILD_x86_64-w64-mingw32
$(subst # install the usual wrappers, ln -sf $(PREFIX)/$(TARGET)/mingw/bin/* $(PREFIX)/$(TARGET)/bin && \
ln -sf '$(PREFIX)/$(TARGET)/mingw/lib/'* '$(PREFIX)/$(TARGET)/lib' && \
ln -sf '$(PREFIX)/$(TARGET)/mingw/include/'* '$(PREFIX)/$(TARGET)/include', \
$(subst @mingw-crt-config-opts@,--disable-lib32 --enable-lib64 $(common_CONFIGURE_OPTS), $(llvm-mingw_BUILD_mingw-w64)))
$(subst @mingw-crt-config-opts@,--disable-lib32 --enable-lib64 $(common_CONFIGURE_OPTS),$(llvm-mingw_BUILD_mingw-w64))
ln -sf '$(PREFIX)/$(TARGET)/mingw/bin/'* '$(PREFIX)/$(TARGET)/bin'
ln -sf '$(PREFIX)/$(TARGET)/mingw/lib/'* '$(PREFIX)/$(TARGET)/lib'
ln -sf '$(PREFIX)/$(TARGET)/mingw/include/'* '$(PREFIX)/$(TARGET)/include'
endef

define llvm-mingw_BUILD_i686-w64-mingw32
$(subst # install the usual wrappers, ln -sf $(PREFIX)/$(TARGET)/mingw/bin/* $(PREFIX)/$(TARGET)/bin && \
ln -sf '$(PREFIX)/$(TARGET)/mingw/lib/'* '$(PREFIX)/$(TARGET)/lib' && \
ln -sf '$(PREFIX)/$(TARGET)/mingw/include/'* '$(PREFIX)/$(TARGET)/include', \
$(subst @mingw-crt-config-opts@,--enable-lib32 --disable-lib64 $(common_CONFIGURE_OPTS), $(llvm-mingw_BUILD_mingw-w64)))
$(subst @mingw-crt-config-opts@,--enable-lib32 --disable-lib64 $(common_CONFIGURE_OPTS),$(llvm-mingw_BUILD_mingw-w64))
ln -sf '$(PREFIX)/$(TARGET)/mingw/bin/'* '$(PREFIX)/$(TARGET)/bin'
ln -sf '$(PREFIX)/$(TARGET)/mingw/lib/'* '$(PREFIX)/$(TARGET)/lib'
ln -sf '$(PREFIX)/$(TARGET)/mingw/include/'* '$(PREFIX)/$(TARGET)/include'
endef

define llvm-mingw_BUILD_armv7-w64-mingw32
$(subst @mingw-crt-config-opts@,--disable-lib32 --disable-lib64 --enable-libarm32 $(common_CONFIGURE_OPTS),$(llvm-mingw_BUILD_mingw-w64))
ln -sf '$(PREFIX)/$(TARGET)/mingw/bin/'* '$(PREFIX)/$(TARGET)/bin'
ln -sf '$(PREFIX)/$(TARGET)/mingw/lib/'* '$(PREFIX)/$(TARGET)/lib'
ln -sf '$(PREFIX)/$(TARGET)/mingw/include/'* '$(PREFIX)/$(TARGET)/include'
endef

define llvm-mingw_BUILD_aarch64-w64-mingw32
$(subst @mingw-crt-config-opts@,--disable-lib32 --disable-lib64 --enable-libarm64 $(common_CONFIGURE_OPTS),$(llvm-mingw_BUILD_mingw-w64))
ln -sf '$(PREFIX)/$(TARGET)/mingw/bin/'* '$(PREFIX)/$(TARGET)/bin'
ln -sf '$(PREFIX)/$(TARGET)/mingw/lib/'* '$(PREFIX)/$(TARGET)/lib'
ln -sf '$(PREFIX)/$(TARGET)/mingw/include/'* '$(PREFIX)/$(TARGET)/include'
endef

## Update dependencies
Expand Down Expand Up @@ -262,7 +276,7 @@ zlib_PATCHES := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST))
# Added: mingw-std-threads, libjpeg-turbo, lcms
# librsvg:
# Removed: libcroco, libgsf
# Added: libxml2
# Added: libxml2, rust
# libwebp:
# Added: gettext
# Cairo:
Expand All @@ -286,14 +300,28 @@ openexr_DEPS := cc ilmbase zlib $(BUILD)~cmake
ilmbase_DEPS := cc $(BUILD)~cmake
pango_DEPS := $(pango_DEPS) fribidi
poppler_DEPS := cc mingw-std-threads cairo libjpeg-turbo freetype glib openjpeg lcms libpng tiff zlib
librsvg_DEPS := cc cairo gdk-pixbuf glib pango libxml2
librsvg_DEPS := $(filter-out libcroco libgsf ,$(librsvg_DEPS)) libxml2 rust
libwebp_DEPS := $(libwebp_DEPS) gettext
cairo_DEPS := cc fontconfig freetype-bootstrap glib libpng pixman
hdf5_DEPS := cc zlib $(BUILD)~cmake
x265_DEPS := cc $(BUILD)~nasm
hdf5_DEPS := $(filter-out pthreads ,$(hdf5_DEPS)) $(BUILD)~cmake
x265_DEPS := $(subst yasm,$(BUILD)~nasm,$(x265_DEPS))

## Override build scripts

# libasprintf isn't needed, so build with --disable-libasprintf
define gettext_BUILD
cd '$(SOURCE_DIR)' && autoreconf -fi
cd '$(BUILD_DIR)' && '$(SOURCE_DIR)/gettext-runtime/configure' \
$(MXE_CONFIGURE_OPTS) \
--enable-threads=win32 \
--without-libexpat-prefix \
--without-libxml2-prefix \
--disable-libasprintf \
CONFIG_SHELL=$(SHELL)
$(MAKE) -C '$(BUILD_DIR)/intl' -j '$(JOBS)'
$(MAKE) -C '$(BUILD_DIR)/intl' -j 1 install
endef

# disable version script on llvm-mingw
# make the raw api unavailable when building a statically linked binary
define libffi_BUILD
Expand All @@ -302,10 +330,15 @@ define libffi_BUILD
$(MXE_CONFIGURE_OPTS) \
--disable-multi-os-directory \
$(if $(BUILD_STATIC), --disable-raw-api) \
$(if $(findstring posix,$(TARGET)), --disable-symvers)
$(if $(IS_LLVM), --disable-symvers)

$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)'
$(MAKE) -C '$(BUILD_DIR)' -j 1 install

'$(TARGET)-gcc' \
-W -Wall -Werror -std=c99 -pedantic \
'$(TEST_FILE)' -o '$(PREFIX)/$(TARGET)/bin/test-libffi.exe' \
`'$(TARGET)-pkg-config' libffi --cflags --libs`
endef

# icu will pull in standard linux headers, which we don't want,
Expand Down Expand Up @@ -435,23 +468,14 @@ define lcms_BUILD
$(MAKE) -C '$(BUILD_DIR)' -j 1 install $(MXE_DISABLE_PROGRAMS)
endef

define imagemagick_REVISION
$(SED) -n 's/MAGICK_GIT_REVISION=\(.*\)/\1/p' $(SOURCE_DIR)/configure
endef

# disable largefile support, we rely on vips for that and ImageMagick's
# detection does not work when cross-compiling
# build with jpeg-turbo and without lzma
# disable POSIX threads with --without-threads, use Win32 threads instead
# exclude deprecated methods in MagickCore API
define imagemagick_BUILD
$(SED) -i "s|\(\[MAGICK_GIT_REVISION\],\).*\]|\1['$(shell $(imagemagick_REVISION))']|" $(SOURCE_DIR)/configure.ac

# avoid linking against -lgdi32, see: https://github.com/kleisauke/net-vips/issues/61
$(SED) -i 's,-lgdi32,,g' $(SOURCE_DIR)/configure.ac

# need to regenerate the configure script
cd '$(SOURCE_DIR)' && autoreconf -fi
$(SED) -i 's,-lgdi32,,g' $(SOURCE_DIR)/configure

cd '$(BUILD_DIR)' && $(SOURCE_DIR)/configure \
$(MXE_CONFIGURE_OPTS) \
Expand Down Expand Up @@ -514,13 +538,25 @@ endef

# compile with the Rust toolchain
define librsvg_BUILD
# We need to explicitly link against msvcrt-os after commit ae95d7c
# on the mingw-w64 repo. Otherwise the __ms_vsnprintf symbol is
# undefined during linking. The standard library of Rust appears
# to link against this symbol by default.
# Note: this can probably be removed when the standard library of
# Rust is build with the latest mingw-w64 version (> v7.0.0).
$(if $(IS_LLVM), \
$(SED) -i 's/^\(Libs:.*\)/\1 -lmsvcrt-os/' '$(SOURCE_DIR)/librsvg.pc.in')

cd '$(BUILD_DIR)' && $(SOURCE_DIR)/configure \
$(MXE_CONFIGURE_OPTS) \
--disable-pixbuf-loader \
--disable-gtk-doc \
--disable-introspection \
--disable-tools \
RUST_TARGET=$(firstword $(subst -, ,$(TARGET)))-pc-windows-gnu
RUST_TARGET='$(PROCESSOR)-pc-windows-gnu' \
CARGO='$(TARGET)-cargo' \
RUSTC='$(TARGET)-rustc' \
$(if $(IS_LLVM), LIBS='-lmsvcrt-os -lucrt')

$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)'
$(MAKE) -C '$(BUILD_DIR)' -j 1 $(INSTALL_STRIP_LIB)
Expand Down Expand Up @@ -685,7 +721,7 @@ define libxml2_BUILD
--without-debug \
--without-python \
--without-threads \
$(if $(findstring posix,$(TARGET)), --disable-ld-version-script)
$(if $(IS_LLVM), --disable-ld-version-script)
$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' $(MXE_DISABLE_CRUFT)
$(MAKE) -C '$(BUILD_DIR)' -j 1 install $(MXE_DISABLE_CRUFT)
ln -sf '$(PREFIX)/$(TARGET)/bin/xml2-config' '$(PREFIX)/bin/$(TARGET)-xml2-config'
Expand Down Expand Up @@ -827,7 +863,7 @@ define hdf5_BUILD
-DH5_LLONG_TO_LDOUBLE_CORRECT=ON \
-DH5_DISABLE_SOME_LDOUBLE_CONV=OFF \
-DH5_NO_ALIGNMENT_RESTRICTIONS=ON \
-DH5_HAVE_IOEO=$(if $(findstring posix,$(TARGET)),1,0) \
-DH5_HAVE_IOEO=$(if $(IS_LLVM),1,0) \
-DTEST_LFS_WORKS_RUN=0 \
-DHDF5_ENABLE_THREADSAFE=ON \
-DHDF5_USE_PREGEN=ON \
Expand Down
13 changes: 9 additions & 4 deletions 8.9/package-vipsdev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ build_os=`$mxe_dir/ext/config.guess`

if [ "$arch" = "i686" ]; then
arch="w32"
else
elif [ "$arch" = "x86_64" ]; then
arch="w64"
elif [ "$arch" = "armv7" ]; then
arch="arm32"
elif [ "$arch" = "aarch64" ]; then
arch="arm64"
fi

# Make sure that the repackaging dir is empty
Expand All @@ -42,7 +46,7 @@ if [ "$MOZJPEG" = "true" ]; then
zip_suffix+="-mozjpeg"
fi

if [ "$LLVM" = "true" ]; then
if [ "$LLVM" = "true" ] && [[ "$arch" != "arm"* ]]; then
zip_suffix+="-llvm"
fi

Expand Down Expand Up @@ -78,9 +82,10 @@ echo "Generating import files"
echo "Cleaning unnecessary files / directories"

# TODO Do we need to keep /share/doc and /share/gtk-doc?
rm -rf $repackage_dir/share/{aclocal,bash-completion,clang,cmake,config.site,doc,gdb,glib-2.0,gtk-2.0,gtk-doc,installed-tests,man,meson,opt-viewer,scan-build,scan-view,thumbnailers,xml}
rm -rf $repackage_dir/share/{aclocal,bash-completion,clang,cmake,config.site,doc,gdb,glib-2.0,gtk-2.0,gtk-doc,installed-tests,man,meson,opt-viewer,scan-build,scan-view,thumbnailers,xml,zsh}
rm -rf $repackage_dir/include/{cairo,clang-c,c++,llvm-c}
rm -rf $repackage_dir/lib/{*.so*,*cairo*,*gdk*,clang,ldscripts}
rm -rf $repackage_dir/lib/{*.so*,*cairo*,*gdk*,clang,ldscripts,rustlib}
rm -rf $repackage_dir/etc/bash_completion.d

find $repackage_dir/lib -name "*.la" -exec rm -f {} \;

Expand Down
26 changes: 23 additions & 3 deletions 8.9/patches/cairo-1-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Contains ad hoc patches for cross building.
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bryce Harrington <[email protected]>
Date: Sun, 3 Mar 2019 00:01:34 -0800
Subject: [PATCH 1/3] Revert "clip-boxes: Drop too-early return"
Subject: [PATCH 1/4] Revert "clip-boxes: Drop too-early return"

This reverts commit cb871c6c692af68d8e0bf9e26472af45435f8a2c.

Expand All @@ -30,7 +30,7 @@ index 1111111..2222222 100644
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Mon, 25 Nov 2019 15:30:00 +0100
Subject: [PATCH 2/3] Remove -D_FORTIFY_SOURCE=2 flag
Subject: [PATCH 2/4] Remove -D_FORTIFY_SOURCE=2 flag

See:
https://github.com/msys2/MINGW-packages/issues/5803
Expand All @@ -54,7 +54,7 @@ index 1111111..2222222 100644
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Wed, 12 Feb 2020 20:00:00 +0100
Subject: [PATCH 3/3] Always define _cairo_utf8_to_utf16 on Windows
Subject: [PATCH 3/4] Always define _cairo_utf8_to_utf16 on Windows

_cairo_utf8_to_utf16 is used by _cairo_fopen on Windows so it must
be defined even if Win32 fonts or other features are disabled.
Expand All @@ -72,3 +72,23 @@ index 1111111..2222222 100644
# define CAIRO_HAS_UTF8_TO_UTF16 1
#endif
#if CAIRO_HAS_UTF8_TO_UTF16

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Fri, 20 Mar 2020 13:00:00 +0100
Subject: [PATCH 4/4] Avoid mapping platform-specific functions on MinGW


diff --git a/src/cairo-compiler-private.h b/src/cairo-compiler-private.h
index 1111111..2222222 100644
--- a/src/cairo-compiler-private.h
+++ b/src/cairo-compiler-private.h
@@ -195,7 +195,7 @@
#define __attribute__(x)
#endif

-#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER)
+#if (defined(__WIN32__) && !defined(__WINE__) && !defined(__MINGW32__)) || defined(_MSC_VER)
#define access _access
#define fdopen _fdopen
#define hypot _hypot
30 changes: 30 additions & 0 deletions 8.9/patches/fftw-3-fixes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
This file is part of MXE. See LICENSE.md for licensing information.

Contains ad hoc patches for cross building.

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <[email protected]>
Date: Sun, 16 Feb 2020 19:20:00 +0100
Subject: [PATCH 1/1] Fixes for the llvm-mingw ARM/ARM64 build


diff --git a/threads/threads.c b/threads/threads.c
index 1111111..2222222 100644
--- a/threads/threads.c
+++ b/threads/threads.c
@@ -236,7 +236,15 @@ typedef volatile LONG os_static_mutex_t;
static void os_static_mutex_lock(os_static_mutex_t *s)
{
while (InterlockedExchange(s, 1) == 1) {
+#if defined(_MSC_VER)
YieldProcessor();
+#elif defined(__i386__) || defined(__x86_64__)
+ __asm__ __volatile__("pause");
+#elif defined(__ia64__) || defined(__ia64)
+ __asm__ __volatile__ ("hint @pause");
+#elif defined(__arm__) || defined(__aarch64__)
+ __asm__ __volatile__ ("yield");
+#endif
Sleep(0);
}
}
Loading

0 comments on commit a5eb868

Please sign in to comment.