rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

Exposing folder to go_binary

Open GRVYDEV opened this issue 2 years ago • 1 comments

What version of rules_go are you using?

0.42.0

What version of gazelle are you using?

0.33.0

What version of Bazel are you using?

7.0.0

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

N/A

What operating system and processor architecture are you using?

macOS arm

Any other potentially useful information about your toolchain?

What did you do?

I have a folder structure like this

servers/
    api/
       main.go
       BUILD.bazel
       web/
            ...misc HTML files

I am trying to read files in the web folder in the resulting go binary. My build file is this:

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

go_library(
    name = "api_lib",
    srcs = ["main.go"],
    importpath = "github.com/GRVYDEV/quantic/servers/api",
    visibility = ["//visibility:private"],
    deps = [
        "//internal/server",
        "@com_github_weaviate_weaviate//entities/models",
        "@com_github_weaviate_weaviate_go_client_v4//weaviate",
        "@com_github_weaviate_weaviate_go_client_v4//weaviate/graphql",
    ],
)

go_binary(
    name = "api",
    embed = [":api_lib"],
    data = glob(["web/**"]),
    visibility = ["//visibility:public"],
)

The web folder is not getting put next to the resulting binary. I am doing something wrong here but I am unsure how to properly do this. Thanks in advance for any help.

GRVYDEV avatar Dec 14 '23 01:12 GRVYDEV

This should be working. Could you share a self-contained reproducer? Also take a look at @rules_go//go/runfiles, a library that helps you find data files at runtime.

fmeum avatar Dec 14 '23 08:12 fmeum