Get support for sagikazarmark/please-go-modules

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

sagikazarmark/please-go-modules

Please Go Modules rule generator

GitHub Workflow Status Please Version

Generate Please go_module targets from your go.mod file.

Introduction

Please added official Go modules support in v16. However, it still requires you to manually write go_module targets. For large projects, that can be a heavy task.

This project helps with that task, by automatically generating a third_party/go/BUILD.plz file containing all modules required for your project.

Usage

Generate BUILD file from go.mod

Add the following snippet to your tools/BUILD file in the root of your repository:

remote_file(
    name = "godeps",
    url = f"https://github.com/sagikazarmark/please-go-modules/releases/latest/download/godeps_{CONFIG.HOSTOS}_{CONFIG.HOSTARCH}.tar.gz",
    extract = True,
    exported_files = ["godeps"],
    binary = True,
)

Add the following snippet to your .plzconfig:

[please]
version = 16.22.0

[alias "godeps"]
desc = Generate third-party dependency rules for a Go project
cmd = run //tools:godeps -- -dir third_party/go -clean -builtin

Run the following:

plz godeps

The above command will generate build targets in third_party/go for your third party dependencies.

Update BUILD files to use dependencies

You can combine the above with wollemi that can generate/update BUILD files in your project to use third-party dependencies.

Add the following content to your tools/BUILD file:

go_toolchain(
    name = "go_toolchain",
    version = "1.16.3",
)

WOLLEMI_VERSION = "v0.8.1"
remote_file(
    name = "wollemi",
    url = f"https://github.com/tcncloud/wollemi/releases/download/{WOLLEMI_VERSION}/wollemi-{WOLLEMI_VERSION}-{CONFIG.HOSTOS}-{CONFIG.HOSTARCH}.tar.gz",
    extract = True,
    exported_files = ["wollemi"],
    binary = True,
)

sh_cmd(
    name = "plz-tidy",
    cmd = [
        "export GOROOT=\\\\$($(out_exe :go_toolchain|go) env GOROOT)",
        "$(out_exe :godeps) -dir third_party/go -clean -builtin -wollemi",
        "$(out_exe :wollemi) gofmt ./...",
    ],
    deps = [
        ":godeps",
        ":wollemi",
        ":go_toolchain",
    ],
)

Note: You can remove any references to go_toolchain if you want to use Go installed on your system.

Finally, add an alias:

[alias "tidy"]
desc = Tidy generates build targets for dependencies and makes sure that BUILD files are up-to-date.
cmd = run //tools:plz-tidy

and run:

plz tidy

Note: the wollemi command might not work perfectly with Go submodules. You need to run wollemi for each module separately.

Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2