Open yaoddao opened 2 months ago
You probably need to make a rule that can export a subpath, then you can use tge static_lib=“:foo”
syntax
Yep, you need it to be the default output of a target or subtarget. What kind of rule is //:ext-link
? If it's a genrule, that already has support for adding subtargets for paths in its output. If it's an http_file/archive, i'm not sure it has that support but it seems like it'd be a nice thing to add. That'd be something like:
http_archive(
name = "ext-link",
named_outs = { "liblef.a": "/opt/b28/s-5.8.003/linux_x86_64_rhel7/lib/liblef.a"}
...
)
prebuilt_cxx_libary(
static_lib = '//:ext-link[liblef.a]',
...
)
As a temporary workaround though (until http_archive supports it natively), you can also just write a rule that takes a target (such as an http_archive
) as a dep, and re-export it.
def _inner_path_impl(ctx):
original_default_output = ctx.attrs.target[DefaultInfo].default_outputs[0]
return [
DefaultInfo(default_outputs = [original_default_output.project(ctx.attrs.subpath)])
]
inner_path = rule(
impl = _inner_path_impl,
attrs = {
"target": attrs.dep(providers = [DefaultInfo]),
"subpath": attrs.string()
}
)
Then you use it like this:
http_archive(
name = "_ext-link",
named_outs = { "liblef.a": "/opt/b28/s-5.8.003/linux_x86_64_rhel7/lib/liblef.a"}
...
)
inner_path(
name = "ext-link",
target = ":_ext-link",
subpath = "opt/b28/s-5.8.003/linux_x86_64_rhel7/lib/liblef.a"
)
prebuilt_cxx_libary(
static_lib = '//:ext-link',
...
)
When using prebuilt_cxx_libary, it is OK if the member static_lib is set to a relative path. However, when I use $(location //:target) buck2 reports the following error I asked if prebuilt_cxx_libary.static_lib supports $(location //:target), just like prebuilt_cxx_libary.exported_linker_flags supports it. Thanks!