Skip to content

Commit 90eb6de

Browse files
morotenEdSchouten
authored andcommitted
Actually build for linux_386 in CI
Add the --platforms argument for 'bazel test'. It is possible to build for linux_386 and run the test on the host platform linux_amd64. While adding //tools/platforms:host, set the host to no-remote-exec.
1 parent 2489d29 commit 90eb6de

6 files changed

Lines changed: 56 additions & 19 deletions

File tree

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ run --workspace_status_command="bash tools/workspace-status.sh"
22
common --enable_platform_specific_config
33
common --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
44
common --protocopt=--fatal_warnings
5+
common --host_platform=//tools/platforms:host
56

67
# Required to make protobuf compile on Windows
78
common:windows --host_cxxopt=/std:c++17 --define=protobuf_allow_msvc=true

.github/workflows/main.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{
2222
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_amd64'",
2323
"name": "linux_amd64: build${{ matrix.host.platform_name == 'linux_amd64' && ' and test' || '' }}",
24-
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
24+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64 //..."
2525
},
2626
{
2727
"if": "matrix.host.upload",
@@ -96,7 +96,7 @@
9696
{
9797
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_amd64_v3'",
9898
"name": "linux_amd64_v3: build${{ matrix.host.platform_name == 'linux_amd64_v3' && ' and test' || '' }}",
99-
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64_v3' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64_v3 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
99+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64_v3' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64_v3 //..."
100100
},
101101
{
102102
"if": "matrix.host.upload",
@@ -171,7 +171,7 @@
171171
{
172172
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_386'",
173173
"name": "linux_386: build${{ matrix.host.platform_name == 'linux_amd64' && ' and test' || '' }}",
174-
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_386 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
174+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_386 //..."
175175
},
176176
{
177177
"if": "matrix.host.upload",
@@ -246,7 +246,7 @@
246246
{
247247
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_arm'",
248248
"name": "linux_arm: build${{ matrix.host.platform_name == 'linux_arm' && ' and test' || '' }}",
249-
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
249+
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm //..."
250250
},
251251
{
252252
"if": "matrix.host.upload",
@@ -321,7 +321,7 @@
321321
{
322322
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_arm64'",
323323
"name": "linux_arm64: build${{ matrix.host.platform_name == 'linux_arm64' && ' and test' || '' }}",
324-
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
324+
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm64 //..."
325325
},
326326
{
327327
"if": "matrix.host.upload",
@@ -396,7 +396,7 @@
396396
{
397397
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'darwin_amd64'",
398398
"name": "darwin_amd64: build${{ matrix.host.platform_name == 'darwin_amd64' && ' and test' || '' }}",
399-
"run": "bazel ${{ matrix.host.platform_name == 'darwin_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
399+
"run": "bazel ${{ matrix.host.platform_name == 'darwin_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_amd64 //..."
400400
},
401401
{
402402
"if": "matrix.host.upload",
@@ -471,7 +471,7 @@
471471
{
472472
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'darwin_arm64'",
473473
"name": "darwin_arm64: build${{ matrix.host.platform_name == 'darwin_arm64' && ' and test' || '' }}",
474-
"run": "bazel ${{ matrix.host.platform_name == 'darwin_arm64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_arm64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
474+
"run": "bazel ${{ matrix.host.platform_name == 'darwin_arm64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_arm64 //..."
475475
},
476476
{
477477
"if": "matrix.host.upload",
@@ -546,7 +546,7 @@
546546
{
547547
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'freebsd_amd64'",
548548
"name": "freebsd_amd64: build${{ matrix.host.platform_name == 'freebsd_amd64' && ' and test' || '' }}",
549-
"run": "bazel ${{ matrix.host.platform_name == 'freebsd_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:freebsd_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
549+
"run": "bazel ${{ matrix.host.platform_name == 'freebsd_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:freebsd_amd64 //..."
550550
},
551551
{
552552
"if": "matrix.host.upload",
@@ -621,7 +621,7 @@
621621
{
622622
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'windows_amd64'",
623623
"name": "windows_amd64: build${{ matrix.host.platform_name == 'windows_amd64' && ' and test' || '' }}",
624-
"run": "bazel ${{ matrix.host.platform_name == 'windows_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:windows_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
624+
"run": "bazel ${{ matrix.host.platform_name == 'windows_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:windows_amd64 //..."
625625
},
626626
{
627627
"if": "matrix.host.upload",

.github/workflows/pull-requests.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,47 @@
2121
{
2222
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_amd64'",
2323
"name": "linux_amd64: build${{ matrix.host.platform_name == 'linux_amd64' && ' and test' || '' }}",
24-
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
24+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64 //..."
2525
},
2626
{
2727
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_amd64_v3'",
2828
"name": "linux_amd64_v3: build${{ matrix.host.platform_name == 'linux_amd64_v3' && ' and test' || '' }}",
29-
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64_v3' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64_v3 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
29+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64_v3' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_amd64_v3 //..."
3030
},
3131
{
3232
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_386'",
3333
"name": "linux_386: build${{ matrix.host.platform_name == 'linux_amd64' && ' and test' || '' }}",
34-
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_386 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
34+
"run": "bazel ${{ matrix.host.platform_name == 'linux_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_386 //..."
3535
},
3636
{
3737
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_arm'",
3838
"name": "linux_arm: build${{ matrix.host.platform_name == 'linux_arm' && ' and test' || '' }}",
39-
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
39+
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm //..."
4040
},
4141
{
4242
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'linux_arm64'",
4343
"name": "linux_arm64: build${{ matrix.host.platform_name == 'linux_arm64' && ' and test' || '' }}",
44-
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
44+
"run": "bazel ${{ matrix.host.platform_name == 'linux_arm64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:linux_arm64 //..."
4545
},
4646
{
4747
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'darwin_amd64'",
4848
"name": "darwin_amd64: build${{ matrix.host.platform_name == 'darwin_amd64' && ' and test' || '' }}",
49-
"run": "bazel ${{ matrix.host.platform_name == 'darwin_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
49+
"run": "bazel ${{ matrix.host.platform_name == 'darwin_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_amd64 //..."
5050
},
5151
{
5252
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'darwin_arm64'",
5353
"name": "darwin_arm64: build${{ matrix.host.platform_name == 'darwin_arm64' && ' and test' || '' }}",
54-
"run": "bazel ${{ matrix.host.platform_name == 'darwin_arm64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_arm64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
54+
"run": "bazel ${{ matrix.host.platform_name == 'darwin_arm64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:darwin_arm64 //..."
5555
},
5656
{
5757
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'freebsd_amd64'",
5858
"name": "freebsd_amd64: build${{ matrix.host.platform_name == 'freebsd_amd64' && ' and test' || '' }}",
59-
"run": "bazel ${{ matrix.host.platform_name == 'freebsd_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:freebsd_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
59+
"run": "bazel ${{ matrix.host.platform_name == 'freebsd_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:freebsd_amd64 //..."
6060
},
6161
{
6262
"if": "matrix.host.cross_compile || matrix.host.platform_name == 'windows_amd64'",
6363
"name": "windows_amd64: build${{ matrix.host.platform_name == 'windows_amd64' && ' and test' || '' }}",
64-
"run": "bazel ${{ matrix.host.platform_name == 'windows_amd64' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:windows_amd64 --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..."
64+
"run": "bazel ${{ matrix.host.platform_name == 'windows_amd64' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:windows_amd64 //..."
6565
}
6666
],
6767
"strategy": {

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ bazel_dep(name = "rules_nodejs", version = "6.7.4")
1919
bazel_dep(name = "rules_shell", version = "0.8.0")
2020
bazel_dep(name = "toolchains_llvm", version = "1.7.0")
2121

22+
register_toolchains("//tools/platforms:test_toolchain_running_linux_x86_32_on_x86_64")
23+
2224
git_override(
2325
module_name = "bazel_remote_apis",
2426
commit = "becdd8f9ff811df88a22d3eadd6341753d51d167",

tools/github_workflows/workflows_template.libsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
[{
8585
name: platform.name + ": build${{ matrix.host.platform_name == '%s' && ' and test' || '' }}" % std.get(platform, 'testPlatform', platform.name),
8686
// Run tests only if we're not cross-compiling.
87-
run: "bazel ${{ matrix.host.platform_name == '%s' && 'test --test_output=errors' || 'build --platforms=@com_github_buildbarn_bb_storage//tools/platforms:%s --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} //..." % [
87+
run: "bazel ${{ matrix.host.platform_name == '%s' && 'test --test_output=errors' || 'build --@bazel_tools//tools/test:incompatible_use_default_test_toolchain=False' }} --platforms=@com_github_buildbarn_bb_storage//tools/platforms:%s //..." % [
8888
std.get(platform, 'testPlatform', platform.name),
8989
platform.name + if enableCgo then '_cgo' else '',
9090
],

tools/platforms/BUILD.bazel

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,37 @@ platform(
2626
parents = ["@rules_go//go/toolchain:linux_amd64"],
2727
visibility = ["//visibility:public"],
2828
)
29+
30+
platform(
31+
name = "host",
32+
constraint_values = [
33+
# If any of the @rules_go//go/toolchain:rules_go platforms above are
34+
# used as target platform under `bazel test`,
35+
# @bazel_tools//tools/test:default_test_toolchain does not match the
36+
# default @platforms//host as execution platform because it is missing
37+
# @rules_go//go/toolchain:cgo_off constraint.
38+
#
39+
# See also https://github.com/bazelbuild/bazel/issues/30560.
40+
"@rules_go//go/toolchain:cgo_off",
41+
],
42+
# The host is not remote.
43+
exec_properties = {"no-remote-exec": "true"},
44+
parents = ["@platforms//host"],
45+
visibility = ["//visibility:public"],
46+
)
47+
48+
# x86_32 binaries can run on x86_64, at least for Linux.
49+
toolchain(
50+
name = "test_toolchain_running_linux_x86_32_on_x86_64",
51+
exec_compatible_with = [
52+
"@platforms//os:linux",
53+
"@platforms//cpu:x86_64",
54+
],
55+
target_compatible_with = [
56+
"@platforms//os:linux",
57+
"@platforms//cpu:x86_32",
58+
],
59+
toolchain = "@bazel_tools//tools/test:empty_toolchain",
60+
toolchain_type = "@bazel_tools//tools/test:default_test_toolchain_type",
61+
visibility = ["//visibility:private"],
62+
)

0 commit comments

Comments
 (0)