mesonbuild / meson

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

Feature Request: make cross-file can include another cross-file #12013

Open ZZH-Finalize opened 1 year ago

ZZH-Finalize commented 1 year ago

Currently, I can pass multiple cross-files to meson and this will merge their content, but there is a problem which is this will cause the command to be very long, and a lot of these cross-files are the same, only one of them needs to be changed.

what I want like this:

arm_toolchain.ini:
[constants]
toolchain_prefix  = 'arm-none-eabi-'
[binaries]
c = toolchain_prefix + 'gcc'

stm32f10x.ini
[include]
arm_toolchain.ini
[host_machine]
system     = 'none'
cpu_family = 'arm'
cpu        = 'cortex-m3'
endian     = 'little'
[properties]
flash_base = '0x08000000'
ram_base = '0x20000000'

stm32f103c8t6.ini
[include]
stm32f10x.ini
[properties]
flash_size = '64K'
ram_size = '20K'

stm32f103zet6.ini:
[include]
stm32f10x.ini
[properties]
flash_size = '512K'
ram_size = '64K'

Then, use: meson setup builddir --cross-file stm32f103c8t6.ini or: meson setup builddir --cross-file stm32f103zet6.ini

instead of:

meson setup builddir --cross-file toolchain.ini --cross-file stm32f10x.ini --cross-file stm32f103c8t6.ini meson setup builddir --cross-file toolchain.ini --cross-file stm32f10x.ini --cross-file stm32f103zet6.ini

xclaesse commented 1 year ago

I would love to have something like this as well. We currently only support multiple cross files because python configparser support it, but it's not really what we want most of the time.

That being said, defining exactly what [include] does could be tricky, and that moves us even further to a "standard" ini file format. Maybe that would be time to just move away completely from the ini format (and for .wrap files too) and make our own format based on Meson syntax. Something like:

stm32f103zet6.machine:

# This interprets common.machine using a global variable namespace, just like subdir() in meson.build files
include('common.machine')

binaries(
  c: path / 'gcc',
  cpp: path / 'g++',
  ...
)

properties(
  flash_size: '512K',
  ...
)

common.machine:

path = '/my/toolchain'

Just thinking out loud....

ZZH-Finalize commented 1 year ago

As I know, Linux kernel code has the same problem on "device-tree" code, but they use GCC pre-processor to expand the #include "xxx.dts" code to solve this problem.

In my opinion, multiple cross-files are actually the same logic as the "[include]", so can we just add something like a "pre-processor"? This component just reads the input cross-file and finds the [include] section, then it creates a cross-file queue, adds every included file to the head of the queue, then it passes this queue to the current code. That is just like using some code to expand the include chain to a multiple cross-file, and don't need to change meson cross-file logic.

As you say, I think using Meson syntax is a great solution, and whatever which solution is accepted, the final result is similar.

glingy commented 1 year ago

Bump. This would be very useful because command line args get really long and hard to track dependencies between cross files