From 7140afc0a86f2aae0689617fca985ef209a7c097 Mon Sep 17 00:00:00 2001 From: Vasu Penugonda <34339497+sompen@users.noreply.github.com> Date: Thu, 21 Jun 2018 03:25:39 +0530 Subject: [PATCH] Added ARMCLANG compiler support for C/C++ (#3717) --- cross/armclang.txt | 20 ++++++ docs/markdown/Reference-tables.md | 1 + docs/markdown/snippets/armclang-cross.md | 25 ++++++++ mesonbuild/compilers/__init__.py | 6 +- mesonbuild/compilers/c.py | 29 +++++++++ mesonbuild/compilers/compilers.py | 80 ++++++++++++++++++++++++ mesonbuild/compilers/cpp.py | 29 +++++++++ mesonbuild/environment.py | 18 ++++++ 8 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 cross/armclang.txt create mode 100644 docs/markdown/snippets/armclang-cross.md diff --git a/cross/armclang.txt b/cross/armclang.txt new file mode 100644 index 000000000000..955b7ef5710f --- /dev/null +++ b/cross/armclang.txt @@ -0,0 +1,20 @@ +# This file assumes that path to the arm compiler toolchain is added +# to the environment(PATH) variable, so that Meson can find +# the armclang, armlink and armar while building. +[binaries] +c = 'armclang' +cpp = 'armclang' +ar = 'armar' +strip = 'armar' + +[properties] +# The '--target', '-mcpu' options with the appropriate values should be mentioned +# to cross compile c/c++ code with armclang. +c_args = ['--target=arm-arm-none-eabi', '-mcpu=cortex-m0plus'] +cpp_args = ['--target=arm-arm-none-eabi', '-mcpu=cortex-m0plus'] + +[host_machine] +system = 'bare metal' # Update with your system name - bare metal/OS. +cpu_family = 'arm' +cpu = 'Cortex-M0+' +endian = 'little' diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md index 571866f1bd6f..b1a7bf6aa9af 100644 --- a/docs/markdown/Reference-tables.md +++ b/docs/markdown/Reference-tables.md @@ -23,6 +23,7 @@ These are return values of the `get_id` method in a compiler object. | nagfor | The NAG Fortran compiler | | lcc | Elbrus C/C++/Fortran Compiler | | arm | ARM compiler | +| armclang | ARMCLANG compiler | ## Script environment variables diff --git a/docs/markdown/snippets/armclang-cross.md b/docs/markdown/snippets/armclang-cross.md new file mode 100644 index 000000000000..f78787638d34 --- /dev/null +++ b/docs/markdown/snippets/armclang-cross.md @@ -0,0 +1,25 @@ +## ARM compiler(version 6) for C and CPP + +Cross-compilation is now supported for ARM targets using ARM compiler version 6 - ARMCLANG. +The required ARMCLANG compiler options for building a shareable library are not included in the +current Meson implementation for ARMCLANG support, so it can not build shareable libraries. +This current Meson implementation for ARMCLANG support can not build assembly files with +arm syntax(we need to use armasm instead of ARMCLANG for the .s files with this syntax) +and only supports gnu syntax. +The default extension of the executable output is .axf. +The environment path should be set properly for the ARM compiler executables. +The '--target', '-mcpu' options with the appropriate values should be mentioned +in the cross file as shown in the snippet below. + +``` +[properties] +c_args = ['--target=arm-arm-none-eabi', '-mcpu=cortex-m0plus'] +cpp_args = ['--target=arm-arm-none-eabi', '-mcpu=cortex-m0plus'] + +``` + +Note: +- The current changes are tested on Windows only. +- PIC support is not enabled by default for ARM, + if users want to use it, they need to add the required arguments + explicitly from cross-file(c_args/c++_args) or some other way. diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index 217357b8e120..9070a9fedd96 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -126,8 +126,9 @@ IntelCompiler, ) from .c import ( - ArmCCompiler, CCompiler, + ArmCCompiler, + ArmclangCCompiler, ClangCCompiler, GnuCCompiler, ElbrusCCompiler, @@ -135,8 +136,9 @@ VisualStudioCCompiler, ) from .cpp import ( - ArmCPPCompiler, CPPCompiler, + ArmCPPCompiler, + ArmclangCPPCompiler, ClangCPPCompiler, GnuCPPCompiler, ElbrusCPPCompiler, diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index cd3aad137f21..b63dce40ace6 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -32,6 +32,7 @@ vs32_instruction_set_args, vs64_instruction_set_args, ArmCompiler, + ArmclangCompiler, ClangCompiler, Compiler, CompilerArgs, @@ -979,6 +980,34 @@ def get_linker_always_args(self): return basic +class ArmclangCCompiler(ArmclangCompiler, CCompiler): + def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs) + ArmclangCompiler.__init__(self) + default_warn_args = ['-Wall', '-Winvalid-pch'] + self.warn_args = {'1': default_warn_args, + '2': default_warn_args + ['-Wextra'], + '3': default_warn_args + ['-Wextra', '-Wpedantic']} + + def get_options(self): + opts = CCompiler.get_options(self) + opts.update({'c_std': coredata.UserComboOption('c_std', 'C language standard to use', + ['none', 'c90', 'c99', 'c11', + 'gnu90', 'gnu99', 'gnu11'], + 'none')}) + return opts + + def get_option_compile_args(self, options): + args = [] + std = options['c_std'] + if std.value != 'none': + args.append('-std=' + std.value) + return args + + def get_option_link_args(self, options): + return [] + + class GnuCCompiler(GnuCompiler, CCompiler): def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None, **kwargs): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 45caf55c36c9..21aab11635a9 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -131,6 +131,12 @@ def is_library(fname): 'release': ['-O3'], 'minsize': ['-Os', '-g']} +armclang_buildtype_args = {'plain': [], + 'debug': ['-O0', '-g'], + 'debugoptimized': ['-O1', '-g'], + 'release': ['-Os'], + 'minsize': ['-Oz']} + arm_buildtype_args = {'plain': [], 'debug': ['-O0', '--debug'], 'debugoptimized': ['-O1', '--debug'], @@ -1414,6 +1420,80 @@ def openmp_flags(self): return [] +class ArmclangCompiler: + def __init__(self): + if not self.is_cross: + raise EnvironmentException('armclang supports only cross-compilation.') + # Check whether 'armlink.exe' is available in path + self.linker_exe = 'armlink.exe' + args = '--vsn' + try: + p, stdo, stderr = Popen_safe(self.linker_exe, args) + except OSError as e: + err_msg = 'Unknown linker\nRunning "{0}" gave \n"{1}"'.format(' '.join([self.linker_exe] + [args]), e) + raise EnvironmentException(err_msg) + # Verify the armlink version + ver_str = re.search('.*Component.*', stdo) + if ver_str: + ver_str = ver_str.group(0) + else: + EnvironmentException('armlink version string not found') + # Using the regular expression from environment.search_version, + # which is used for searching compiler version + version_regex = '(?