Bug 1350362 Fix NSS Build System for MinGW draft
authorTom Ritter <tom@mozilla.com>
Wed, 10 May 2017 15:14:51 -0500
changeset 575737 d42620b0ee659b42dfcefa2f887549fb156fc805
parent 575736 3d9e022a3fb5e0645798ad4b2a0d43e11b5ca1ab
child 628004 8924d71c8204df4530553d1bd3530bda67432b2a
push id58151
push userbmo:tom@mozilla.com
push dateWed, 10 May 2017 20:15:37 +0000
bugs1350362
milestone55.0a1
Bug 1350362 Fix NSS Build System for MinGW MozReview-Commit-ID: 4QROlna5Cvg
security/generate_mapfile.py
security/moz.build
security/nss/coreconf/config.gypi
security/nss/lib/freebl/freebl.gyp
security/nss/lib/freebl/freebl_base.gypi
--- a/security/generate_mapfile.py
+++ b/security/generate_mapfile.py
@@ -7,43 +7,49 @@
 # This script processes NSS .def files according to the rules defined in
 # a comment at the top of each one. The files are used to define the
 # exports from NSS shared libraries, with -DEFFILE on Windows, a linker
 # script on Linux, or with -exported_symbols_list on OS X.
 #
 # The NSS build system processes them using a series of sed replacements,
 # but the Mozilla build system is already running a Python script to generate
 # the file so it's simpler to just do the replacement in Python.
+#
+# One difference between the NSS build system and Mozilla's is that
+# Mozilla's supports building on Linux for Windows using MinGW. MinGW
+# expects all lines containing ;+ removed and all ;- tokens removed.
 
 import buildconfig
 
 
 def main(output, input):
     is_darwin = buildconfig.substs['OS_ARCH'] == 'Darwin'
+    is_mingw = "WINNT" == buildconfig.substs['OS_ARCH'] and buildconfig.substs['GCC_USE_GNU_LD']
 
     with open(input, 'rb') as f:
         for line in f:
             line = line.rstrip()
             # Remove all lines containing ';-'
-            if ';-' in line:
+            if not is_mingw and ';-' in line:
                 continue
             # On OS X, remove all lines containing ';+'
             if is_darwin and ';+' in line:
                 continue
             # Remove the string ' DATA '.
             line = line.replace(' DATA ', '')
             # Remove the string ';+'
-            line = line.replace(';+', '')
+            if not is_mingw:
+                line = line.replace(';+', '')
             # Remove the string ';;'
             line = line.replace(';;', '')
             # If a ';' is present, remove everything after it,
             # and on OS X, remove it as well.
             i = line.find(';')
             if i != -1:
-                if is_darwin:
+                if is_darwin or is_mingw:
                     line = line[:i]
                 else:
                     line = line[:i+1]
             # On OS X, symbols get an underscore in front.
             if line and is_darwin:
                 output.write('_')
             output.write(line)
             output.write('\n')
--- a/security/moz.build
+++ b/security/moz.build
@@ -88,16 +88,18 @@ else:
     gyp_vars['nspr_include_dir'] = CONFIG['NSPR_INCLUDE_DIR']
     gyp_vars['nspr_lib_dir'] = CONFIG['NSPR_LIB_DIR']
     # The Python scripts that detect clang need it to be set as CC
     # in the environment, which isn't true here. I don't know that
     # setting that would be harmful, but we already have this information
     # anyway.
     if CONFIG['CLANG_CXX'] or CONFIG['CLANG_CL']:
         gyp_vars['cc_is_clang'] = 1
+    if CONFIG['GNU_CC']:
+        gyp_vars['cc_use_gnu_ld'] = 1
 
     GYP_DIRS += ['nss']
     GYP_DIRS['nss'].input = 'nss/nss.gyp'
     GYP_DIRS['nss'].variables = gyp_vars
 
     sandbox_vars = {
         # NSS explicitly exports its public symbols
         # with linker scripts.
@@ -108,16 +110,18 @@ else:
         # We could probably do so, but not without a lot of
         # careful consideration.
         'NO_PGO': True,
     }
     if CONFIG['OS_TARGET'] == 'WINNT':
         if CONFIG['CPU_ARCH'] == 'x86':
             # This should really be the default.
             sandbox_vars['ASFLAGS'] = ['-safeseh']
+        if CONFIG['MOZ_FOLD_LIBS_FLAGS']:
+            sandbox_vars['CFLAGS'] = [CONFIG['MOZ_FOLD_LIBS_FLAGS']]
     if CONFIG['OS_TARGET'] == 'Android':
         sandbox_vars['CFLAGS'] = [
             '-include', TOPSRCDIR + '/security/manager/android_stub.h',
             # Setting sandbox_vars['DEFINES'] is broken currently.
             '-DCHECK_FORK_GETPID',
         ]
         if CONFIG['ANDROID_VERSION']:
             sandbox_vars['CFLAGS'] += ['-DANDROID_VERSION=' + CONFIG['ANDROID_VERSION']]
--- a/security/nss/coreconf/config.gypi
+++ b/security/nss/coreconf/config.gypi
@@ -213,17 +213,17 @@
           ],
         },
         'conditions': [
           [ 'cc_use_gnu_ld==1', {
             'ldflags': [
               '-Wl,--version-script,<(INTERMEDIATE_DIR)/out.>(mapfile)',
             ],
           }],
-          [ 'OS=="win"', {
+          [ 'cc_use_gnu_ld!=1 and OS=="win"', {
             # On Windows, .def files are used directly as sources.
             'sources': [
               '>(mapfile)',
             ],
           }, {
             # On other platforms, .def files need processing.
             'sources': [
               '<(INTERMEDIATE_DIR)/out.>(mapfile)',
--- a/security/nss/lib/freebl/freebl.gyp
+++ b/security/nss/lib/freebl/freebl.gyp
@@ -169,27 +169,38 @@
           },
         },
       }],
       [ 'OS=="win" and target_arch=="x64"', {
         'msvs_settings': {
           'VCCLCompilerTool': {
             #TODO: -Ox optimize flags
             'PreprocessorDefinitions': [
+	      # Should be copied to mingw defines below
               'MP_IS_LITTLE_ENDIAN',
               'NSS_BEVAND_ARCFOUR',
               'MPI_AMD64',
               'MP_ASSEMBLY_MULTIPLY',
               'NSS_USE_COMBA',
               'USE_HW_AES',
               'INTEL_GCM',
             ],
           },
         },
       }],
+      [ 'cc_use_gnu_ld==1 and OS=="win" and target_arch=="x64"', {
+        'defines': [
+          'MP_IS_LITTLE_ENDIAN',
+          'NSS_BEVAND_ARCFOUR',
+          'MPI_AMD64',
+          'MP_ASSEMBLY_MULTIPLY',
+          'NSS_USE_COMBA',
+          'USE_HW_AES',
+         ],
+      }],
       [ 'OS!="win"', {
         'conditions': [
           [ 'target_arch=="x64" or target_arch=="arm64" or target_arch=="aarch64"', {
             'defines': [
               # The Makefile does version-tests on GCC, but we're not doing that here.
               'HAVE_INT128_SUPPORT',
             ],
           }, {
--- a/security/nss/lib/freebl/freebl_base.gypi
+++ b/security/nss/lib/freebl/freebl_base.gypi
@@ -101,26 +101,27 @@
       'sources': [
         #TODO: building with mingw should not need this.
         'ecl/uint128.c',
       ],
       'libraries': [
         'advapi32.lib',
       ],
       'conditions': [
-        [ 'target_arch=="x64"', {
+        [ 'cc_use_gnu_ld!=1 and target_arch=="x64"', {
           'sources': [
             'arcfour-amd64-masm.asm',
             'mpi/mpi_amd64.c',
             'mpi/mpi_amd64_masm.asm',
             'mpi/mp_comba_amd64_masm.asm',
             'intel-aes-x64-masm.asm',
             'intel-gcm-x64-masm.asm',
           ],
-        }, {
+        }],
+	[ 'cc_use_gnu_ld!=1 and target_arch!="x64"', {
           # not x64
           'sources': [
             'mpi/mpi_x86_asm.c',
             'intel-aes-x86-masm.asm',
             'intel-gcm-x86-masm.asm',
           ],
         }],
         [ 'cc_is_clang!=1', {