bazel: use host platform by default (#1434)

This commit is contained in:
Malte Poll 2023-03-16 16:13:48 +01:00 committed by GitHub
parent 0fc15b2393
commit 62e2e70699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 107 additions and 21 deletions

View File

@ -20,9 +20,6 @@ build --strip=always
# set build mode to opt by default (better reproducibility and performance) # set build mode to opt by default (better reproducibility and performance)
build --compilation_mode=opt build --compilation_mode=opt
# compile for linux_amd64 by default (this is the target for any binaries that go into the cluster)
build --platforms @zig_sdk//libc_aware/platform:linux_amd64_gnu.2.34
# enable tpm simulator for tests # enable tpm simulator for tests
test --//bazel/settings:tpm_simulator test --//bazel/settings:tpm_simulator

View File

@ -9,8 +9,8 @@ enable_testing()
# disk-mapper # disk-mapper
# #
add_custom_target(disk-mapper ALL add_custom_target(disk-mapper ALL
COMMAND ${BAZEL} build //disk-mapper/cmd:cmd COMMAND ${BAZEL} build //disk-mapper/cmd:disk-mapper_linux_amd64
COMMAND cp \$$\(${BAZEL} cquery --output=files //disk-mapper/cmd:cmd\) ${CMAKE_BINARY_DIR}/disk-mapper COMMAND cp \$$\(${BAZEL} cquery --output=files //disk-mapper/cmd:disk-mapper_linux_amd64\) ${CMAKE_BINARY_DIR}/disk-mapper
COMMAND chmod +w ${CMAKE_BINARY_DIR}/disk-mapper COMMAND chmod +w ${CMAKE_BINARY_DIR}/disk-mapper
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS disk-mapper BYPRODUCTS disk-mapper
@ -20,8 +20,8 @@ add_custom_target(disk-mapper ALL
# measurement-reader # measurement-reader
# #
add_custom_target(measurement-reader ALL add_custom_target(measurement-reader ALL
COMMAND ${BAZEL} build //measurement-reader/cmd:cmd COMMAND ${BAZEL} build //measurement-reader/cmd:measurement-reader_linux_amd64
COMMAND cp \$$\(${BAZEL} cquery --output=files //measurement-reader/cmd:cmd\) ${CMAKE_BINARY_DIR}/measurement-reader COMMAND cp \$$\(${BAZEL} cquery --output=files //measurement-reader/cmd:measurement-reader_linux_amd64\) ${CMAKE_BINARY_DIR}/measurement-reader
COMMAND chmod +w ${CMAKE_BINARY_DIR}/measurement-reader COMMAND chmod +w ${CMAKE_BINARY_DIR}/measurement-reader
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS measurement-reader BYPRODUCTS measurement-reader
@ -31,8 +31,8 @@ add_custom_target(measurement-reader ALL
# bootstrapper # bootstrapper
# #
add_custom_target(bootstrapper ALL add_custom_target(bootstrapper ALL
COMMAND ${BAZEL} build //bootstrapper/cmd/bootstrapper:bootstrapper COMMAND ${BAZEL} build //bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64
COMMAND cp \$$\(${BAZEL} cquery --output=files //bootstrapper/cmd/bootstrapper:bootstrapper\) ${CMAKE_BINARY_DIR}/bootstrapper COMMAND cp \$$\(${BAZEL} cquery --output=files //bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64\) ${CMAKE_BINARY_DIR}/bootstrapper
COMMAND chmod +w ${CMAKE_BINARY_DIR}/bootstrapper COMMAND chmod +w ${CMAKE_BINARY_DIR}/bootstrapper
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS bootstrapper BYPRODUCTS bootstrapper
@ -42,8 +42,8 @@ add_custom_target(bootstrapper ALL
# upgrade-agent # upgrade-agent
# #
add_custom_target(upgrade-agent ALL add_custom_target(upgrade-agent ALL
COMMAND ${BAZEL} build //upgrade-agent/cmd:cmd COMMAND ${BAZEL} build //upgrade-agent/cmd:upgrade_agent_linux_amd64
COMMAND cp \$$\(${BAZEL} cquery --output=files //upgrade-agent/cmd:cmd\) ${CMAKE_BINARY_DIR}/upgrade-agent COMMAND cp \$$\(${BAZEL} cquery --output=files //upgrade-agent/cmd:upgrade_agent_linux_amd64\) ${CMAKE_BINARY_DIR}/upgrade-agent
COMMAND chmod +w ${CMAKE_BINARY_DIR}/upgrade-agent COMMAND chmod +w ${CMAKE_BINARY_DIR}/upgrade-agent
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS upgrade-agent BYPRODUCTS upgrade-agent
@ -53,8 +53,8 @@ add_custom_target(upgrade-agent ALL
# cli # cli
# #
add_custom_target(cli ALL add_custom_target(cli ALL
COMMAND ${BAZEL} build --@io_bazel_rules_go//go/config:tags='${CLI_BUILD_TAGS}' --platforms=@local_config_platform//:host //cli:cli_oss COMMAND ${BAZEL} build --@io_bazel_rules_go//go/config:tags='${CLI_BUILD_TAGS}' //cli:cli_oss_host
COMMAND cp \$$\(${BAZEL} cquery --@io_bazel_rules_go//go/config:tags='${CLI_BUILD_TAGS}' --platforms=@local_config_platform//:host --output=files //cli:cli_oss\) ${CMAKE_BINARY_DIR}/constellation COMMAND cp \$$\(${BAZEL} cquery --@io_bazel_rules_go//go/config:tags='${CLI_BUILD_TAGS}' --output=files //cli:cli_oss_host\) ${CMAKE_BINARY_DIR}/constellation
COMMAND chmod +w ${CMAKE_BINARY_DIR}/constellation COMMAND chmod +w ${CMAKE_BINARY_DIR}/constellation
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS constellation BYPRODUCTS constellation
@ -64,8 +64,8 @@ add_custom_target(cli ALL
# debugd # debugd
# #
add_custom_target(debugd ALL add_custom_target(debugd ALL
COMMAND ${BAZEL} build //debugd/cmd/debugd:debugd COMMAND ${BAZEL} build //debugd/cmd/debugd:debugd_linux_amd64
COMMAND cp \$$\(${BAZEL} cquery --output=files //debugd/cmd/debugd:debugd\) ${CMAKE_BINARY_DIR}/debugd COMMAND cp \$$\(${BAZEL} cquery --output=files //debugd/cmd/debugd:debugd_linux_amd64\) ${CMAKE_BINARY_DIR}/debugd
COMMAND chmod +w ${CMAKE_BINARY_DIR}/debugd COMMAND chmod +w ${CMAKE_BINARY_DIR}/debugd
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS debugd BYPRODUCTS debugd
@ -75,8 +75,8 @@ add_custom_target(debugd ALL
# cdbg # cdbg
# #
add_custom_target(cdbg ALL add_custom_target(cdbg ALL
COMMAND ${BAZEL} build --platforms=@local_config_platform//:host //debugd/cmd/cdbg:cdbg COMMAND ${BAZEL} build //debugd/cmd/cdbg:cdbg_host
COMMAND cp \$$\(${BAZEL} cquery --platforms=@local_config_platform//:host --output=files //debugd/cmd/cdbg:cdbg\) ${CMAKE_BINARY_DIR}/cdbg COMMAND cp \$$\(${BAZEL} cquery --output=files //debugd/cmd/cdbg:cdbg_host\) ${CMAKE_BINARY_DIR}/cdbg
COMMAND chmod +w ${CMAKE_BINARY_DIR}/cdbg COMMAND chmod +w ${CMAKE_BINARY_DIR}/cdbg
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
BYPRODUCTS cdbg BYPRODUCTS cdbg

View File

@ -3,16 +3,16 @@ load("//bazel/sh:def.bzl", "sh_template")
sh_template( sh_template(
name = "devbuild", name = "devbuild",
data = [ data = [
"//bootstrapper/cmd/bootstrapper", "//bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64",
"//cli:cli_oss_host", "//cli:cli_oss_host",
"//debugd/cmd/cdbg:cdbg_host", "//debugd/cmd/cdbg:cdbg_host",
"//upgrade-agent/cmd", "//upgrade-agent/cmd:upgrade_agent_linux_amd64",
], ],
substitutions = { substitutions = {
"@@BOOTSTRAPPER@@": "$(rootpath //bootstrapper/cmd/bootstrapper)", "@@BOOTSTRAPPER@@": "$(rootpath //bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64)",
"@@CDBG@@": "$(rootpath //debugd/cmd/cdbg:cdbg_host)", "@@CDBG@@": "$(rootpath //debugd/cmd/cdbg:cdbg_host)",
"@@CLI@@": "$(rootpath //cli:cli_oss_host)", "@@CLI@@": "$(rootpath //cli:cli_oss_host)",
"@@UPGRADE_AGENT@@": "$(rootpath //upgrade-agent/cmd)", "@@UPGRADE_AGENT@@": "$(rootpath //upgrade-agent/cmd:upgrade_agent_linux_amd64)",
}, },
template = "prepare_developer_workspace.sh.in", template = "prepare_developer_workspace.sh.in",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],

49
bazel/go/platform.bzl Normal file
View File

@ -0,0 +1,49 @@
"""A rule to build a single executable for a specific platform."""
def _platform_transition_impl(settings, attr):
_ignore = settings # @unused
return {
"//command_line_option:platforms": "{}".format(attr.platform),
}
_platform_transition = transition(
implementation = _platform_transition_impl,
inputs = [],
outputs = [
"//command_line_option:platforms",
],
)
def _platform_binary_impl(ctx):
out = ctx.actions.declare_file("{}_{}".format(ctx.file.target_file.basename, ctx.attr.platform))
ctx.actions.symlink(output = out, target_file = ctx.file.target_file)
return [
DefaultInfo(
executable = out,
files = depset([out]),
runfiles = ctx.runfiles(files = ctx.files.target_file),
),
]
_attrs = {
"platform": attr.string(
doc = "The platform to build the target for.",
),
"target_file": attr.label(
allow_single_file = True,
mandatory = True,
doc = "Target to build.",
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}
# wrap a single exectable and build it for the specified platform.
platform_binary = rule(
implementation = _platform_binary_impl,
cfg = _platform_transition,
attrs = _attrs,
executable = True,
)

View File

@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//bazel/go:platform.bzl", "platform_binary")
go_library( go_library(
name = "bootstrapper_lib", name = "bootstrapper_lib",
@ -54,3 +55,10 @@ go_binary(
}), }),
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
platform_binary(
name = "bootstrapper_linux_amd64",
platform = "@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.34",
target_file = ":bootstrapper",
visibility = ["//visibility:public"],
)

View File

@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//bazel/go:platform.bzl", "platform_binary")
go_library( go_library(
name = "debugd_lib", name = "debugd_lib",
@ -33,3 +34,10 @@ go_binary(
pure = "on", pure = "on",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
platform_binary(
name = "debugd_linux_amd64",
platform = "@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.34",
target_file = ":debugd",
visibility = ["//visibility:public"],
)

View File

@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//bazel/go:platform.bzl", "platform_binary")
go_library( go_library(
name = "cmd_lib", name = "cmd_lib",
@ -35,3 +36,10 @@ go_binary(
embed = [":cmd_lib"], embed = [":cmd_lib"],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
platform_binary(
name = "disk-mapper_linux_amd64",
platform = "@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.34",
target_file = ":cmd",
visibility = ["//visibility:public"],
)

View File

@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//bazel/go:platform.bzl", "platform_binary")
go_library( go_library(
name = "cmd_lib", name = "cmd_lib",
@ -21,3 +22,10 @@ go_binary(
embed = [":cmd_lib"], embed = [":cmd_lib"],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
platform_binary(
name = "measurement-reader_linux_amd64",
platform = "@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.34",
target_file = ":cmd",
visibility = ["//visibility:public"],
)

View File

@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//bazel/go:platform.bzl", "platform_binary")
go_library( go_library(
name = "cmd_lib", name = "cmd_lib",
@ -22,3 +23,10 @@ go_binary(
pure = "on", pure = "on",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
platform_binary(
name = "upgrade_agent_linux_amd64",
platform = "@zig_sdk//libc_aware/platform:linux_amd64_gnu.2.34",
target_file = ":cmd",
visibility = ["//visibility:public"],
)