Bug 1621785 - Build configuration for OpenPGP libraries. r=kaie
authorRob Lemley <rob@thunderbird.net>
Tue, 14 Apr 2020 22:29:22 +0000
changeset 37956 b1139f8617d4488b3bb5693c50886c3a9925c43b
parent 37955 a6d09372afd04610039510fd19ed6620f520c14e
child 37957 7c06681d8e9a22d9226498c34b620cd4d3cf8ea3
push id2595
push userclokep@gmail.com
push dateMon, 04 May 2020 19:02:04 +0000
treeherdercomm-beta@f53913797371 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaie
bugs1621785
Bug 1621785 - Build configuration for OpenPGP libraries. r=kaie Differential Revision: https://phabricator.services.mozilla.com/D70758
third_party/defs.mk
third_party/moz.build
third_party/openpgp.configure
third_party/rnpdefs.mozbuild
new file mode 100644
--- /dev/null
+++ b/third_party/defs.mk
@@ -0,0 +1,12 @@
+# 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/.
+
+# This file is included my mozbuild for this directory and any subdirectories
+# that use mozbuild. Currently the OTR libraries do not use mozbuild and
+# are not affected.
+
+# MZLA_RNP_CC and MZLA_RNP_CXX are set in openpgp.configure and are used
+# to remove the -std= flags from the commands.
+CC := $(MZLA_RNP_CC)
+CXX := $(MZLA_RNP_CXX)
--- a/third_party/moz.build
+++ b/third_party/moz.build
@@ -3,8 +3,17 @@
 # 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/.
 
 if CONFIG['TB_LIBOTR_PREBUILT']:
     DEFINES['TB_LIBOTR_PREBUILT'] = CONFIG['TB_LIBOTR_PREBUILT']
 
     if CONFIG['HAVE_64BIT_BUILD']:
         DEFINES['HAVE_64BIT_BUILD'] = True
+
+if CONFIG['MOZ_OPENPGP']:
+    DIRS += [
+        'botan',
+        'bzip2',
+        'json-c',
+        'rnp',
+        'zlib',
+    ]
new file mode 100644
--- /dev/null
+++ b/third_party/openpgp.configure
@@ -0,0 +1,155 @@
+# -*- 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/.
+
+
+@template
+def noset_check_header(header, language='C++', flags=None, includes=None, when=None,
+                 onerror=lambda: None):
+    if when is None:
+        when = always
+
+    if includes:
+        includes = includes[:]
+    else:
+        includes = []
+    includes.append(header)
+
+    return try_compile(includes=includes, language=language, flags=flags,
+                       check_msg='for %s' % header, when=when, onerror=onerror)
+
+
+@template
+def check_symbol_exists(symbol, header, language='C', flags=None, includes=None,
+                        when=None, onerror=lambda: None):
+    if when is None:
+        when = always
+
+    if includes:
+        includes = includes[:]
+    else:
+        includes = []
+    includes.append('stdio.h')
+    includes.append(header)
+
+    body = '''#ifndef %s
+(void) %s;
+#endif
+''' % (symbol, symbol)
+
+    return try_compile(includes, body, language=language, flags=flags,
+                       check_msg='for %s' % symbol, when=when, onerror=onerror)
+
+
+have_fcntl_h = check_header('fcntl.h')
+have_stdlib_h = check_header('stdlib.h')
+have_locale_h = check_header('locale.h')
+have_string_h = check_header('string.h')
+have_strings_h = check_header('strings.h')
+
+check_headers(
+    'stdarg.h',
+    'dlfcn.h',
+    'endian.h',
+    'limits.h',
+    'memory.h',
+    'sys/auxv.h',
+    'sys/cdefs.h',
+    'sys/resource.h',
+    'sys/param.h',
+    'sys/stat.h',
+    'sys/wait.h',
+    'xlocale.h'
+)
+
+set_define('JSON_C_HAVE_INTTYPES_H', noset_check_header('inttypes.h'))
+
+set_define('HAVE_DECL__ISNAN', check_symbol_exists('_isnan', 'float.h'))
+
+set_define('HAVE_DECL__FINITE', check_symbol_exists('_finite', 'float.h'))
+set_define('HAVE_DECL_INFINITY', check_symbol_exists('INFINITY', 'math.h'))
+set_define('HAVE_DECL_ISINF', check_symbol_exists('isinf', 'math.h'))
+set_define('HAVE_DECL_ISNAN', check_symbol_exists('isnan', 'math.h'))
+set_define('HAVE_DECL_NAN', check_symbol_exists('nan', 'math.h'))
+
+set_define('HAVE_DOPRNT', check_symbol_exists('_doprnt', 'stdio.h'))
+set_define('HAVE_SNPRINTF', check_symbol_exists('snprintf', 'stdio.h'))
+set_define('HAVE_VASPRINTF', check_symbol_exists('vasprintf', 'stdio.h', flags=['-D_GNU_SOURCE']))
+set_define('HAVE_VSNPRINTF', check_symbol_exists('vsnprintf', 'stdio.h'))
+set_define('HAVE_VPRINTF', check_symbol_exists('vprintf', 'stdio.h'))
+
+set_define('HAVE_OPEN', check_symbol_exists('open', 'fcntl.h', when=have_fcntl_h))
+set_define('HAVE_REALLOC', check_symbol_exists('realloc', 'stdlib.h', when=have_stdlib_h))
+set_define('HAVE_SETLOCALE', check_symbol_exists('setlocale', 'locale.h', when=have_locale_h))
+set_define('HAVE_USELOCALE', check_symbol_exists('uselocale', 'locale.h', when=have_locale_h))
+set_define('HAVE_STRCASECMP', check_symbol_exists('strcasecmp', 'strings.h', when=have_strings_h))
+set_define('HAVE_STRNCASECMP', check_symbol_exists('strncasecmp', 'strings.h', when=have_strings_h))
+set_define('HAVE_STRDUP', check_symbol_exists('strdup', 'string.h', when=have_string_h))
+
+set_define('HAVE_MKDTEMP', check_symbol_exists('mkdtemp', ['stdlib.h','unistd.h']))
+set_define('HAVE_REALPATH', check_symbol_exists('realpath', 'stdlib.h'))
+set_define('HAVE_O_BINARY', check_symbol_exists('O_BINARY', 'fcntl.h'))
+set_define('HAVE__O_BINARY', check_symbol_exists('_O_BINARY', 'fcntl.h'))
+
+
+@depends(c_compiler, target)
+@checking('for clang_rt.builtins path', lambda x: x if x is None else x.clang_rt_lib)
+@imports(_from='os', _import='pathsep')
+@imports(_from='os.path', _import='isdir')
+@imports(_from='os.path', _import='exists')
+@imports(_from='os.path', _import='join')
+def clang_rt_builtins(compiler_info, target):
+    if compiler_info.type == 'clang-cl':
+        if target.raw_cpu in ['i686']:
+            rt_arch = 'i386'
+        else:
+            rt_arch = target.raw_cpu
+
+        clang_rt_builtins = 'clang_rt.builtins-{}'.format(rt_arch)
+        clang_cl = compiler_info.compiler
+        flags = []
+        flags.extend(compiler_info.flags)
+        flags.append('-clang:-print-search-dirs')
+        clang_search_dirs = check_cmd_output(clang_cl, *flags)
+        for line in clang_search_dirs.splitlines():
+            name, _, value = line.partition(': =')
+            if name == 'libraries':
+                for dir in value.split(pathsep):
+                    if dir.endswith(compiler_info.version.vstring):
+                        clang_rt_dir = join(dir, 'lib/windows')
+                        clang_rt_lib = join(clang_rt_dir, clang_rt_builtins)
+                        if isdir(clang_rt_dir):
+                            if exists('{}.lib'.format(clang_rt_lib)):
+                                return namespace(
+                                    clang_rt_path=clang_rt_dir,
+                                    clang_rt_lib=clang_rt_lib
+                                )
+        die('Cannot find clang_rt.builtins path.')
+
+
+set_config('COMPILER_RT_BUILTIN_PATH', clang_rt_builtins.clang_rt_path, when=is_windows)
+set_config('COMPILER_RT_BUILTIN_LIB', clang_rt_builtins.clang_rt_lib, when=is_windows)
+
+
+@depends(c_compiler, cxx_compiler)
+def rnp_compiler(c_compiler, cxx_compiler):
+    _cflags = [f for f in c_compiler.flags if f not in ('-Xclang', '-std=gnu99')]
+    _cxxflags = [f for f in cxx_compiler.flags if f not in ('-Xclang', '-std=c++17', '-std=gnu17')]
+
+    rnp_cc = ' '.join(list(c_compiler.wrapper) + [c_compiler.compiler] + _cflags)
+    rnp_cxx = ' '.join(list(cxx_compiler.wrapper) + [cxx_compiler.compiler] + _cxxflags)
+
+    return namespace(rnp_cc=rnp_cc,
+                     rnp_cxx=rnp_cxx)
+
+set_config('MZLA_RNP_CC', rnp_compiler.rnp_cc)
+set_config('MZLA_RNP_CXX', rnp_compiler.rnp_cxx)
+
+@depends('MOZ_AUTOMATION')
+def tb_is_automation(automation):
+    if automation:
+        return True
+
+set_config('TB_IS_AUTOMATION', tb_is_automation)
new file mode 100644
--- /dev/null
+++ b/third_party/rnpdefs.mozbuild
@@ -0,0 +1,32 @@
+# -*- 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/.
+
+# We allow warnings for third-party code that can be updated from upstream.
+AllowCompilerWarnings()
+DisableStlWrapping()
+NoVisibilityFlags()
+
+
+rnp_dist_info = '{} {} rnp'.format(
+    CONFIG['MOZ_APP_DISPLAYNAME'],
+    CONFIG['MOZ_APP_VERSION_DISPLAY']
+)
+
+COMPILE_FLAGS['OS_CFLAGS'] = []
+COMPILE_FLAGS['OS_CXXFLAGS'] = []
+COMPILE_FLAGS['OS_INCLUDES'] = []
+COMPILE_FLAGS['CLANG_PLUGIN'] = []
+COMPILE_FLAGS['MOZ_HARDENING_CFLAGS'] = []
+
+if CONFIG['CC_TYPE'] == 'clang-cl':
+    CFLAGS += [
+        '-Wno-inconsistent-dllimport',
+        '-Wno-macro-redefined', # 'WIN32_LEAN_AND_MEAN' macro redefined
+    ]
+    USE_STATIC_LIBS = True
+
+if CONFIG['MOZ_LIBSTDCXX_TARGET_VERSION']:
+    DEFINES['_GLIBCXX_USE_CXX11_ABI'] = 0