Skip to content

Commit 823deb2

Browse files
tomgrEdSchouten
authored andcommitted
Make bb-browser build cleanly on Windows
This also switches to using the pre-built protoc toolchains.
1 parent 5d2ed98 commit 823deb2

File tree

9 files changed

+238
-84
lines changed

9 files changed

+238
-84
lines changed

.bazelrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
build --host_cxxopt=-std=c++17
21
run --workspace_status_command="bash tools/workspace-status.sh"
2+
common --enable_platform_specific_config
3+
common --incompatible_enable_proto_toolchain_resolution
4+
common --protocopt=--fatal_warnings
5+
6+
# Required to make protobuf compile on Windows
7+
common:windows --host_cxxopt=/std:c++17 --define=protobuf_allow_msvc=true

.github/workflows/master.yaml

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,85 @@
11
{
22
"jobs": {
33
"build_and_test": {
4-
"runs-on": "ubuntu-latest",
4+
"name": "build_and_test ${{ matrix.host.os }}",
5+
"runs-on": "${{ matrix.host.os }}",
56
"steps": [
67
{
78
"name": "Check out source code",
89
"uses": "actions/checkout@v1"
910
},
1011
{
1112
"name": "Installing Bazel",
12-
"run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}"
13+
"run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-${{matrix.host.bazel_os}}-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}",
14+
"shell": "bash"
1315
},
1416
{
17+
"if": "matrix.host.platform_name == 'windows_amd64'",
18+
"name": "Override .bazelrc",
19+
"run": "echo \"startup --output_base=D:/bazel_output\" >> .bazelrc"
20+
},
21+
{
22+
"if": "matrix.host.lint",
1523
"name": "Bazel mod tidy",
1624
"run": "bazel mod tidy"
1725
},
1826
{
27+
"if": "matrix.host.lint",
1928
"name": "Gazelle",
2029
"run": "rm -f $(find . -name '*.pb.go' | sed -e 's/[^/]*$/BUILD.bazel/') && bazel run //:gazelle"
2130
},
2231
{
32+
"if": "matrix.host.lint",
2333
"name": "Buildifier",
2434
"run": "bazel run @com_github_bazelbuild_buildtools//:buildifier"
2535
},
2636
{
37+
"if": "matrix.host.lint",
2738
"name": "Gofmt",
2839
"run": "bazel run @cc_mvdan_gofumpt//:gofumpt -- -w -extra $(pwd)"
2940
},
3041
{
42+
"if": "matrix.host.lint",
3143
"name": "Clang format",
3244
"run": "find . -name '*.proto' -exec bazel run @llvm_toolchain_llvm//:bin/clang-format -- -i {} +"
3345
},
3446
{
47+
"if": "matrix.host.lint",
3548
"name": "GitHub workflows",
3649
"run": "bazel build //tools/github_workflows && cp bazel-bin/tools/github_workflows/*.yaml .github/workflows"
3750
},
3851
{
52+
"if": "matrix.host.lint",
3953
"name": "Protobuf generation",
4054
"run": "if [ -d pkg/proto ]; then\n find . bazel-bin/pkg/proto -name '*.pb.go' -delete || true\n bazel build $(bazel query --output=label 'kind(\"go_proto_library\", //...)')\n find bazel-bin/pkg/proto -name '*.pb.go' | while read f; do\n cat $f > $(echo $f | sed -e 's|.*/pkg/proto/|pkg/proto/|')\n done\nfi\n"
4155
},
4256
{
57+
"if": "matrix.host.lint",
4358
"name": "Embedded asset generation",
4459
"run": "bazel build $(git grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |//\\1:|; s|\"||g; s| .*||' | sort -u)\ngit grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |\\1/|' | while read o; do\n if [ -e \"bazel-bin/$o\" ]; then\n rm -rf \"$o\"\n cp -r \"bazel-bin/$o\" \"$o\"\n find \"$o\" -type f -exec chmod -x {} +\n fi\ndone\n"
4560
},
4661
{
62+
"if": "matrix.host.lint",
4763
"name": "Test style conformance",
4864
"run": "git add . && git diff --exit-code HEAD --"
4965
},
5066
{
67+
"if": "matrix.host.lint",
5168
"name": "Golint",
5269
"run": "bazel run @org_golang_x_lint//golint -- -set_exit_status $(pwd)/..."
5370
},
5471
{
55-
"name": "linux_amd64: build and test",
56-
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_amd64 //..."
72+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_amd64'",
73+
"name": "linux_amd64: build${{ matrix.host.platform_name == 'linux_amd64' && ' and test' || '' }}",
74+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:linux_amd64 //..."
5775
},
5876
{
77+
"if": "matrix.host.upload",
5978
"name": "linux_amd64: copy bb_browser",
6079
"run": "rm -f bb_browser && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_amd64 //cmd/bb_browser $(pwd)/bb_browser"
6180
},
6281
{
82+
"if": "matrix.host.upload",
6383
"name": "linux_amd64: upload bb_browser",
6484
"uses": "actions/upload-artifact@v4",
6585
"with": {
@@ -68,14 +88,17 @@
6888
}
6989
},
7090
{
71-
"name": "linux_386: build and test",
72-
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_386 //..."
91+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_386'",
92+
"name": "linux_386: build${{ matrix.host.platform_name == 'linux_amd64' && ' and test' || '' }}",
93+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:linux_386 //..."
7394
},
7495
{
96+
"if": "matrix.host.upload",
7597
"name": "linux_386: copy bb_browser",
7698
"run": "rm -f bb_browser && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_386 //cmd/bb_browser $(pwd)/bb_browser"
7799
},
78100
{
101+
"if": "matrix.host.upload",
79102
"name": "linux_386: upload bb_browser",
80103
"uses": "actions/upload-artifact@v4",
81104
"with": {
@@ -84,14 +107,17 @@
84107
}
85108
},
86109
{
87-
"name": "linux_arm: build and test",
88-
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm //..."
110+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_arm'",
111+
"name": "linux_arm: build${{ matrix.host.platform_name == 'linux_arm' && ' and test' || '' }}",
112+
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:linux_arm //..."
89113
},
90114
{
115+
"if": "matrix.host.upload",
91116
"name": "linux_arm: copy bb_browser",
92117
"run": "rm -f bb_browser && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_arm //cmd/bb_browser $(pwd)/bb_browser"
93118
},
94119
{
120+
"if": "matrix.host.upload",
95121
"name": "linux_arm: upload bb_browser",
96122
"uses": "actions/upload-artifact@v4",
97123
"with": {
@@ -100,14 +126,17 @@
100126
}
101127
},
102128
{
103-
"name": "linux_arm64: build and test",
104-
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm64 //..."
129+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_arm64'",
130+
"name": "linux_arm64: build${{ matrix.host.platform_name == 'linux_arm64' && ' and test' || '' }}",
131+
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm64' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:linux_arm64 //..."
105132
},
106133
{
134+
"if": "matrix.host.upload",
107135
"name": "linux_arm64: copy bb_browser",
108136
"run": "rm -f bb_browser && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_arm64 //cmd/bb_browser $(pwd)/bb_browser"
109137
},
110138
{
139+
"if": "matrix.host.upload",
111140
"name": "linux_arm64: upload bb_browser",
112141
"uses": "actions/upload-artifact@v4",
113142
"with": {
@@ -116,14 +145,17 @@
116145
}
117146
},
118147
{
119-
"name": "darwin_amd64: build and test",
120-
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_amd64 //..."
148+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'darwin_amd64'",
149+
"name": "darwin_amd64: build${{ matrix.host.platform_name == 'darwin_amd64' && ' and test' || '' }}",
150+
"run": "bazel ${{ matrix.host.platform_name == 'darwin_amd64' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:darwin_amd64 //..."
121151
},
122152
{
153+
"if": "matrix.host.upload",
123154
"name": "darwin_amd64: copy bb_browser",
124155
"run": "rm -f bb_browser && bazel run --run_under cp --platforms=@rules_go//go/toolchain:darwin_amd64 //cmd/bb_browser $(pwd)/bb_browser"
125156
},
126157
{
158+
"if": "matrix.host.upload",
127159
"name": "darwin_amd64: upload bb_browser",
128160
"uses": "actions/upload-artifact@v4",
129161
"with": {
@@ -132,14 +164,17 @@
132164
}
133165
},
134166
{
135-
"name": "darwin_arm64: build and test",
136-
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_arm64 //..."
167+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'darwin_arm64'",
168+
"name": "darwin_arm64: build${{ matrix.host.platform_name == 'darwin_arm64' && ' and test' || '' }}",
169+
"run": "bazel ${{ matrix.host.platform_name == 'darwin_arm64' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:darwin_arm64 //..."
137170
},
138171
{
172+
"if": "matrix.host.upload",
139173
"name": "darwin_arm64: copy bb_browser",
140174
"run": "rm -f bb_browser && bazel run --run_under cp --platforms=@rules_go//go/toolchain:darwin_arm64 //cmd/bb_browser $(pwd)/bb_browser"
141175
},
142176
{
177+
"if": "matrix.host.upload",
143178
"name": "darwin_arm64: upload bb_browser",
144179
"uses": "actions/upload-artifact@v4",
145180
"with": {
@@ -148,14 +183,17 @@
148183
}
149184
},
150185
{
151-
"name": "freebsd_amd64: build and test",
152-
"run": "bazel build --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_browser"
186+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'freebsd_amd64'",
187+
"name": "freebsd_amd64: build${{ matrix.host.platform_name == 'freebsd_amd64' && ' and test' || '' }}",
188+
"run": "bazel ${{ matrix.host.platform_name == 'freebsd_amd64' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:freebsd_amd64 //..."
153189
},
154190
{
191+
"if": "matrix.host.upload",
155192
"name": "freebsd_amd64: copy bb_browser",
156193
"run": "rm -f bb_browser && bazel run --run_under cp --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_browser $(pwd)/bb_browser"
157194
},
158195
{
196+
"if": "matrix.host.upload",
159197
"name": "freebsd_amd64: upload bb_browser",
160198
"uses": "actions/upload-artifact@v4",
161199
"with": {
@@ -164,14 +202,17 @@
164202
}
165203
},
166204
{
167-
"name": "windows_amd64: build and test",
168-
"run": "bazel build --platforms=@rules_go//go/toolchain:windows_amd64 //cmd/bb_browser"
205+
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'windows_amd64'",
206+
"name": "windows_amd64: build${{ matrix.host.platform_name == 'windows_amd64' && ' and test' || '' }}",
207+
"run": "bazel ${{ matrix.host.platform_name == 'windows_amd64' && 'test --test_output=errors' || 'build' }} --platforms=@rules_go//go/toolchain:windows_amd64 //..."
169208
},
170209
{
210+
"if": "matrix.host.upload",
171211
"name": "windows_amd64: copy bb_browser",
172212
"run": "rm -f bb_browser.exe && bazel run --run_under cp --platforms=@rules_go//go/toolchain:windows_amd64 //cmd/bb_browser $(pwd)/bb_browser.exe"
173213
},
174214
{
215+
"if": "matrix.host.upload",
175216
"name": "windows_amd64: upload bb_browser",
176217
"uses": "actions/upload-artifact@v4",
177218
"with": {
@@ -183,14 +224,38 @@
183224
"env": {
184225
"GITHUB_TOKEN": "${{ secrets.GITHUB_TOKEN }}"
185226
},
227+
"if": "matrix.host.upload",
186228
"name": "Install Docker credentials",
187229
"run": "echo \"${GITHUB_TOKEN}\" | docker login ghcr.io -u $ --password-stdin"
188230
},
189231
{
232+
"if": "matrix.host.upload",
190233
"name": "Push container bb_browser:bb_browser",
191234
"run": "bazel run --stamp //cmd/bb_browser:bb_browser_container_push"
192235
}
193-
]
236+
],
237+
"strategy": {
238+
"matrix": {
239+
"host": [
240+
{
241+
"bazel_os": "linux",
242+
"cross_compile": true,
243+
"lint": true,
244+
"os": "ubuntu-latest",
245+
"platform_name": "linux_amd64",
246+
"upload": true
247+
},
248+
{
249+
"bazel_os": "windows",
250+
"cross_compile": false,
251+
"lint": false,
252+
"os": "windows-latest",
253+
"platform_name": "windows_amd64",
254+
"upload": false
255+
}
256+
]
257+
}
258+
}
194259
}
195260
},
196261
"name": "master",

0 commit comments

Comments
 (0)