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

Imports of headers not handled inside inline assembly files (.s or .h) #1393

Open
esprehn opened this issue Dec 12, 2022 · 5 comments
Open

Comments

@esprehn
Copy link

esprehn commented Dec 12, 2022

What version of gazelle are you using?

v0.26.0

What version of rules_go are you using?

v0.35.0

What version of Bazel are you using?

5.1.10

Does this issue reproduce with the latest releases of all the above?

yes.

What operating system and processor architecture are you using?

Mac OS M1 and Linux Intel.

What did you do?

We're trying to use github.com/go-git/go-git/v5

which depends on github.com/cloudflare/circl

which contains a number of inline assembly files

which contain relative imports of includes across package boundaries, for example:

https://github.com/cloudflare/circl/blob/c56c51d2526f71be07939782d59d1a98744e062c/dh/x448/curve_amd64.s#L6

#include "../../math/fp448/fp_amd64.h"

which fails the build because the headers cannot be found at build time.

What did you expect to see?

Build passes.

What did you see instead?

gazelle does not appear to handle import statements in header files for assembly, which breaks popular libraries like the go-git library.

Gazelle should probably generate go_source() targets inside packages that contain .h files, ex. here:

https://github.com/cloudflare/circl/tree/main/math/fp448

and gazelle should also take a dependency on other packages when a cross project important statement appears in a .h or .s file.

In particular the dependency parser here:

https://github.com/bazelbuild/bazel-gazelle/blob/ec1c643571ece7bb5cac359b96c17b3641638c5d/language/go/fileinfo.go

should parse .s files and resolve relative import statements to absolute paths within the repo. And then produce cross project deps based on those just like import statements in .go code.

gazelle should also produce go_source() rules whenever there's a .h file within a package.

We fixed this in our repo with a series of patches like below, but ideally this would be generated by gazelle itself.

patches/com_github_cloudflare_circl/math_fp25519_BUILD_bazel.patch

--- math/fp25519/BUILD.bazel	2000-01-01 00:00:00.000000000 -0000
+++ math/fp25519/BUILD.bazel	2000-01-01 00:00:00.000000000 -0000
@@ -1,4 +1,4 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_source", "go_test")

 go_library(
     name = "fp25519",
@@ -22,6 +22,14 @@
     }),
 )

+go_source(
+    name = "headers",
+    srcs = [
+        "fp_amd64.h",
+    ],
+    visibility = ["//visibility:public"],
+)
+
 alias(
     name = "go_default_library",
     actual = ":fp25519",
@@ -37,3 +45,4 @@
         "//internal/test",
     ],
 )
+

patches/com_github_cloudflare_circl/source/dh_x25519_BUILD_bazel.new

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "x25519",
    srcs = [
        "curve.go",
        "curve_amd64.go",
        "curve_amd64.h",
        "curve_amd64.s",
        "curve_generic.go",
        "curve_noasm.go",
        "doc.go",
        "key.go",
        "table.go",
    ],
    embed = [
        "//math/fp25519:headers",
    ],
    importpath = "github.com/cloudflare/circl/dh/x25519",
    visibility = ["//visibility:public"],
    deps = [
        "//math/fp25519",
    ] + select({
        "@io_bazel_rules_go//go/platform:amd64": [
            "@org_golang_x_sys//cpu",
        ],
        "//conditions:default": [],
    }),
)

cc/ @skevy @indygreg

@patnaikshekhar
Copy link

I'm seeing the same error with go-git. @esprehn were you able to find a solution?

@malt3
Copy link
Contributor

malt3 commented Feb 10, 2023

Same issue here

@Tachone
Copy link

Tachone commented Apr 25, 2023

same here

@charlesoconor
Copy link
Contributor

I'm having the same issue on the latest version v0.30.0. My workaround, for now, is to patch in the changes to the BUILD.bazel files. Don't know if I have the best solution for it coping the directory e.g external/com_github_cloudflare_circl/ into a temp folder creating a git repo. Then making my changes and checking in the patch into my repo with git diff > temp.patch but it unblocked me.

@klandergren
Copy link

FYI: if you are using bzlmod there is another workaround described in this comment on bazelbuild/rules_go#3799

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

6 participants