Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use "frameworks" for mac builds? #386

Open
miaoyipu opened this issue Aug 15, 2023 · 1 comment
Open

How to use "frameworks" for mac builds? #386

miaoyipu opened this issue Aug 15, 2023 · 1 comment

Comments

@miaoyipu
Copy link
Contributor

miaoyipu commented Aug 15, 2023

Hi, new to the buck on Mac. I am adding "-framework SomeFramework" to the link flag on Mac (can be implemented by exported_link_flags). So I added the framework to the hello world, like

cxx_library(
    name = "print",
    srcs = glob(["**/*.cpp"]),
    exported_headers = glob(["**/*.hpp"]),
    visibility = ["PUBLIC"],
    frameworks = [
        '$SDKROOT/System/Library/CoreAudio.framework',
    ],
)

I am seeing missing apple toolchain error

4: Traceback (most recent call last):
         File <builtin>, in <module>
         * prelude/cxx/cxx.bzl:169, in cxx_library_impl
             output = cxx_library_parameterized(ctx, params)
         * prelude/cxx/cxx_library.bzl:427, in cxx_library_parameterized
             shared_links, link_group_map, link_execution_preference = _get_shared_library...
         * prelude/cxx/cxx_library.bzl:1067, in _get_shared_library_links
             return apple_build_link_args_with_deduped_flags(
         * prelude/apple/apple_frameworks.bzl:135, in apple_build_link_args_with_deduped_flags
             link_info = _link_info_from_linkables(ctx, [merged.frameworks[link_style], fr...
         * prelude/apple/apple_frameworks.bzl:194, in _link_info_from_linkables
             framework_link_args = _get_apple_frameworks_linker_flags(ctx, merge_framework...
         * prelude/apple/apple_frameworks.bzl:50, in _get_apple_frameworks_linker_flags
             expanded_frameworks_paths = _expand_sdk_framework_paths(ctx, linkable.unresol...
         * prelude/apple/apple_frameworks.bzl:92, in _expand_sdk_framework_paths
             return [_expand_sdk_framework_path(ctx, unresolved_framework_path) for unreso...
       error: Object of type `struct` has no attribute `_apple_toolchain`
         --> prelude/apple/apple_frameworks.bzl:95:28
          |
       95 |     apple_toolchain_info = ctx.attrs._apple_toolchain[AppleToolchainInfo]
          |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^
          |

How should I make this work and passing apple_toolchain ?

@zjturner
Copy link
Contributor

I think you need to return one of these from your toolchain.

https://github.com/facebook/buck2/blob/56c1bcf08bb793a5314d7739b090b6d173314cde/prelude/apple/apple_toolchain_types.bzl#L8C1-L39

If you're using system_cxx_toolchain(), it doesn't do that so you would need to define a custom apple toolchain that does (or alternatively, patch system_cxx_toolchain()). The semantics of each of the fields isn't really documented, so it might take some work to figure out exactly what each field is supposed to do by looking for how each one is used. At least they are annotated with the intended type of the field.

This is the kind of thing that if you can figure out exactly how to use each field, upstreaming a patch to add comments to each fields describing how to use them would be super valuable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants