mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.65k stars 1.64k forks source link

Tasking compiler support to Meson build system #11866

Open arunptm opened 1 year ago

arunptm commented 1 year ago

Please add Tasking embedded software compiler support to Meson build syste. CPU name is Tricore.

Otherwise unknown compiler error appears

Log:

Build started at 2023-06-12T12:58:06.638998
Main binary: C:\Tools\python-3.11.4-embed-amd64\python.exe
Build Options: -Dbuildtype=debugoptimized --cross-file=cross_tasking.txt
Python system: Windows
The Meson build system
Version: 1.1.1
Source dir: C:\projects\app1\Software\Appl\Make
Build dir: C:\projects\app1\Software\Appl\Make\builddir
Build type: cross build
Project name: obd2
Project version: 1.0
WARNING: Failed to activate VS environment: Could not find C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe
-----
Detecting compiler via: cctc --version
compiler returned <Popen: returncode: 1 args: ['cctc', '--version']>
compiler stdout:

compiler stderr:
TASKING VX-toolset for TriCore: control program   v4.2r2 Build 199.1.1
Copyright 2003-2013 Altium BV                     
Libraries used:
  libxml2 1.0    => ..\libexec\libxml2.dll (libxml2 1.0 Build 050.1.1)

meson.build:2:0: ERROR: Unknown compiler(s): [['cctc']]

cmd stdout:

C:\projects\app1\Software\Appl\Make>mbuild.cmd
WARNING: Unknown CPU family Tricore, please report this at https://github.com/mesonbuild/meson/issues/new
DEPRECATION: c_args in the [properties] section of the machine file is deprecated, use the [built-in options] section.
DEPRECATION: c_link_args in the [properties] section of the machine file is deprecated, use the [built-in options] section.
The Meson build system
Version: 1.1.1
Source dir: C:\projects\app1\Software\Appl\Make
Build dir: C:\projects\app1\Software\Appl\Make\builddir
Build type: cross build
Project name: obd2
Project version: 1.0
WARNING: Failed to activate VS environment: Could not find C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe

meson.build:2:0: ERROR: Unknown compiler(s): [['cctc']]

A full log can be found at C:\projects\app1\Software\Appl\Make\builddir\meson-logs\meson-log.txt
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.
Traceback (most recent call last):
  File "C:\Tools\meson-1.1.1\meson-1.1.1\meson.py", line 40, in <module>
    sys.exit(mesonmain.main())
             ^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\mesonmain.py", line 294, in main
    return run(sys.argv[1:], launcher)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\mesonmain.py", line 285, in run
    return CommandLineParser().run(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\mesonmain.py", line 196, in run
    return errorhandler(e, command)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\mesonmain.py", line 40, in errorhandler
    raise e
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\mesonmain.py", line 194, in run
    return options.run_func(options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\msetup.py", line 318, in run
    app.generate()
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\msetup.py", line 194, in generate
    self._generate(env)
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\msetup.py", line 216, in _generate
    intr = interpreter.Interpreter(b, user_defined_options=user_defined_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreter\interpreter.py", line 330, in __init__
    self.parse_project()
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreterbase\interpreterbase.py", line 134, in parse_project
    self.evaluate_codeblock(self.ast, end=1)
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreterbase\interpreterbase.py", line 190, in evaluate_codeblock
    raise e
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreterbase\interpreterbase.py", line 182, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreterbase\interpreterbase.py", line 196, in evaluate_statement
    return self.function_call(cur)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreterbase\interpreterbase.py", line 521, in function_call
    res = func(node, func_args, kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreterbase\decorators.py", line 277, in wrapper
    return f(*nargs, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreterbase\decorators.py", line 596, in wrapper
    return f(*wrapped_args, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreter\interpreter.py", line 1298, in func_project
    self.add_languages(proj_langs, True, MachineChoice.HOST)
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreter\interpreter.py", line 1452, in add_languages
    success = self.add_languages_for(args, required, for_machine)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\interpreter\interpreter.py", line 1492, in add_languages_for
    comp = compilers.detect_compiler_for(self.environment, lang, for_machine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\compilers\detect.py", line 115, in detect_compiler_for
    comp = compiler_from_language(env, lang, for_machine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\compilers\detect.py", line 112, in compiler_from_language
    return lang_map[lang](env, for_machine) if lang in lang_map else None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\compilers\detect.py", line 580, in detect_c_compiler
    return _detect_c_or_cpp_compiler(env, 'c', for_machine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\compilers\detect.py", line 576, in _detect_c_or_cpp_compiler
    _handle_exceptions(popen_exceptions, compilers)
  File "C:\Tools\meson-1.1.1\meson-1.1.1\mesonbuild\compilers\detect.py", line 157, in _handle_exceptions
    raise EnvironmentException(errmsg)
mesonbuild.utils.universal.EnvironmentException: Unknown compiler(s): [['cctc']]

C:\projects\app1\Software\Appl\Make>
tristan957 commented 1 year ago

The best person to add support is you. I am quite positive that none of us use that compiler. It shouldn't be very hard to add support for it.

arunptm commented 1 year ago

Hi, Thanks for hint. I started to add Tasking compiler support but missing some documentation means which all .py files to update. e.g linker rule need to update as below

# Rule for linking C executable.

rule C_EXECUTABLE_LINKER__ASILC_OBD_Stub_Release
  command = cmd.exe /C "$PRE_LINK && C:\Tasking\bin\cctc.exe $FLAGS $LINK_FLAGS -f $RSP_FILE -o $TARGET_FILE  && $POST_BUILD"
  description = Linking C executable $TARGET_FILE
  rspfile = $RSP_FILE
  rspfile_content = $in_newline $LINK_PATH $LINK_LIBRARIES
  restat = $RESTAT
eli-schwartz commented 1 year ago

What is $PRE_LINK here? Other than that I think this should work fine with the existing compiler model, and doesn't require editing the ninja backend.

arunptm commented 1 year ago

$PRE_LINK can be ignored, following way linking rule should be generated, before linking rsp file should be generated. I have found the py code location to update the linking rule but not able to update the format as given below

rule c_LINKER command = "cctc" $ARGS $LINK_ARGS -f $RSP_FILE -o $out description = Linking target $out rspfile = $RSP_FILE rspfile_content = $in_newline $LINK_PATH $LINK_LIBRARIES restat = $RESTAT

arunptm commented 1 year ago

I have added new compiler py file also and adapted static & dynamic rule accordingly.

gerioldman commented 1 year ago

I have implemented support for TASKING compilers on this branch: https://github.com/gerioldman/meson/tree/TaskingCCompiler but I would like to add support for the MIL linking feature of the compiler family before I create a PR. The reason I am asking before trying to implement it is because this mode of the compiler doesn't exactly conform to the "normal" compilation process. What I mean by that is, that instead of the normal: image

it is like this: image

Basically, the fronted of the compiler transpiles the C language into some proprietary intermediate language (*.mil files) first, then these files MIL files get "linked" together, and is given to the backend of the compiler where it is compiled to a single object file. The reason this is done, is to get application wide optimizations instead of file scope optimizations, pretty akin to unity builds. You can find more information here on page 210: https://www.tasking.com/support/tricore/ctc_user_guide_v6.3r1.pdf

As far as I can see, there is no way to implement this without changing the Ninja backend implementation, and I don't want to do work on something that won't be accepted. Could you give me guidance as how this could be implemented that would actually get accepted?

tristan957 commented 1 year ago

Might want to also raise awareness in the Matrix/IRC channel. I'm sure there might be some opinions there.