bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

Header files not available when source contains assembly importing header file

Open tokongs opened this issue 2 years ago • 8 comments

What version of gazelle are you using?

v0.28.0

What version of rules_go are you using?

v0.37.0

What version of Bazel are you using?

5.3.2

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

What operating system and processor architecture are you using?

  • OS Manjaro
  • Arch: x86-64

What did you do?

Have a dependency on github.com/cloudflare/circl

    go_repository(
        name = "com_github_cloudflare_circl",
        build_file_proto_mode = "disable_global",
        importpath = "github.com/cloudflare/circl",
        sum = "h1:bZgT/A+cikZnKIwn7xL2OBj012Bmvho/o6RpRvv3GKY=",
        version = "v1.1.0",
    )

The issue occurs when you have a source with a Go assembly file which includes a header file, and the Go code is not CGO.

What did you expect to see?

Expect Gazelle to generate valid BUILD.bazel files for this.

What did you see instead?

The generated BUILD.bazel contains a go_library which fails to build because a header is ignored as the library is not marked with cgo=True

external/com_github_cloudflare_circl/dh/x25519/curve_amd64.s:7: #include: open external/com_github_cloudflare_circl/math/fp25519/fp_amd64.h: no such file or directory

compilepkg: error running subcommand external/go_sdk/pkg/tool/linux_amd64/asm: exit status 1

tokongs avatar Jan 17 '23 13:01 tokongs

I am facing same issue in my setup. Is there a workaround to use this repo com_github_cloudflare_circl in bazel by making some manual changes?

aman-harness avatar Feb 09 '23 09:02 aman-harness

encountered same issue +1

wenpincui avatar Feb 09 '23 09:02 wenpincui

@aman-harness @wenpincui We solved this by patching the generated BUILD.bazel files.

go_repository(
    name = "com_github_cloudflare_circl",
    build_file_proto_mode = "disable_global",
    importpath = "github.com/cloudflare/circl",
    patches = [
        "//third-party/go/com_github_cloudflare_circl:fp448.patch",
        "//third-party/go/com_github_cloudflare_circl:fp25519.patch",
        "//third-party/go/com_github_cloudflare_circl:x448.patch",
        "//third-party/go/com_github_cloudflare_circl:x25519.patch",
    ],
        sum = "h1:bZgT/A+cikZnKIwn7xL2OBj012Bmvho/o6RpRvv3GKY=",
        version = "v1.1.0",
    )

fp448.patch

--- math/fp448/BUILD.bazel
+++ math/fp448/BUILD.bazel
@@ -10,6 +10,7 @@ go_library(
         "fp_generic.go",
         "fp_noasm.go",
     ],
+    cgo = True,
     importpath = "github.com/cloudflare/circl/math/fp448",
     visibility = ["//visibility:public"],
     deps = [
@@ -28,6 +29,8 @@ alias(
     visibility = ["//visibility:public"],
 )

+exports_files(["fp_amd64.h"], ["//visibility:public"])
+
 go_test(
     name = "fp448_test",
     srcs = [

x448.patch

--- dh/x448/BUILD.bazel
+++ dh/x448/BUILD.bazel
@@ -12,7 +12,9 @@ go_library(
         "doc.go",
         "key.go",
         "table.go",
+       "//math/fp448:fp_amd64.h",
     ],
+    cgo = True,
     importpath = "github.com/cloudflare/circl/dh/x448",
     visibility = ["//visibility:public"],
     deps = [

With similar files for fp25519 and x25519

tokongs avatar Feb 09 '23 12:02 tokongs

Thanks @tokongs for the workaround. I use it here.

satreix avatar Mar 19 '23 17:03 satreix

@tokongs thank you!

ramilmsh avatar Mar 20 '23 12:03 ramilmsh

Thank you @tokongs!!!

friendly-pineapple avatar Apr 11 '23 01:04 friendly-pineapple

Duplicate of #1393

ashi009 avatar Aug 21 '23 14:08 ashi009

FYI: if you are using bzlmod there is another workaround described in this comment on https://github.com/bazelbuild/rules_go/issues/3799

klandergren avatar Mar 27 '24 02:03 klandergren