You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Bazel的configure_make规则中如何输出.la文件?

在Bazel的configure_make规则中包含.la文件的解决方案

问题场景

我在编写构建xmlsec1的configure_make规则时,尝试将.la文件纳入构建产物,配置如下:

configure_make(
    name="xmlsec1",
    lib_name="xmlsec1",
    lib_source=":all_srcs",
    configure_command="configure",
    configure_in_place=True,
    deps=["@openssl"],
    out_binaries=["xmlsec1"],
    out_shared_libs=[
        "libxmlsec1.so",
        "libxmlsec1-openssl.so",
        "libxmlsec1-openssl.la",
    ],
    targets=["install"],
)

遇到的错误:

  • 同时列出.so和.la文件时,报错 Can not have libraries with the same name in the same category
  • 单独列出.la文件时,报错 Error in create_library_to_link: 'libxmlsec1-openssl.la' does not have any of the allowed extensions .so, .dylib or .dll

解决方法

out_shared_libs 是专门用于识别共享库的字段,不适合存放.la这类libtool辅助文件,可通过以下方式处理:

1. 直接使用out_data字段(规则支持时优先用)

部分版本的configure_make规则扩展了out_data字段,允许直接指定单个非库、非二进制文件,修改配置如下:

configure_make(
    name="xmlsec1",
    lib_name="xmlsec1",
    lib_source=":all_srcs",
    configure_command="configure",
    configure_in_place=True,
    deps=["@openssl"],
    out_binaries=["xmlsec1"],
    out_shared_libs=[
        "libxmlsec1.so",
        "libxmlsec1-openssl.so",
    ],
    out_data=["libxmlsec1-openssl.la"],
    targets=["install"],
)

2. 用filegroup提取产物文件

如果out_data不可用,先正常构建生成所有产物,再通过filegroup单独提取.la文件:

  • 第一步:调整configure_make配置,确保构建过程生成.la文件(不在out_shared_libs中添加)
    configure_make(
        name="xmlsec1_build",
        lib_name="xmlsec1",
        lib_source=":all_srcs",
        configure_command="configure",
        configure_in_place=True,
        deps=["@openssl"],
        out_binaries=["xmlsec1"],
        out_shared_libs=[
            "libxmlsec1.so",
            "libxmlsec1-openssl.so",
        ],
        targets=["install"],
        # 确保configure启用共享库生成,保证.la文件被产出
        configure_args=["--enable-shared"],
    )
    
  • 第二步:通过filegroup聚合目标文件
    filegroup(
        name="xmlsec1",
        srcs=[
            ":xmlsec1_build",
            "@xmlsec1_build//:libxmlsec1-openssl.la",
        ],
        visibility=["//visibility:public"],
    )
    

3. 结合out_data_dirs与glob筛选文件

如果必须使用out_data_dirs,可指定安装目录后,用glob筛选出需要的.la文件:

configure_make(
    name="xmlsec1",
    lib_name="xmlsec1",
    lib_source=":all_srcs",
    configure_command="configure",
    configure_in_place=True,
    deps=["@openssl"],
    out_binaries=["xmlsec1"],
    out_shared_libs=[
        "libxmlsec1.so",
        "libxmlsec1-openssl.so",
    ],
    out_data_dirs=["lib"],
    targets=["install"],
)

filegroup(
    name="xmlsec1_la_files",
    srcs=[":xmlsec1"],
    visibility=["//visibility:public"],
    glob=["lib/*.la"],
)

内容的提问来源于stack exchange,提问作者frans

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 22:55:56