Skip to content
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

cmake: Add option for exporting build metadata to Make #22020

Merged
merged 1 commit into from
Jan 23, 2020

Conversation

SebastianBoe
Copy link
Collaborator

Add an opt-in feature that will generate a Makefile with build
variables like CC, and KBUILD_CFLAGS for consumption by third-party
Make-based build systems.

This emulates the 'outputexports' target that KBuild supported and is
supported for the same reasons that KBuild supported it. Easier
integration with third-party build systems.

This fixes #4917

@SebastianBoe
Copy link
Collaborator Author

An example of a makefile being generated:

sebo@sebo-nix:~/ncs/zephyr/samples/hello_world$ cat outdir/zephyr/Makefile.exports.C
cat outdir/zephyr/Makefile.exports.C

CC = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
CXX = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-g++
OBJCOPY = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-objcopy
OBJDUMP = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-objdump
AS = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-as
AR = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-ar
NM = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-nm
GDB = /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb
KBUILD_CFLAGS = "-I/home/sebo/ncs/zephyr/include -I/home/sebo/ncs/zephyr/include/drivers -I/home/sebo/ncs/zephyr/samples/hello_world/outdir/zephyr/include/generated -I/home/sebo/ncs/zephyr/soc/arm/nordic_nrf/nrf52 -I/home/sebo/ncs/zephyr/lib/libc/minimal/include -I/home/sebo/ncs/zephyr/ext/hal/cmsis/Core/Include -I/home/sebo/ncs/modules/hal/nordic/nrfx -I/home/sebo/ncs/modules/hal/nordic/nrfx/drivers/include -I/home/sebo/ncs/modules/hal/nordic/nrfx/mdk -I/home/sebo/ncs/modules/hal/nordic/. -I/home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/include -I/home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/include-fixed -isystem /home/sebo/ncs/zephyr/lib/libc/minimal/include -isystem /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/include -isystem /home/sebo/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/include-fixed -DKERNEL -D__ZEPHYR__=1 -D_FORTIFY_SOURCE=2 -DBUILD_VERSION=zephyr-v2.1.0-635-g5a6276e04e25 -D__PROGRAM_START -DNRF52832_XXAA -Os -imacros/home/sebo/ncs/zephyr/samples/hello_world/outdir/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -mthumb -mcpu=cortex-m4 -imacros/home/sebo/ncs/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/sebo/ncs/zephyr/samples/hello_world=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/sebo/ncs/zephyr=ZEPHYR_BASE -ffunction-sections -fdata-sections -mabi=aapcs -march=armv7e-m -std=c99 -nostdinc"

@SebastianBoe
Copy link
Collaborator Author

@pfalcon : I need help with understanding which variables would be needed to be present in the Makefile and what they should contain for this feature to be able to resolve #4917

@SebastianBoe SebastianBoe added area: Build System Feature A planned feature with a milestone labels Jan 17, 2020
@zephyrbot
Copy link
Collaborator

zephyrbot commented Jan 17, 2020

All checks are passing now.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@pfalcon
Copy link
Contributor

pfalcon commented Jan 17, 2020

@SebastianBoe: I much appreciate your working on this, I'll look into this soon.

@pfalcon
Copy link
Contributor

pfalcon commented Jan 17, 2020

Ok, this looks pretty good. Note that in my workarounds I used CMake's add_custom_target, but if you see this as the better way, to have a Kconfig option, and then automagically generate these export files on cmake invocation, no further questions to me.

So, I was able to put this to work, and this indeed simplifies integration files on 3rd-party app side noticeably.

Looking forward to fixes suggested in the comment above, thanks!

@SebastianBoe
Copy link
Collaborator Author

There were some issues with how CMake reads out the build metadata when I tried to create a target, so it will have to be an automatically generated file.

Thank you for the feedback @pfalcon , it is now addressed.

Add an opt-in feature that will generate a Makefile with build
variables like CC, and KBUILD_CFLAGS for consumption by third-party
Make-based build systems.

This emulates the 'outputexports' target that KBuild supported and is
supported for the same reasons that KBuild supported it. Easier
integration with third-party build systems.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look great, thanks!

@pfalcon
Copy link
Contributor

pfalcon commented Jan 21, 2020

@SebastianBoe, thanks, works great, approved. For reference, example of simplification to 3rd-party build system is here: https://github.com/pfalcon/pycopy/compare/zephyr-new-Makefile.exports .

But this change is one half of the story. The 2nd half is examplified by this line: https://github.com/pfalcon/pycopy/compare/zephyr-new-Makefile.exports#diff-35d7a1c676537f5e7dfb8d9ae6926033L111 :

make -C outdir/$(OUTDIR_PREFIX) syscall_list_h_target kobj_types_h_target

This list is quote adhoc and changes over time, causing breakage (which is expected, as those are Zephyr's internal targets). What I would be looking is the analog of the following make rule:

genheaders: syscall_list_h_target kobj_types_h_target

Where "genheaders" (or more suitable name, per your likes) would be an official public build system target, causing any autogenerated to be generated (so, after that target, it would be possible to compile an app-level source code featuring #include <zephyr.h> or any other public Zephyr header, and this include won't complain that some of (autogenerated) Zephyr headers are missing.

I assume that this change would be only simpler than this PR.

And the main point of these changes isn't even technical, but "organizational" - to treas these new facilities (Makefile.exports.* generation and "genheaders" target) as parts of "external public interface" of Zephyr build system. So for example, of you (as the maintainer of the build system) do refactors of it, to keep in mind that their functioning/behavior should be preserved. Likewise, if you review changes of other folks to the build system, to consider this point to. And if something if overlooked (we're all humans), leading to regression, then such reports to be produced with a due priority to recover the functionality.

I from my side would be glad to look into adding regression tests for this functionality into Zephyr tree (currently, this functionality is used in JerryScript/MicroPython Zephyr ports, for which we run CI on our (Linaro's) side, so I would see any regressions soon. To run regression builds for this functionality as part of Zephyr CI, there's a kind of "organizational" issue of building samples using non-CMake top-level build system).

Thanks again!

@nashif nashif merged commit d3a8fd4 into zephyrproject-rtos:master Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: Kconfig Feature A planned feature with a milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reintroduce generic "outputexports" target after CMake migration
4 participants