Skip to content

Commit e90910c

Browse files
committed
Fix most cases of nondeterminism.
1 parent 2e372d4 commit e90910c

File tree

7 files changed

+53
-12
lines changed

7 files changed

+53
-12
lines changed

.bazelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Use hermetic C++ toolchain from nixpkgs
2+
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
3+
build --incompatible_enable_cc_toolchain_resolution
4+
5+
# Ensure no environment variables leak into actions
6+
build --incompatible_strict_action_env
7+
18
# EngFlow recommended flags
29
build --grpc_keepalive_time=30s
310
build --nolegacy_important_outputs

WORKSPACE.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,23 @@ new_git_repository(
9292
remote = "https://github.com/emikulic/darkhttpd.git",
9393
)
9494

95+
# https://github.com/bazel-contrib/rules_oci/pull/385
96+
9597
http_archive(
9698
name = "rules_oci",
9799
sha256 = "21a7d14f6ddfcb8ca7c5fc9ffa667c937ce4622c7d2b3e17aea1ffbc90c96bed",
98100
strip_prefix = "rules_oci-1.4.0",
99101
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v1.4.0/rules_oci-v1.4.0.tar.gz",
100102
)
101103

104+
#load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
105+
#
106+
#git_repository(
107+
# name = "rules_oci",
108+
# commit = "495b9b592b963c37959dbcac4e68153185b6a580",
109+
# remote = "https://github.com/bazel-contrib/rules_oci.git",
110+
#)
111+
102112
load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")
103113

104114
rules_oci_dependencies()
@@ -140,3 +150,8 @@ load("//docker:defs.bzl", "generate_entrypoint")
140150
generate_entrypoint(
141151
name = "docker_entrypoint",
142152
)
153+
154+
nixpkgs_package(
155+
name = "ffmpeg",
156+
repository = "@nixpkgs",
157+
)

diff.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
hashes() {
5+
sha256sum \
6+
bazel-bin/src/life_/life \
7+
bazel-bin/gif/animated.gif \
8+
bazel-bin/httpd/darkhttpd \
9+
bazel-bin/httpd/closure.tar \
10+
bazel-bin/docker/overlay.tar \
11+
bazel-bin/docker/tarball/tarball.tar
12+
}
13+
14+
build() {
15+
bazel clean
16+
bazel shutdown
17+
bazel build //...
18+
}
19+
20+
build; hashes1="$(hashes)"
21+
build; hashes2="$(hashes)"
22+
diff <(echo "$hashes1") <(echo "$hashes2")

docker/BUILD.bazel

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
2+
load("@rules_pkg//:pkg.bzl", "pkg_tar")
23

3-
genrule(
4+
pkg_tar(
45
name = "overlay",
56
srcs = [
67
"@docker_entrypoint//:entrypoint",
78
"//gif:animated",
89
],
9-
outs = ["overlay.tar"],
10-
cmd = """
11-
mkdir overlay
12-
cp $(SRCS) overlay
13-
tar -cf $@ -C overlay .
14-
""",
1510
)
1611

1712
oci_image(

gif/BUILD.bazel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ genrule(
1616
outs = FRAMES,
1717
)
1818

19+
FFMPEG = "@ffmpeg//:bin/ffmpeg"
20+
1921
genrule(
2022
name = "animated",
2123
srcs = FRAMES,
24+
tools = [FFMPEG],
2225
cmd = """
2326
vfopts="fps=10,scale=512:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"
24-
ffmpeg -i "$$(dirname $(execpath frame1.png))/frame%d.png" -vf "$$vfopts" $@
25-
""",
27+
$(execpath {ffmpeg}) -i "$$(dirname $(execpath frame1.png))/frame%d.png" -vf "$$vfopts" $@
28+
""".format(ffmpeg = FFMPEG),
2629
outs = ["animated.gif"],
2730
visibility = ["//visibility:public"],
2831
)

httpd/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ genrule(
1717
}
1818
mkdir closure
1919
cp $$(closure $< | sort -u) closure
20-
tar -cf $@ closure
20+
tar --sort=name --mtime=0 --owner=0 --group=0 --numeric-owner -cf $@ closure
2121
""",
2222
visibility = ["//visibility:public"],
2323
)

src/life.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"math/rand"
88
"os"
99
"strconv"
10-
"time"
1110
)
1211

1312
type Grid [][]bool
@@ -83,7 +82,7 @@ func (cells Grid) render(dc *gg.Context) {
8382
}
8483

8584
func main() {
86-
rand.Seed(time.Now().UnixNano())
85+
rand.Seed(0)
8786
cellSize, _ := strconv.Atoi(os.Args[1])
8887
cellCount, _ := strconv.Atoi(os.Args[2])
8988
frameCount, _ := strconv.Atoi(os.Args[3])

0 commit comments

Comments
 (0)