Bug 1262155 - Use moz.build instead of libffi's build system. r=ted,glandium
authorChris Manchester <cmanchester@mozilla.com>
Mon, 08 Aug 2016 16:58:54 -0700
changeset 314856 cddf2e43ee9f5e047573c92e101a333948fe5705
parent 314855 0f8ca5c828f254754661a1d5a7cae5f22163a1b9
child 314857 f4a5fdfecb10d5052c9f065c502aa30b9e155d32
push id20591
push usercbook@mozilla.com
push dateThu, 22 Sep 2016 11:42:18 +0000
treeherderfx-team@f0e6cc636021 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted, glandium
bugs1262155
milestone52.0a1
Bug 1262155 - Use moz.build instead of libffi's build system. r=ted,glandium MozReview-Commit-ID: 3wobNk0HDU5
aclocal.m4
build/autoconf/alloc.m4
build/autoconf/ffi.m4
build/moz.configure/ffi.configure
build/moz.configure/headers.configure
config/external/ffi/Makefile.in
config/external/ffi/moz.build
config/external/ffi/subst_header.py
js/src/aclocal.m4
js/src/moz.build
js/src/old-configure.in
old-configure.in
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -19,17 +19,16 @@ builtin(include, build/autoconf/mozheade
 builtin(include, build/autoconf/lto.m4)dnl
 builtin(include, build/autoconf/frameptr.m4)dnl
 builtin(include, build/autoconf/compiler-opts.m4)dnl
 builtin(include, build/autoconf/expandlibs.m4)dnl
 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
 builtin(include, build/autoconf/jemalloc.m4)dnl
 builtin(include, build/autoconf/sanitize.m4)dnl
 
 MOZ_PROG_CHECKMSYS()
 
--- a/build/autoconf/alloc.m4
+++ b/build/autoconf/alloc.m4
@@ -11,18 +11,16 @@ MALLOC_H=
 for file in $MALLOC_HEADERS; do
   MOZ_CHECK_HEADER($file, [MALLOC_H=$file])
   if test "$MALLOC_H" != ""; then
     AC_DEFINE_UNQUOTED(MALLOC_H, <$MALLOC_H>)
     break
   fi
 done
 
-MOZ_CHECK_HEADERS(alloca.h)
-
 AC_CHECK_FUNCS(strndup posix_memalign memalign)
 
 AC_CHECK_FUNCS(malloc_usable_size)
 MALLOC_USABLE_SIZE_CONST_PTR=const
 if test -n "$HAVE_MALLOC_H"; then
   AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
   AC_TRY_COMPILE([#include <malloc.h>
                   #include <stddef.h>
deleted file mode 100644
--- 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
-])
-
--- a/build/moz.configure/ffi.configure
+++ b/build/moz.configure/ffi.configure
@@ -1,16 +1,57 @@
 # -*- Mode: python; 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/.
 
+@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)')
 
 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'))
--- a/build/moz.configure/headers.configure
+++ b/build/moz.configure/headers.configure
@@ -9,16 +9,18 @@ check_header('stdint.h')
 have_inttypes = check_header('inttypes.h')
 
 set_config('HAVE_INTTYPES_H', have_inttypes)
 
 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(
     'sys/byteorder.h',
     'getopt.h',
     'unistd.h',
     'nl_types.h',
     'cpuid.h',
--- 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
--- a/config/external/ffi/moz.build
+++ b/config/external/ffi/moz.build
@@ -1,18 +1,101 @@
 # -*- Mode: python; 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/.
 
-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)
+    ]
new file mode 100644
--- /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:])
--- a/js/src/aclocal.m4
+++ b/js/src/aclocal.m4
@@ -18,17 +18,16 @@ builtin(include, ../../build/autoconf/mo
 builtin(include, ../../build/autoconf/lto.m4)dnl
 builtin(include, ../../build/autoconf/frameptr.m4)dnl
 builtin(include, ../../build/autoconf/compiler-opts.m4)dnl
 builtin(include, ../../build/autoconf/expandlibs.m4)dnl
 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
 builtin(include, ../../build/autoconf/sanitize.m4)dnl
 builtin(include, ../../build/autoconf/ios.m4)dnl
 
 define([__MOZ_AC_INIT_PREPARE], defn([AC_INIT_PREPARE]))
 define([AC_INIT_PREPARE],
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -589,16 +589,17 @@ else:
 if CONFIG['JS_HAS_CTYPES']:
     SOURCES += [
         'ctypes/CTypes.cpp',
         'ctypes/Library.cpp',
     ]
     if not CONFIG['MOZ_SYSTEM_FFI']:
         LOCAL_INCLUDES += [
             '!ctypes/libffi/include',
+            'ctypes/libffi/src/%s' % CONFIG['FFI_TARGET_DIR'],
         ]
 
 if CONFIG['MOZ_VTUNE']:
     SOURCES += [
         'vtune/jitprofiling.c'
     ]
 
 if CONFIG['HAVE_LINUX_PERF_EVENT_H']:
@@ -632,21 +633,16 @@ if CONFIG['JS_SHARED_LIBRARY']:
     SHARED_LIBRARY_NAME = CONFIG['JS_LIBRARY_NAME']
     SDK_LIBRARY = True
 else:
     Library('js')
 
 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 += [
             'icu',
         ]
     else:
         # Linking 'icu' will pull in the stubdata library,
         # which the shell doesn't want, so link the other bits.
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -2275,17 +2275,16 @@ if test -n "$GNU_CC"; then
 JS_CONFIG_MOZ_JS_LIBS='-L${libdir} -l${JS_LIBRARY_NAME}'
 else
 JS_CONFIG_MOZ_JS_LIBS='${libdir}/${JS_LIBRARY_NAME}.lib'
 fi
 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
 AC_DEFINE(NO_NSPR_10_SUPPORT)
 
 dnl Spit out some output
 dnl ========================================================
 MOZ_CREATE_CONFIG_STATUS()
--- a/old-configure.in
+++ b/old-configure.in
@@ -6022,17 +6022,16 @@ AC_DEFINE(NO_NSPR_10_SUPPORT)
 
 # Don't build NSS libpkix
 NSS_DISABLE_LIBPKIX=1
 AC_SUBST(NSS_DISABLE_LIBPKIX)
 
 MOZ_CREATE_CONFIG_STATUS()
 
 if test "$COMPILE_ENVIRONMENT"; then
-  MOZ_SUBCONFIGURE_FFI()
   MOZ_SUBCONFIGURE_JEMALLOC()
 fi
 
 # Run freetype configure script
 
 if test "$MOZ_TREE_FREETYPE"; then
    export CFLAGS="$CFLAGS $MOZ_DEBUG_FLAGS -std=c99"
    export CPPFLAGS="$CPPFLAGS $MOZ_DEBUG_FLAGS"