Bazel如何检测Windows上的MINGW位置?

发布于 2025-02-05 04:02:23 字数 836 浏览 2 评论 0 原文

我试图说服Bazel在Windows上使用MingW32工具链。没有库存工具链的定义,所以我试图自己制作。

我在 local_config_cc/build 中找到了mingw64工具链定义:

cc_toolchain_config(
    name = "msys_x64_mingw",
    cpu = "x64_windows",
    compiler = "mingw-gcc",
    ...
    tool_paths = {"ar": "f:/msys64/mingw64/bin/ar",
        "compat-ld": "f:/msys64/mingw64/bin/compat-ld",
        "cpp": "f:/msys64/mingw64/bin/cpp",
        "dwp": "f:/msys64/mingw64/bin/dwp",
        "gcc": "f:/msys64/mingw64/bin/gcc",
        "gcov": "f:/msys64/mingw64/bin/gcov",
        "ld": "f:/msys64/mingw64/bin/ld",
        "nm": "f:/msys64/mingw64/bin/nm",
        "objcopy": "f:/msys64/mingw64/bin/objcopy",
        "objdump": "f:/msys64/mingw64/bin/objdump",
        "strip": "f:/msys64/mingw64/bin/strip"},
    ...
)

但是,这些定义包含通往mingw64安装目录的硬编码路径。这些来自哪里?

I'm trying to persuade bazel to use the mingw32 toolchain on Windows. There isn't a stock toolchain definition for this, so I'm trying to make my own.

I've found the mingw64 toolchain definition in local_config_cc/BUILD:

cc_toolchain_config(
    name = "msys_x64_mingw",
    cpu = "x64_windows",
    compiler = "mingw-gcc",
    ...
    tool_paths = {"ar": "f:/msys64/mingw64/bin/ar",
        "compat-ld": "f:/msys64/mingw64/bin/compat-ld",
        "cpp": "f:/msys64/mingw64/bin/cpp",
        "dwp": "f:/msys64/mingw64/bin/dwp",
        "gcc": "f:/msys64/mingw64/bin/gcc",
        "gcov": "f:/msys64/mingw64/bin/gcov",
        "ld": "f:/msys64/mingw64/bin/ld",
        "nm": "f:/msys64/mingw64/bin/nm",
        "objcopy": "f:/msys64/mingw64/bin/objcopy",
        "objdump": "f:/msys64/mingw64/bin/objdump",
        "strip": "f:/msys64/mingw64/bin/strip"},
    ...
)

However, these contain hard-coded paths to the mingw64 installation directory. Where do these come from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖迟 2025-02-12 04:02:23

一些Bazel-Internal机制调用,从那里是正常的星号。 (它随BZLMOD的变化而变化,但在下游具有相同的效果)。该调用存储库规则,其实现函数( cc_autoconf_impl )已经开始了。它查看当前的操作系统和某些环境变量,然后调用实际生成 cc_toolchain_config Invocation的几个功能之一。在您的情况下,看起来是。这就是生成这些路径并将它们替换为模板的功能。

如果您需要一种简单的方法来更改这些路径,只需复制整个 local_config_cc repository(aka文件夹),对其进行编辑,然后 local_repository 结果。如果您也想在工作区旁边检查它,则可以使用相对路径。

如果您正在寻找更复杂的东西,则可以查看 configure_windows_toolchain 中的逻辑是否支持它。您还可以编写自己的Starlark规则(基于 configure_windows_toolchain 或完全分开),该规则会创建相似的 cc_toolchain_config 。例如,Bazel-Toolchain项目从unix_cc_toolchain_config调用cc_toolchain_config .bzl

Some Bazel-internal mechanisms call cc_configure(), and from there it's normal Starlark. (It changes with bzlmod, but has the same effects downstream). That calls the cc_autoconf repository rule, whose implementation function (cc_autoconf_impl) has the start of the logic. It looks at the current operating system and some environment variables, and then calls one of several functions that actually generate a cc_toolchain_config invocation. In your case, that looks like it's configure_windows_toolchain. That's the function that generates those paths and substitutes them into a template.

If you want an easy way to change those paths, just copy the whole local_config_cc repository (aka folder) somewhere, edit it, and point local_repository at the result. You can use a relative path if you want to check that in next to your WORKSPACE too.

If you're looking for something more sophisticated, you can see if the logic in configure_windows_toolchain supports it. You can also write your own Starlark rule (based on configure_windows_toolchain or completely separate) that creates a similar cc_toolchain_config. For example, the bazel-toolchain project calls cc_toolchain_config from unix_cc_toolchain_config.bzl.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文