bazel-contrib / bazel-contrib/rules_go

Non-reproducible builds with templated files

Open
#2,844 3 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

v0.26.0

### What version of gazelle are you using?

V0.23.0

### What version of Bazel are you using?

4.0.0

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

Yes

### What operating system and processor architecture are you using?

Linux / MacOS, AMD64.

### What did you do?

At work, we are templating Go files with information from other parts of the build. For example, `go_image` (+ `container_push`) produce a `.digest` file, containing the image digests. These digests are then added to `.go` files, which are further used within the build process.

All images are built with `goos = "linux"` and `goarch = "amd64"`.

So far, we always copied those templated files back into the workspace with a `bazel run` command. However, as I need those templated files now as part of the build-process already, I do not want to need multiple `bazel run`s to get to the end state.

To work around this, we depend on the templated, but not yet copied into the workspace, file within `go_library`.

### What did you expect to see?

To get the same final image digest, no matter on which platform the build is being run.

### What did you see instead?

Non-reproducible builds with different libraries being built on MacOS and Linux.
I think the cause of this issue is the path of the templated file, which seems to differ on platforms.
MacOS:

```
Writing to output file bazel-out/darwin-fastbuild-ST-5fa8105c1248/bin/hello.go
```

Linux:
```
Writing to output file bazel-out/k8-fastbuild-ST-5fa8105c1248/bin/hello.go
```

This seems to build different libraries:
MacOS:
```
$ ls -la bazel-out/darwin-fastbuild-ST-5fa8105c1248/bin/
-r-xr-xr-x 1 ramon wheel 7852 Mar 12 11:27 mybin.a
-r-xr-xr-x 1 ramon wheel 160 Mar 12 11:27 mybin.x
```

Linux:
```
$ ls -la bazel-out/k8-fastbuild-ST-5fa8105c1248/bin/
-r-xr-xr-x 1 root root 7848 Mar 12 10:28 mybin.a
-r-xr-xr-x 1 root root 160 Mar 12 10:28 mybin.x
```

Which in turn means different image digests.

I made a full repro here:
https://github.com/tommyknows/rules_go_repro

To test this on linux, I've ran this in Docker:
```
docker run --entrypoint="" -v (pwd):/project --rm -it gcr.io/cloud-marketplace-containers/google/bazel /bin/bash
```

Am I doing something wrong? or is this a bug in `rules_go`? (or a known issue, and can it be fixed / worked around?)

Thanks!

Contributor guide

Open the contributing guide

Research direction

Start with the full reproduction at https://github.com/tommyknows/rules_go_repro and the reported rules_go, Gazelle, and Bazel versions. Run the build on Linux and macOS, or use the provided Docker command, then compare the templated hello.go output paths and generated library artifacts under bazel-out. Done means the same final image digest is produced across the reported platforms, or the platform-dependent behavior is documented with a confirmed workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
build-system, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.