Skip to content

Incorrect use of user link flags in bindgen. #2406

@ghost

Description

Hello,

In generate_cc_link_build_info, the field user_link_flags of the LinkerInput is used to extend the command line of rustc through --arg-file:

linker_flags.extend(linker_input.user_link_flags)

It doesn't work with platform-specific linker flags such as Apple's -framework.

Here is a PoC:

# BUILD
load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_library")                    
                                                                                 
cc_library(                                                                      
    name = "foo",                                                                
    srcs = ["foo.c"],                                                            
    hdrs = ["foo.h"],                                                            
    linkopts = ["-framework", "Security"],                                       
)                                                                                
                                                                                 
rust_bindgen_library(                                                            
    name = "foo_bindgen",                                                        
    cc_lib = ":foo",                                                             
    header = "foo.h",                                                            
)

Bazel fails with the following error:

error: Unrecognized option: 'f'

The content of the .link_flags is the following:

-lstatic=foo
-framework
Security

-framework is treated as -f ramework, leading to the Unrecognized option error.

Since user_link_flags is supposed to contain linker flags, I think you should instead use the codegen option link-args:

-C
link-args=-framework Security

(Note that -lstatic= arguments won't end up in link-args since they don't come from user_link_flags)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions