diff options
-rw-r--r-- | mesonbuild/compilers/c.py | 13 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 8 | ||||
-rw-r--r-- | mesonbuild/dependencies/dev.py | 54 | ||||
-rw-r--r-- | mesonbuild/envconfig.py | 13 | ||||
-rw-r--r-- | mesonbuild/modules/i18n.py | 3 | ||||
-rwxr-xr-x | run_unittests.py | 15 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/app/app.c | 13 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/app/meson.build | 2 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/liba/liba.c | 18 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/liba/liba.h | 8 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/liba/meson.build | 8 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/libb/libb.c | 7 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/libb/libb.h | 6 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/libb/meson.build | 6 | ||||
-rw-r--r-- | test cases/unit/55 dedup compiler libs/meson.build | 7 |
15 files changed, 149 insertions, 32 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index d4626d6..3548b6d 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -35,6 +35,7 @@ from .compilers import ( get_largefile_args, gnu_winlibs, msvc_winlibs, + unixy_compiler_internal_libs, vs32_instruction_set_args, vs64_instruction_set_args, ArmCompiler, @@ -52,8 +53,6 @@ from .compilers import ( CcrxCompiler, ) -gnu_compiler_internal_libs = ('m', 'c', 'pthread', 'dl', 'rt') - class CCompiler(Compiler): # TODO: Replace this manual cache with functools.lru_cache @@ -61,7 +60,7 @@ class CCompiler(Compiler): program_dirs_cache = {} find_library_cache = {} find_framework_cache = {} - internal_libs = gnu_compiler_internal_libs + internal_libs = unixy_compiler_internal_libs @staticmethod def attribute_check_func(name): @@ -912,8 +911,10 @@ class CCompiler(Compiler): priority ''' stlibext = ['a'] - # We've always allowed libname to be both `foo` and `libfoo`, - # and now people depend on it + # We've always allowed libname to be both `foo` and `libfoo`, and now + # people depend on it. Also, some people use prebuilt `foo.so` instead + # of `libfoo.so` for unknown reasons, and may also want to create + # `foo.so` by setting name_prefix to '' if strict and not isinstance(self, VisualStudioCCompiler): # lib prefix is not usually used with msvc prefixes = ['lib'] else: @@ -1375,7 +1376,7 @@ class IntelCCompiler(IntelCompiler, CCompiler): class VisualStudioCCompiler(CCompiler): std_warn_args = ['/W3'] std_opt_args = ['/O2'] - ignore_libs = gnu_compiler_internal_libs + ignore_libs = unixy_compiler_internal_libs internal_libs = () crt_args = {'none': [], diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 94ebf16..ceefefe 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -81,6 +81,9 @@ cflags_mapping = {'c': 'CFLAGS', 'vala': 'VALAFLAGS', 'rust': 'RUSTFLAGS'} +# execinfo is a compiler lib on BSD +unixy_compiler_internal_libs = ('m', 'c', 'pthread', 'dl', 'rt', 'execinfo') + # All these are only for C-linkable languages; see `clink_langs` above. def sort_clink(lang): @@ -659,6 +662,9 @@ class CompilerArgs(list): # Only UNIX shared libraries require this. Others have a fixed extension. dedup1_regex = re.compile(r'([\/\\]|\A)lib.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$') dedup1_args = ('-c', '-S', '-E', '-pipe', '-pthread') + # In generate_link() we add external libs without de-dup, but we must + # *always* de-dup these because they're special arguments to the linker + always_dedup_args = tuple('-l' + lib for lib in unixy_compiler_internal_libs) compiler = None def _check_args(self, args): @@ -793,7 +799,7 @@ class CompilerArgs(list): normal_flags = [] lflags = [] for i in iterable: - if i.startswith('-l') or i.startswith('-L'): + if i not in self.always_dedup_args and (i.startswith('-l') or i.startswith('-L')): lflags.append(i) else: normal_flags.append(i) diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 3967dc5..57a6a96 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -1,4 +1,4 @@ -# Copyright 2013-2017 The Meson development team +# Copyright 2013-2019 The Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import os import re from .. import mesonlib -from ..mesonlib import version_compare, stringlistify, extract_as_list +from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice from .base import ( DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency, strip_system_libdirs, ConfigToolDependency, @@ -203,30 +203,40 @@ class LLVMDependency(ConfigToolDependency): LLVM uses a special tool, llvm-config, which has arguments for getting c args, cxx args, and ldargs as well as version. """ - - # Ordered list of llvm-config binaries to try. Start with base, then try - # newest back to oldest (3.5 is arbitrary), and finally the devel version. - # Please note that llvm-config-6.0 is a development snapshot and it should - # not be moved to the beginning of the list. - tools = [ - 'llvm-config', # base - 'llvm-config-8', 'llvm-config80', - 'llvm-config-7', 'llvm-config70', - 'llvm-config-6.0', 'llvm-config60', - 'llvm-config-5.0', 'llvm-config50', - 'llvm-config-4.0', 'llvm-config40', - 'llvm-config-3.9', 'llvm-config39', - 'llvm-config-3.8', 'llvm-config38', - 'llvm-config-3.7', 'llvm-config37', - 'llvm-config-3.6', 'llvm-config36', - 'llvm-config-3.5', 'llvm-config35', - 'llvm-config-9', # Debian development snapshot - 'llvm-config-devel', # FreeBSD development snapshot - ] tool_name = 'llvm-config' __cpp_blacklist = {'-DNDEBUG'} def __init__(self, environment, kwargs): + # Ordered list of llvm-config binaries to try. Start with base, then try + # newest back to oldest (3.5 is arbitrary), and finally the devel version. + # Please note that llvm-config-6.0 is a development snapshot and it should + # not be moved to the beginning of the list. + self.tools = [ + 'llvm-config', # base + 'llvm-config-8', 'llvm-config80', + 'llvm-config-7', 'llvm-config70', + 'llvm-config-6.0', 'llvm-config60', + 'llvm-config-5.0', 'llvm-config50', + 'llvm-config-4.0', 'llvm-config40', + 'llvm-config-3.9', 'llvm-config39', + 'llvm-config-3.8', 'llvm-config38', + 'llvm-config-3.7', 'llvm-config37', + 'llvm-config-3.6', 'llvm-config36', + 'llvm-config-3.5', 'llvm-config35', + 'llvm-config-9', # Debian development snapshot + 'llvm-config-devel', # FreeBSD development snapshot + ] + + # Fedora starting with Fedora 30 adds a suffix of the number + # of bits in the isa that llvm targets, for example, on x86_64 + # and aarch64 the name will be llvm-config-64, on x86 and arm + # it will be llvm-config-32. + m = MachineChoice.BUILD if environment.is_cross_build() and kwargs.get('native', True) else MachineChoice.HOST + if environment.machines[m].is_64_bit: + self.tools.append('llvm-config-64') + else: + self.tools.append('llvm-config-32') + # It's necessary for LLVM <= 3.8 to use the C++ linker. For 3.9 and 4.0 # the C linker works fine if only using the C API. super().__init__('LLVM', environment, 'cpp', kwargs) diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index f2510c1..609899c 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -55,6 +55,18 @@ known_cpu_families = ( 'x86_64' ) +# It would feel more natural to call this "64_BIT_CPU_FAMILES", but +# python identifiers cannot start with numbers +CPU_FAMILES_64_BIT = [ + 'aarch64', + 'ia64', + 'mips64', + 'ppc64', + 'riscv64', + 'sparc64', + 'x86_64', +] + class MesonConfigFile: @classmethod def parse_datafile(cls, filename): @@ -150,6 +162,7 @@ class MachineInfo: self.cpu_family = cpu_family self.cpu = cpu self.endian = endian + self.is_64_bit = cpu_family in CPU_FAMILES_64_BIT def __eq__(self, other): if self.__class__ is not other.__class__: diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py index 7b00178..4b37069 100644 --- a/mesonbuild/modules/i18n.py +++ b/mesonbuild/modules/i18n.py @@ -64,8 +64,7 @@ class I18nModule(ExtensionModule): return [path.join(src_dir, d) for d in dirs] @FeatureNew('i18n.merge_file', '0.37.0') - @permittedKwargs({'languages', 'data_dirs', 'preset', 'args', 'po_dir', 'type', - 'input', 'output', 'install', 'install_dir'}) + @permittedKwargs(build.CustomTarget.known_kwargs | {'data_dirs', 'po_dir', 'type'}) def merge_file(self, state, args, kwargs): podir = kwargs.pop('po_dir', None) if not podir: diff --git a/run_unittests.py b/run_unittests.py index 3f1a290..0b2164f 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -3893,7 +3893,7 @@ class WindowsTests(BasePlatformTests): if cc.get_argument_syntax() != 'msvc': raise unittest.SkipTest('Not using MSVC') # To force people to update this test, and also test - self.assertEqual(set(cc.ignore_libs), {'c', 'm', 'pthread', 'dl', 'rt'}) + self.assertEqual(set(cc.ignore_libs), {'c', 'm', 'pthread', 'dl', 'rt', 'execinfo'}) for l in cc.ignore_libs: self.assertEqual(cc.find_library(l, env, []), []) @@ -5043,6 +5043,19 @@ endian = 'little' max_count = max(max_count, line.count(search_term)) self.assertEqual(max_count, 1, 'Export dynamic incorrectly deduplicated.') + def test_compiler_libs_static_dedup(self): + testdir = os.path.join(self.unit_test_dir, '55 dedup compiler libs') + self.init(testdir) + build_ninja = os.path.join(self.builddir, 'build.ninja') + with open(build_ninja, 'r', encoding='utf-8') as f: + lines = f.readlines() + for lib in ('-ldl', '-lm', '-lc', '-lrt'): + for line in lines: + if lib not in line: + continue + # Assert that + self.assertEqual(len(line.split(lib)), 2, msg=(lib, line)) + def should_run_cross_arm_tests(): return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm') diff --git a/test cases/unit/55 dedup compiler libs/app/app.c b/test cases/unit/55 dedup compiler libs/app/app.c new file mode 100644 index 0000000..4e215b3 --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/app/app.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <liba.h> +#include <libb.h> + +int +main(void) +{ + printf("start value = %d\n", liba_get()); + liba_add(2); + libb_mul(5); + printf("end value = %d\n", liba_get()); + return 0; +} diff --git a/test cases/unit/55 dedup compiler libs/app/meson.build b/test cases/unit/55 dedup compiler libs/app/meson.build new file mode 100644 index 0000000..82ac306 --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/app/meson.build @@ -0,0 +1,2 @@ +executable('app', 'app.c', + dependencies: [liba_dep, libb_dep]) diff --git a/test cases/unit/55 dedup compiler libs/liba/liba.c b/test cases/unit/55 dedup compiler libs/liba/liba.c new file mode 100644 index 0000000..962d47f --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/liba/liba.c @@ -0,0 +1,18 @@ +#include "liba.h" + +static int val; + +void liba_add(int x) +{ + val += x; +} + +void liba_sub(int x) +{ + val -= x; +} + +int liba_get(void) +{ + return val; +} diff --git a/test cases/unit/55 dedup compiler libs/liba/liba.h b/test cases/unit/55 dedup compiler libs/liba/liba.h new file mode 100644 index 0000000..a980cdc --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/liba/liba.h @@ -0,0 +1,8 @@ +#ifndef LIBA_H_ +#define LIBA_H_ + +void liba_add(int x); +void liba_sub(int x); +int liba_get(void); + +#endif diff --git a/test cases/unit/55 dedup compiler libs/liba/meson.build b/test cases/unit/55 dedup compiler libs/liba/meson.build new file mode 100644 index 0000000..eccfa46 --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/liba/meson.build @@ -0,0 +1,8 @@ +deps = [dependency('threads'), cc.find_library('dl'), cc.find_library('m')] + +liba = library('a', 'liba.c', + dependencies: deps) + +liba_dep = declare_dependency(link_with: liba, + include_directories: include_directories('.'), + dependencies: deps) diff --git a/test cases/unit/55 dedup compiler libs/libb/libb.c b/test cases/unit/55 dedup compiler libs/libb/libb.c new file mode 100644 index 0000000..3720868 --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/libb/libb.c @@ -0,0 +1,7 @@ +#include <liba.h> +#include "libb.h" + +void libb_mul(int x) +{ + liba_add(liba_get() * (x - 1)); +} diff --git a/test cases/unit/55 dedup compiler libs/libb/libb.h b/test cases/unit/55 dedup compiler libs/libb/libb.h new file mode 100644 index 0000000..2e4ddd0 --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/libb/libb.h @@ -0,0 +1,6 @@ +#ifndef _LIBB_H_ +#define _LIBB_H_ + +void libb_mul(int x); + +#endif diff --git a/test cases/unit/55 dedup compiler libs/libb/meson.build b/test cases/unit/55 dedup compiler libs/libb/meson.build new file mode 100644 index 0000000..d59206f --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/libb/meson.build @@ -0,0 +1,6 @@ +libb = library('b', 'libb.c', + dependencies: liba_dep) + +libb_dep = declare_dependency(link_with: libb, + include_directories: include_directories('.'), + dependencies: liba_dep) diff --git a/test cases/unit/55 dedup compiler libs/meson.build b/test cases/unit/55 dedup compiler libs/meson.build new file mode 100644 index 0000000..fad0ed5 --- /dev/null +++ b/test cases/unit/55 dedup compiler libs/meson.build @@ -0,0 +1,7 @@ +project('temp', 'c') + +cc = meson.get_compiler('c') + +subdir('liba') +subdir('libb') +subdir('app') |