-
Notifications
You must be signed in to change notification settings - Fork 389
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
Read flags from pkg-config files #203
Comments
Using the following it does at least compile:
|
The following does link:
|
I'll look into this as soon as I can, but due to conference and travel schedules, it will be at least a few days before I can look into this. A few things I notice from the build files:
|
Not just in this case I would consider this a bug. With the default go toolchain, there is no visibility and thus everything is "visible" no matter how deep the files are nested. As such, IMO gazelle should emulate that behavior as much as possible (and as a consequence collect these header files).
That is great. Sadly this project does not actually use this mechanism.
Agreed.
Thanks, will give that a spin next week. |
Ok, I had a chance to look at this. All the flags needed are in the .pc files, and Gazelle doesn't know about these. I was vaguely aware that cgo supported them. I've marked this issue as a feature request for Gazelle to support them as well. In general, cgo flags almost always require some adjustment in Bazel because they frequently point to include directories and libraries outside of the workspace. Even link flags within the workspace like Unfortunately, those adjustments are hard to make with |
Gazelle errors out when it encounters pkg-config today. Creating BUILD files by hand can be challenging when dealing with many external or vendored repositories that use pkg-config. Does it make sense to throw a warning instead so we can get a set of BUILD files that we can edit and add C flags to? (Encountering this when attempting to build CRI-O with rules_go.) |
Closing this issue: I don't think pkg-config can be reasonably supported. It fundamentally relies on system configuration outside the Bazel workspace. Flags appropriate for one system may not be appropriate for another. Different versions of a library may be installed (or not installed at all). Cross compilation and remote execution can't work. A better way to depend on these libraries is to pull them in as git_repository or http_archive rules with build files that provide cc_library targets. Unfortunately, there's not an easy way to automate that. |
@jayconrod Could you give some more details here? I'm migrating a Go project to Bazel, which requires libvirt-go as a dependency. I used to BTW, libvirt-go has |
You'll need to be able to incorporate
|
@jayconrod Thank you for your quick response. So I finally got it work with your last option, posting some key points here in case someone may also need it. First, introduce the libvirt library to the workspace: # WORKSPACE
new_local_repository(
name = "system_libs",
build_file_content = """
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "libvirt",
srcs = ["libvirt.so", "libvirt-admin.so", "libvirt-lxc.so", "libvirt-qemu.so"],
visibility = ["//visibility:public"],
)
""",
path = "/usr/lib64",
) Patch the auto generated BUILD.bazel file of libvirt-go to add the lib with # WORKSPACE
go_repository(
name = "com_github_libvirt_libvirt_go",
importpath = "github.com/libvirt/libvirt-go",
patch_args = ["-p1"],
patches = ["//hack:com_github_libvirt_libvirt_go.patch"],
sum = "h1:/Vmyq7XnPS2bfjJUkeJrkDueFDXNtbIkIE/E0tfRlY8=",
version = "v6.4.0+incompatible",
) # hack/com_github_libvirt_libvirt_go.patch
diff --git a/BUILD.bazel b/BUILD.bazel
index ce3e7e0..442f16b 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -92,6 +92,7 @@ go_library(
"typedparams_wrapper.go",
"typedparams_wrapper.h",
],
+ cdeps = ["@system_libs//:libvirt"],
cgo = True,
importpath = "github.com/libvirt/libvirt-go",
visibility = ["//visibility:public"], With these in place, I can now build and run my Go binary. This is not the ideal way to go since it would require people to install libvirt as system lib to compile or run the program, but I'm glad it's working. I'd probably vendor these .so files in the next step to make builds repeatable again. |
The following does not work with rules_go 0.12 and bazel 0.13:
First off - I am quite impressed that it works as far as it does.
It seems to not find
_cgo_export.h
, though.The text was updated successfully, but these errors were encountered: