From 6736329d5eed47b222cd3ea88c855b0a26cdf0c1 Mon Sep 17 00:00:00 2001 From: Chris Manchester Date: Mon, 8 Aug 2016 16:58:54 -0700 Subject: [PATCH] Bug 1262155 - Use moz.build instead of libffi's build system. r=ted,glandium MozReview-Commit-ID: 3wobNk0HDU5 --- aclocal.m4 | 1 - build/autoconf/alloc.m4 | 2 - build/autoconf/ffi.m4 | 74 -------------------- build/moz.configure/ffi.configure | 41 +++++++++++ build/moz.configure/headers.configure | 2 + config/external/ffi/Makefile.in | 14 ++-- config/external/ffi/moz.build | 99 ++++++++++++++++++++++++--- config/external/ffi/subst_header.py | 25 +++++++ js/src/aclocal.m4 | 1 - js/src/moz.build | 6 +- js/src/old-configure.in | 1 - old-configure.in | 1 - 12 files changed, 167 insertions(+), 100 deletions(-) delete mode 100644 build/autoconf/ffi.m4 create mode 100644 config/external/ffi/subst_header.py diff --git a/aclocal.m4 b/aclocal.m4 index c938ad093d78..fe8419da2db2 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -24,7 +24,6 @@ builtin(include, build/autoconf/arch.m4)dnl builtin(include, build/autoconf/android.m4)dnl builtin(include, build/autoconf/zlib.m4)dnl builtin(include, build/autoconf/icu.m4)dnl -builtin(include, build/autoconf/ffi.m4)dnl builtin(include, build/autoconf/clang-plugin.m4)dnl builtin(include, build/autoconf/alloc.m4)dnl builtin(include, build/autoconf/ios.m4)dnl diff --git a/build/autoconf/alloc.m4 b/build/autoconf/alloc.m4 index 33e4a3f68a09..6a0772f58058 100644 --- a/build/autoconf/alloc.m4 +++ b/build/autoconf/alloc.m4 @@ -16,8 +16,6 @@ for file in $MALLOC_HEADERS; do fi done -MOZ_CHECK_HEADERS(alloca.h) - AC_CHECK_FUNCS(strndup posix_memalign memalign) AC_CHECK_FUNCS(malloc_usable_size) diff --git a/build/autoconf/ffi.m4 b/build/autoconf/ffi.m4 deleted file mode 100644 index 8e8cc38ee1c0..000000000000 --- a/build/autoconf/ffi.m4 +++ /dev/null @@ -1,74 +0,0 @@ -dnl This Source Code Form is subject to the terms of the Mozilla Public -dnl License, v. 2.0. If a copy of the MPL was not distributed with this -dnl file, You can obtain one at http://mozilla.org/MPL/2.0/. - -AC_DEFUN([MOZ_SUBCONFIGURE_FFI], [ -if test "$MOZ_BUILD_APP" != js -o -n "$JS_STANDALONE"; then - - if test "$BUILD_CTYPES" -a -z "$MOZ_SYSTEM_FFI"; then - # Run the libffi 'configure' script. - ac_configure_args="--disable-shared --enable-static --disable-raw-api" - if test "$MOZ_DEBUG"; then - ac_configure_args="$ac_configure_args --enable-debug" - fi - if test "$DSO_PIC_CFLAGS"; then - ac_configure_args="$ac_configure_args --with-pic" - fi - for var in AS CC CXX CPP LD AR RANLIB STRIP; do - ac_configure_args="$ac_configure_args $var='`eval echo \\${${var}}`'" - done - old_cflags="$CFLAGS" - # The libffi sources (especially the ARM ones) are written expecting gas - # syntax, and clang's integrated assembler doesn't handle all of gas syntax. - if test -n "$CLANG_CC" -a "$CPU_ARCH" = arm; then - CFLAGS="-no-integrated-as $CFLAGS" - fi - ac_configure_args="$ac_configure_args --build=$build --host=$target" - if test "$CROSS_COMPILE"; then - ac_configure_args="$ac_configure_args \ - CFLAGS=\"$CFLAGS\" \ - CPPFLAGS=\"$CPPFLAGS\" \ - LDFLAGS=\"$LDFLAGS\"" - fi - CFLAGS="$old_cflags" - if test "$_MSC_VER"; then - # Use a wrapper script for cl and ml that looks more like gcc. - # autotools can't quite handle an MSVC build environment yet. - LDFLAGS= - CFLAGS= - ac_configure_args="$ac_configure_args LD=link CPP=\"$CC -nologo -EP\" \ - CXXCPP=\"$CXX -nologo -EP\" SHELL=sh.exe" - flags= - if test -z "$MOZ_NO_DEBUG_RTL" -a -n "$MOZ_DEBUG"; then - flags=" -DUSE_DEBUG_RTL" - fi - if test -n "$CLANG_CL"; then - flags="$flags -clang-cl" - fi - case "${target_cpu}" in - x86_64) - # Need target since MSYS tools into mozilla-build may be 32bit - ac_configure_args="$ac_configure_args \ - CC=\"$_topsrcdir/js/src/ctypes/libffi/msvcc.sh -m64$flags\" \ - CXX=\"$_topsrcdir/js/src/ctypes/libffi/msvcc.sh -m64$flags\"" - ;; - *) - ac_configure_args="$ac_configure_args \ - CC=\"$_topsrcdir/js/src/ctypes/libffi/msvcc.sh$flags\" \ - CXX=\"$_topsrcdir/js/src/ctypes/libffi/msvcc.sh$flags\"" - ;; - esac - fi - - # Use a separate cache file for libffi, since it does things differently - # from our configure. - old_config_files=$CONFIG_FILES - unset CONFIG_FILES - AC_OUTPUT_SUBDIRS(js/src/ctypes/libffi) - ac_configure_args="$_SUBDIR_CONFIG_ARGS" - CONFIG_FILES=$old_config_files - fi - -fi -]) - diff --git a/build/moz.configure/ffi.configure b/build/moz.configure/ffi.configure index a85ebea08bf2..d7fc365ff558 100644 --- a/build/moz.configure/ffi.configure +++ b/build/moz.configure/ffi.configure @@ -4,6 +4,14 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +@depends(target) +def force_system_ffi(target): + # Pre-emptively move to system ffi for non-tier one platforms. + if target.cpu not in ('x86', 'x86_64', 'arm'): + return True + +imply_option('--with-system-ffi', force_system_ffi, "target") + js_option('--with-system-ffi', help='Use system libffi (located with pkgconfig)') @@ -12,5 +20,38 @@ use_system_ffi = depends_if('--with-system-ffi')(lambda _: True) system_ffi = pkg_check_modules('MOZ_FFI', 'libffi > 3.0.9', when=use_system_ffi) +building_ffi = depends(system_ffi)(lambda v: not bool(v)) + set_config('MOZ_SYSTEM_FFI', system_ffi) add_old_configure_assignment('MOZ_SYSTEM_FFI', system_ffi) + +# Target selection, based on ffi/configure.ac. +@depends_when(target, when=building_ffi) +def ffi_target(target): + if target.cpu not in ('x86', 'x86_64', 'arm'): + die('Building libffi from the tree is not supported on this platform. ' + 'Use --with-system-ffi instead.') + + if target.os == 'WINNT': + target_dir = 'x86' + if target.cpu == 'x86_64': + target_name = 'X86_WIN64' + else: + target_name = 'X86_WIN32' + elif target.os == 'OSX': + target_dir = 'x86' + target_name = 'X86_DARWIN' + elif target.cpu == 'arm': + target_dir = 'arm' + target_name = 'ARM' + else: + target_dir = 'x86' + target_name = target.cpu.upper() + + return namespace( + name=target_name, + dir=target_dir + ) + +set_config('FFI_TARGET', delayed_getattr(ffi_target, 'name')) +set_config('FFI_TARGET_DIR', delayed_getattr(ffi_target, 'dir')) diff --git a/build/moz.configure/headers.configure b/build/moz.configure/headers.configure index b91ceb756777..ff33626d3803 100644 --- a/build/moz.configure/headers.configure +++ b/build/moz.configure/headers.configure @@ -14,6 +14,8 @@ building_linux = depends(target)(lambda target: target.kernel == 'Linux') have_malloc = check_header('malloc.h') +check_header('alloca.h') + add_old_configure_assignment('HAVE_MALLOC_H', have_malloc) check_headers( diff --git a/config/external/ffi/Makefile.in b/config/external/ffi/Makefile.in index c268c5f31d8a..717b5d8291e2 100644 --- a/config/external/ffi/Makefile.in +++ b/config/external/ffi/Makefile.in @@ -1,12 +1,12 @@ +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -ifndef MOZ_SYSTEM_FFI - -include $(topsrcdir)/config/config.mk - -$(STATIC_LIBS): - $(MAKE) -C $(DEPTH)/js/src/ctypes/libffi - +# libffi's assembly files want to be pre-processed, so we still use the libffi +# wrapper to combine the preprocessor and assembler stages. +# Bug 1299959 is on file to find a better way to do this in moz.build. +ifdef _MSC_VER +AS = $(topsrcdir)/js/src/ctypes/libffi/msvcc.sh endif diff --git a/config/external/ffi/moz.build b/config/external/ffi/moz.build index e5c2c3bb14a5..a0fed263e38f 100644 --- a/config/external/ffi/moz.build +++ b/config/external/ffi/moz.build @@ -4,15 +4,98 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -Library('ffi') - if CONFIG['MOZ_SYSTEM_FFI']: OS_LIBS += CONFIG['MOZ_FFI_LIBS'] else: - if CONFIG['_MSC_VER']: - prefix = 'lib' - else: - prefix = '' - USE_LIBS += [ - 'static:/js/src/ctypes/libffi/.libs/%sffi' % prefix, + FINAL_LIBRARY = 'js' + ALLOW_COMPILER_WARNINGS = True + NO_VISIBILITY_FLAGS = True + + CONFIGURE_DEFINE_FILES += [ + '../../../js/src/ctypes/libffi/fficonfig.h', + ] + GENERATED_FILES += [ + '../../../js/src/ctypes/libffi/include/ffi.h', + ] + ffi_h = GENERATED_FILES['../../../js/src/ctypes/libffi/include/ffi.h'] + ffi_h.script = 'subst_header.py' + ffi_h.inputs = ['../../../js/src/ctypes/libffi/include/ffi.h.in'] + + LOCAL_INCLUDES += [ + '!/js/src/ctypes/libffi', + '!/js/src/ctypes/libffi/include', + '/js/src/ctypes/libffi/include', + '/js/src/ctypes/libffi/src/%s' % CONFIG['FFI_TARGET_DIR'], + ] + + DEFINES.update({ + 'TARGET': CONFIG['FFI_TARGET'], + CONFIG['FFI_TARGET']: True, + 'FFI_NO_RAW_API': True, + 'HAVE_AS_ASCII_PSEUDO_OP': True, + 'HAVE_AS_STRING_PSEUDO_OP': True, + 'HAVE_AS_X86_64_UNWIND_SECTION_TYPE': True, + }) + + if CONFIG['MOZ_DEBUG']: + DEFINES['FFI_DEBUG'] = True + if not CONFIG['MOZ_NO_DEBUG_RTL']: + DEFINES['USE_DEBUG_RTL'] = True + SOURCES += [ + '/js/src/ctypes/libffi/src/debug.c', + ] + + if CONFIG['OS_TARGET'] not in ('WINNT', 'Darwin'): + DEFINES['HAVE_HIDDEN_VISIBILITY_ATTRIBUTE'] = True + + if CONFIG['INTEL_ARCHITECTURE']: + DEFINES['HAVE_AS_X86_PCREL'] = True + + # Don't bother setting EH_FRAME_FLAGS on Windows. + # Quoted defines confuse msvcc.sh, and the value isn't used there. + if CONFIG['OS_TARGET'] != 'WINNT': + if CONFIG['FFI_TARGET'] == 'ARM': + DEFINES['EH_FRAME_FLAGS'] = '"aw"' + else: + DEFINES['EH_FRAME_FLAGS'] = '"a"' + + if CONFIG['CLANG_CL']: + ASFLAGS += ['-clang-cl'] + + # Common source files. + SOURCES += [ + '/js/src/ctypes/libffi/src/closures.c', + '/js/src/ctypes/libffi/src/java_raw_api.c', + '/js/src/ctypes/libffi/src/prep_cif.c', + '/js/src/ctypes/libffi/src/raw_api.c', + '/js/src/ctypes/libffi/src/types.c', + ] + + # Per-platform sources and flags. + ffi_srcs = () + if CONFIG['FFI_TARGET'] == 'ARM': + ffi_srcs = ('sysv.S', 'ffi.c') + if CONFIG['CLANG_CXX']: + ASFLAGS += ['-no-integrated-as'] + elif CONFIG['FFI_TARGET'] == 'X86': + ffi_srcs = ('ffi.c', 'sysv.S', 'win32.S') + elif CONFIG['FFI_TARGET'] == 'X86_64': + ffi_srcs = ('ffi64.c', 'unix64.S', 'ffi.c', 'sysv.S') + elif CONFIG['FFI_TARGET'] == 'X86_WIN32': + ffi_srcs = ('ffi.c', 'win32.S') + elif CONFIG['FFI_TARGET'] == 'X86_WIN64': + ffi_srcs = ('ffi.c', 'win64.S') + ASFLAGS += ['-m64'] + elif CONFIG['FFI_TARGET'] == 'X86_DARWIN': + DEFINES['FFI_MMAP_EXEC_WRIT'] = True + if CONFIG['OS_TEST'] != 'x86_64': + ffi_srcs = ('ffi.c', 'darwin.S', 'ffi64.c', 'darwin64.S', + 'win32.S') + DEFINES['SYMBOL_UNDERSCORE'] = True + else: + ffi_srcs = ('ffi.c', 'darwin.S', 'ffi64.c', 'darwin64.S') + + SOURCES += [ + '/js/src/ctypes/libffi/src/%s/%s' % (CONFIG['FFI_TARGET_DIR'], s) + for s in sorted(ffi_srcs) ] diff --git a/config/external/ffi/subst_header.py b/config/external/ffi/subst_header.py new file mode 100644 index 000000000000..a138f9020040 --- /dev/null +++ b/config/external/ffi/subst_header.py @@ -0,0 +1,25 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Souce Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distibuted with this +# file, You can obtain one at http://mozilla.og/MPL/2.0/. + +import sys +import buildconfig +from mozbuild.preprocessor import Preprocessor + +def main(output, input_file): + pp = Preprocessor() + pp.context.update({ + 'FFI_EXEC_TRAMPOLINE_TABLE': '0', + 'HAVE_LONG_DOUBLE': '0', + 'TARGET': buildconfig.substs['FFI_TARGET'], + 'VERSION': '', + }) + pp.do_filter('substitution') + pp.setMarker(None) + pp.out = output + pp.do_include(input_file) + +if __name__ == '__main__': + main(*sys.agv[1:]) diff --git a/js/src/aclocal.m4 b/js/src/aclocal.m4 index 4f6b4f103bb7..627837a41247 100644 --- a/js/src/aclocal.m4 +++ b/js/src/aclocal.m4 @@ -23,7 +23,6 @@ builtin(include, ../../build/autoconf/arch.m4)dnl builtin(include, ../../build/autoconf/android.m4)dnl builtin(include, ../../build/autoconf/zlib.m4)dnl builtin(include, ../../build/autoconf/icu.m4)dnl -builtin(include, ../../build/autoconf/ffi.m4)dnl builtin(include, ../../build/autoconf/clang-plugin.m4)dnl builtin(include, ../../build/autoconf/alloc.m4)dnl builtin(include, ../../build/autoconf/jemalloc.m4)dnl diff --git a/js/src/moz.build b/js/src/moz.build index c2b44abe9f7e..b43acb83185c 100644 --- a/js/src/moz.build +++ b/js/src/moz.build @@ -594,6 +594,7 @@ if CONFIG['JS_HAS_CTYPES']: if not CONFIG['MOZ_SYSTEM_FFI']: LOCAL_INCLUDES += [ '!ctypes/libffi/include', + 'ctypes/libffi/src/%s' % CONFIG['FFI_TARGET_DIR'], ] if CONFIG['MOZ_VTUNE']: @@ -637,11 +638,6 @@ else: FORCE_STATIC_LIB = True STATIC_LIBRARY_NAME = 'js_static' -if CONFIG['JS_HAS_CTYPES']: - USE_LIBS += [ - 'ffi', - ] - if CONFIG['ENABLE_INTL_API']: if not CONFIG['MOZ_ICU_DATA_ARCHIVE']: USE_LIBS += [ diff --git a/js/src/old-configure.in b/js/src/old-configure.in index 6600bcdcffde..a046c4b15bba 100644 --- a/js/src/old-configure.in +++ b/js/src/old-configure.in @@ -2280,7 +2280,6 @@ AC_SUBST(JS_LIBRARY_NAME) AC_SUBST(JS_CONFIG_MOZ_JS_LIBS) AC_SUBST(JS_CONFIG_LIBS) -MOZ_SUBCONFIGURE_FFI() MOZ_SUBCONFIGURE_JEMALLOC() # Avoid using obsolete NSPR features diff --git a/old-configure.in b/old-configure.in index 004e432f4e98..611aa321fb79 100644 --- a/old-configure.in +++ b/old-configure.in @@ -6027,7 +6027,6 @@ AC_SUBST(NSS_DISABLE_LIBPKIX) MOZ_CREATE_CONFIG_STATUS() if test "$COMPILE_ENVIRONMENT"; then - MOZ_SUBCONFIGURE_FFI() MOZ_SUBCONFIGURE_JEMALLOC() fi