-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Support TI Code Generation Tools #10182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, I was not able to follow all of the code, but this looks like an approach we can work with. |
Thanks @SebastianBoe . I take it as a go for the current direction. I'll re-submit when I completed the work. |
@SebastianBoe I think it would be cleaner and simpler to handle this within Cmake: Whenever a literal GCC-specific compiler flag is used, abstract it away into a cmake macro (or function). E.g. "-g" becomes something like get_cc_debug_flags() which becomes an API each toolchain has to implement. @yashi So you translate the command line flags, but do you expect to also modify the C files in-place? For linker specifics as you mentioned on the mailing list? |
I disagree. Users will be more familiar with GCC flags than our CMake compiler flag API and will therefore find it easier to read and write build scripts with the solution proposed here. |
Note that we do employ the "wrapper CMake API" approach for some flags, such as -g. This has been wrapped with the CMake variable OPTIMIZE_FOR_DEBUG_FLAG. But this approach does not work well for the full GCC CLI. |
@mped-oticon I haven't encountered any C file to modify. I've posted my diff here. https://gist.github.com/yashi/d200601d68cd3d9948600d99aee5ef1f There are many debug / test code in it or missing files but hope you feel what I'm doing. |
Having compiler option translator / compiler driver is to add yet another layer to our already complex build system, IMO. With cmake, however, it is easier to add arbitrary compile options in sub-directories and we already have some of them. Having if-gcc-elif in all of those cmake is burden to developers who don't know all compilers we will support. The current compiler driver is designed to be executed at actual compile time but is it possible / good idea to translate compiler option at cmake time? If it can be done |
This is not possible because the compiler options are not known until after "cmake time" (Configure-time). For instance, if generator expression are used; zephyr_compile_options($<$BOOL:${ENABLE_SOME_FLAG}:--some-flag>) |
One more thing. |
How about moving all the "zephyr_compile_options" and friends (ld_options, ...) from the root CMakeLists.txt to the specific toolchain cmake files? Those are included after kconfig so they should have access to CONFIG_* variables as well as most cmake variables. It shouldn't be rocket science to move the logic from the root CMakeLists.txt to -for example- gcc.cmake and others. That would also simplify the root CMakeLists.txt. As for the few additional flags defined in specific elsewhere in arch or soc, they can stay there and use the ZEPHYR_TOOLCHAIN_VARIANT variable to select appropriate flags if they can be built with more than one toolchain. |
This wouldn't scale. Subsystem-specific information would pollute (what should be subsystem-independent) toolchain portability files. The condition for when a zephyr_[library_]compiler_options() invocation occurs can be arbitrarily complex, for instance for subsys/bluetooth/controller/CMakeLists.txt:63 it would be when (CONFIG_BT && CONFIG_BT_CTLR && CONFIG_BT_LL_SW && CONFIG_BT_CTLR_FAST_ENC). Copying this dependency from a subsystem (where it belongs) to a portability file (where it is out-of-place) would cause maintainability issues. In the proposed solution, portability issues are dealt with by portability scripts, and subsystems are portable across non-gcc toolchains without being aware of any portability layer. This is the solution that separates portability issues and specific subsystems the best and will be the easiest to maintain. |
That is why the intent should be expressed as a cmake macro/function. That takes care of the general case. If a subsystem then really has a non-generalizable need, then that subsystem is allowed to branch on Your example of
Would it really be so bad to replace it with:
? That way we keep the logic in Cmake and not [some ad-hoc python tool + 1 more build step]. More reasons:
|
This may be an issue worthy of TSC attention. @nashif Do you have input? |
There is a misunderstading, I am not saying we should never use a What is designated as a portable and non-portable flag is up for zephyr_library_compile_options_ifdef( An example of what is today considered a 'portable' flag would be
No, it's not, but it's more standardized than any wrapper API
If there are any flags that can not be dealt with by the compiler
I disagree, using an existing CLI makes it easier for users to
I disagree, portability can be achieved without intent-based
Non-gcc compatible out-of-tree toolchains will need to develop
I don't see that this scheme is doomed to be fragile, and have |
@mped-oticon I agree that this will probably need discussion at the TSC level. Can you please send an email to the TSC mailing list to raise awareness and to request it being included in the next TSC meeting? |
will put this on the agenda for next week. my point of view on this: Zephyr should support toolchains/compiler without any bias to one or another toolchain/compiler. We do need a portable way for supporting any compiler, wether in-tree or out-of-tree the same way. GCC is getting all the benefits because it was there first, but thats about it, once we have more compiler supported, this bias hopefully will go away. |
My point of view is that we should bias towards the GCC CLI. It is familiar and well documented. The alternative to biasing against a CLI is to disallow direct usage of compiler flags, which would make the build system difficult to read and write. |
Or you could replace the literal compiler flag(s) with a better-named, English, intent-based name :) |
I don't know, how would that work? This looks unmaintainable, and it is only changing 4 out of dozens of flags; |
Those variables could contain multiple flags grouped by intent, such as desired warning levels or readable assembly, ... It would leave us with a dozen variables such as: COMPILER_FLAGS_MAIN fx: Macros/functions could also be used. |
I think your diff looks very readable: An English description tied to what flag is needed to achieve that in GCC. I'd argue if you increase readability, you increase maintainability. Then we can discuss implementation details;
Finally, note that this does not only apply to the compiler but also the linker. |
Zephyr has two API's for adding flags. *_cc_option one is used to express that the flag should be used if the toolchain supports it. And the other that the flag is a requirement (So optional or mandatory flag). We need to retain this ability somehow ... silently dropping flags when the toolchain doesn't support it won't do. |
cc: @GAnthony as a TI guy. |
@tejlmand please close if you think this is not applicable anymore |
@carlescufi yep, will try to go through current status to see if more needs to be done. |
@yashi I believe the toolchain / compiler infrastructure used in Zephyr today provides a mechanism that allows you to implement CGT compiler support. The template for compiler flags can be seen here: basically a given set of properties are defined, and then the compiler CMake files populates those properties with their corresponding arguments. An example on how gcc populates those properties can be found here: If a compiler has many options in common with gcc, then it may inherit GCC's values and overwrite just those which are different, for example as clang does here: zephyr/cmake/compiler/clang/compiler_flags.cmake Lines 2 to 4 in 0badef8
Other compilers, such as ARC MWDT, may create its own compiler_flags file: I believe this infrastructure also support the use-case in this issue. @yashi please take a look, and close this issue if you believe it meets your needs. |
@tejlmand It looks great! Unfortunately I don't currently use CGT so it might be little while to submit CGT support. I'll close this issue for now and reopen it when I need it. I hope someone beat me to it. |
Currently Zephyr doesn't support TI's CGT (Code Generation Tools). TI's CCS (Code Composer Studio) uses CGT as the compiler.
I'd like to support it. To do that, I've discussed with @SebastianBoe (sebo) on IRC channel how we should support non-GCC compilers. sebo suggested to create a compiler wrapper or a compiler driver as he called.
Hi @SebastianBoe ,
As we talked on the irc channel, I've coded up a preliminary version of compiler driver (aka. compiler option translator). Before digging down deep, would you mind to review whether I'm going the right direction or not?
Thanks,
compiler-driver-cgt.py.gz
or
https://gist.github.com/yashi/f3fbf2fc2062486f60211296324c5f2b
The text was updated successfully, but these errors were encountered: