【问题标题】:How to make run_target depend on a previous custom target in Meson build system?如何使 run_target 依赖于 Meson 构建系统中以前的自定义目标?
【发布时间】:2023-02-01 05:40:33
【问题描述】:

我正在使用 Meson 构建系统,我有一个自定义目标 cargo_build,它生成一个名为 sw_bin 的二进制文件。我还有一个运行sw_bin 文件的run_target

我想让 run_target 依赖于 cargo_build 目标,以便 run_target 仅在 cargo_build 目标完成后执行。

请注意,run_target 不应像cargo_build 那样始终运行,但只有在我明确执行ninja -v -C "${MESON_BUILD_DIR}" run 时才会运行。

这是我当前的代码:

cargo_build = custom_target(
  'cargo-build',
  build_by_default: true,
  build_always_stale: true,
  output: meson.project_name(),
  console: true,
  install: true,
  install_dir: get_option('bindir'),
  command: [
    'env',
    cargo_env,
    cargo,
    'build',
    cargo_options,
    '&&',
    'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
  ]
)

run_target(
  'run',
  command: [sw_bin],
  depends: cargo_build,
)

我试过在run_target 中使用depends 关键字,但它似乎不起作用。 run_target 仍在检查 sw_bin 文件是否存在,即使在正常运行构建时也没有找到它:

src/meson.build:67:0: ERROR: Program 'build/output/install/bin/rwr' not found or not executable

如果我删除/评论 run_target 部分,一切正常,并生成 rwr 文件。然后我可以添加回/取消注释run_target,一切都会正常进行。 但是,如果我删除介子构建目录,我将再次收到错误。

看起来 run_target 正在检查 command 是否存在,而忽略了 depends

我正在使用介子版本 0.61.2。

如何使 run_target 依赖于 Meson 构建系统中的 cargo_build 目标?

【问题讨论】:

  • 您是否尝试过将 depends 指定为列表?喜欢depends: [cargo_build]

标签: rust ninja meson-build


【解决方案1】:

来自 meson run_target 函数文档:

  depends:
    type: list[build_tgt | custom_tgt]
    description: |
      A list of targets that this target depends on but which
      are not listed in the command array (because, for example, the
      script does file globbing internally)

所以在你的情况下

run_target(
  'run',
  command: [sw_bin],
  depends: [cargo_build],
)

【讨论】:

    最近更新 更多