Bazel go binary: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 33: Line 33:


<syntaxhighlight lang='go'>
<syntaxhighlight lang='go'>
load("//meta/rules:go.bzl", "go_library")
load("//meta/rules:go.bzl", "go_binary")


go_library(
go_binary(
     name = "somepkg",
     name = "",
     srcs = [
     srcs = [
         "file1.go",
         "main.go",
         "file2.go",
         "aux.go",
     ],
     ],
    importpath = "github.com/someorg/somemodule/pkg/somepkg",
     visibility = ["//visibility:public"],
     visibility = ["//visibility:public"], # private if this is a library that becomes part of an executable
     deps = [
     deps = [
         "//lib/a",
         "//lib/some_lib",
         "//lib/b",
         "//tools/some_tool/some_package",
        ...
         "@com_github_google_uuid//:uuid",
         "@com_github_blang_semver//:semver",
     ],
     ],
)
)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:36, 20 September 2024

Internal

Overview

Example

load("//meta/rules:go.bzl", "go_library", "go_binary")

go_library(
    name = "somepkg_lib",
    srcs = [
        "file1.go",
        "file2.go",
    ],
    importpath = "github.com/someorg/somemodule/pkg/somepkg",
    visibility = ["//visibility:private"],
    deps = [
        "//lib/a",
        "//lib/b",
        ...
        "@com_github_blang_semver//:semver",
    ],
)

go_binary(
    name = "somebin",
    embed = [":somepkg_lib"],
    visibility = ["//visibility:public"],
    x_defs = {"github.com/someorg/somemodule/version.Version": "{BUILD_VERSION}"},
)
load("//meta/rules:go.bzl", "go_binary")

go_binary(
    name = "",
    srcs = [
        "main.go",
        "aux.go",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//lib/some_lib",
        "//tools/some_tool/some_package",
        "@com_github_google_uuid//:uuid",
    ],
)