Skip to content

go: support go:embed directives in 1.16 #2775

@jayconrod

Description

@jayconrod

Go 1.16 allows embedding files within a compiled package by imported the embed package and using one or more //go:embed directives. For example:

package main

import (
  _ "embed"
  "fmt"
)

func main() {
  //go:embed quine.go
  var s string
  fmt.Print(s)
}

rules_go should support this.

go_library, go_binary, go_test, and perhaps also go_proto_library should support a new embedsrcs attribute specifying a list of targets that could provide embeddable files. It's unfortunate we can't just call it embed, but that already means something else.

The rules should pass these files to the builder, which should match the //go:embed patterns against these files to produce an embedcfg file, which may be passed to the compiler.

The builder should produce a sensible error messages if //go:embed directives are used Go versions lower than 1.16.

Until this is implemented, go_embed_data may be used instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions