Bindgen and Bzlmod #2903
              
                Unanswered
              
          
                  
                    
                      sonoclock110
                    
                  
                
                  asked this question in
                Q&A
              
            Replies: 2 comments 2 replies
-
| Same issue, anyone? | 
Beta Was this translation helpful? Give feedback.
                  
                    2 replies
                  
                
            -
| When using bindgen, you need to provide an LLVM toolchain to bazel. On the docs there are listed two methods: either compile  register_toolchains("@rules_rust_bindgen//:default_bindgen_toolchain")or use a precompiled version, fetched from the web, which should be similar to (but please CHECK!): # MODULE.bazel
bazel_dep(name = "rules_rust", version = "0.59.2")
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_rust_bindgen", version = "0.59.2")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "toolchains_llvm", version = "1.3.0")
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(llvm_version = "17.0.6")
use_repo(llvm, "llvm_toolchain_llvm")
register_toolchains("//my_package:my_bindgen_toolchain")# BUILD file of my_package
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@rules_cc//cc:defs.bzl", "cc_import")
load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_toolchain")
native_binary(
    name = "clang",
    src = "@llvm_toolchain_llvm//:bin/clang",
)
cc_import(
    name = "libclang",
    shared_library = "@llvm_toolchain_llvm//:libclang",
)
rust_bindgen_toolchain(
    name = "rust_bindgen_toolchain",
    bindgen = "@rules_rust_bindgen//3rdparty:bindgen",
    clang = ":clang",
    libclang = ":libclang",
)
toolchain(
    name = "my_bindgen_toolchain",
    toolchain = ":rust_bindgen_toolchain",
    toolchain_type = "@rules_rust_bindgen//:toolchain_type",
)After this you should be able to load and call the bindgen functions, though i didn't manage to find how to link everything toghether | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Q&A,
I try to use bindgen with bzlmod.
In MODULE.bazel I added:
bazel_dep(name = "rules_rust", version = "0.51.0")Within a BUILD file I use bindgen:
load("@rules_rust//bindgen:defs.bzl", "rust_bindgen")cc_library( name = "hello_bindgen", srcs = ["hello_bindgen.c"], hdrs = ["hello_bindgen.h"], linkstatic = True, visibility = ["//visibility:public"], )rust_bindgen( name = "hello_rust_bindgen", cc_lib = ":hello_bindgen", header = ":hello_bindgen.h", )When try to build the target I get the error:
Do you have any idea what I have forgotten here?
Thanks!!!
Beta Was this translation helpful? Give feedback.
All reactions