Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions worker/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build:riscv64 --platforms=//platforms:riscv64_linux
build:riscv64 --extra_toolchains=//toolchains/riscv:cc_toolchain_for_linux_riscv64
98 changes: 69 additions & 29 deletions worker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,82 @@ cc_binary(
"@curl//:curl",
],
copts = [
"-mssse3",
"-msse4.2",
"-mpclmul",
"-maes",
"-I$(GENDIR)/..",
"-I/usr/include",
],
] + select({
"@platforms//cpu:x86_64": [
"-mssse3",
"-msse4.2",
"-mpclmul",
"-maes",
"-I/usr/include",
],
"@platforms//cpu:riscv64": [],
"//conditions:default": ["-I/usr/include"],
}),
cxxopts = [
"-std=c++17",
"-std=c++17",
],
linkopts = [
"-L/usr/local/openssl/lib",
"-lssl",
"-lcrypto",

"-L/usr/local/lib",
"-lprometheus-cpp-push",
"-lprometheus-cpp-core",

"-L/usr/lib",
"-lrte_eal",
"-lrte_ethdev",
"-lrte_mempool",
"-lrte_mbuf",
"-lrte_bus_vdev",
"-lrte_ring",
"-lrte_telemetry",
"-lrte_kvargs",
"-lrte_log",
"-lrte_net",
"-lrte_hash",
"-lrte_timer",
"-lsqlite3",

"-lsqlite3",
"-lssl",
"-lcrypto",
"-lnuma",
"-ldl",
"-lpthread",
],
] + select({
"@platforms//cpu:x86_64": [
"-L/usr/local/openssl/lib",
"-L/usr/local/lib",
"-L/usr/lib",
"-lrte_eal",
"-lrte_ethdev",
"-lrte_mempool",
"-lrte_mbuf",
"-lrte_bus_vdev",
"-lrte_ring",
"-lrte_telemetry",
"-lrte_kvargs",
"-lrte_log",
"-lrte_net",
"-lrte_hash",
"-lrte_timer",
],
"@platforms//cpu:riscv64": [
"-Wl,--whole-archive",
"-lrte_eal",
"-lrte_ethdev",
"-lrte_mempool",
"-lrte_mbuf",
"-lrte_bus_vdev",
"-lrte_ring",
"-lrte_telemetry",
"-lrte_kvargs",
"-lrte_log",
"-lrte_net",
"-lrte_hash",
"-lrte_timer",
"-lrte_net_af_xdp",
"-Wl,--no-whole-archive",
"-lbpf",
"-lxdp",
"-lelf",
"-lz",
],
"//conditions:default": [
"-lrte_eal",
"-lrte_ethdev",
"-lrte_mempool",
"-lrte_mbuf",
"-lrte_bus_vdev",
"-lrte_ring",
"-lrte_telemetry",
"-lrte_kvargs",
"-lrte_log",
"-lrte_net",
"-lrte_hash",
"-lrte_timer",
],
}),
)
9 changes: 9 additions & 0 deletions worker/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "rules_proto", version = "7.0.2")
bazel_dep(name = "protobuf", version = "31.1", repo_name = "com_google_protobuf")
bazel_dep(name = "grpc", version = "1.78.0")

register_toolchains(
"//toolchains/riscv:cc_toolchain_for_linux_riscv64",
)

local_path_override(
module_name = "zlib",
path = "third_party/system_zlib",
)
5 changes: 5 additions & 0 deletions worker/third_party/system_zlib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cc_library(
name = "zlib",
linkopts = ["-lz"],
visibility = ["//visibility:public"],
)
4 changes: 4 additions & 0 deletions worker/third_party/system_zlib/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module(
name = "zlib",
version = "1.3.1",
)
2 changes: 1 addition & 1 deletion worker/toolchains/riscv/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ filegroup(name = "empty")

cc_toolchain(
name = "linux_riscv64_toolchain",
toolchain_identifier = "linux_riscv64-toolchain",
toolchain_identifier = "riscv-yocto-toolchain",
toolchain_config = ":linux_riscv64_toolchain_config",
all_files = ":empty",
compiler_files = ":empty",
Expand Down
71 changes: 41 additions & 30 deletions worker/toolchains/riscv/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ all_compile_actions = [
ACTION_NAMES.c_compile,
]

_SDK_BASE = "/opt/riscv-sdk"
_SDK_HOST = _SDK_BASE + "/sysroots/x86_64-pokysdk-linux"
_SDK_TARGET = _SDK_BASE + "/sysroots/riscv64-poky-linux"
_TOOLCHAIN_BIN = _SDK_HOST + "/usr/bin/riscv64-poky-linux"

def _impl(ctx):
tool_paths = [
tool_path(
name = "gcc",
path = "/usr/bin/riscv64-linux-gnu-g++",
path = _TOOLCHAIN_BIN + "/riscv64-poky-linux-gcc",
),
tool_path(
name = "ld",
path = "/usr/bin/riscv64-linux-gnu-ld",
path = _TOOLCHAIN_BIN + "/riscv64-poky-linux-ld",
),
tool_path(
name = "ar",
path = "/usr/bin/riscv64-linux-gnu-ar",
path = _TOOLCHAIN_BIN + "/riscv64-poky-linux-ar",
),
tool_path(
name = "cpp",
Expand All @@ -42,19 +47,37 @@ def _impl(ctx):
),
tool_path(
name = "nm",
path = "/usr/bin/riscv64-linux-gnu-nm",
path = _TOOLCHAIN_BIN + "/riscv64-poky-linux-nm",
),
tool_path(
name = "objdump",
path = "/usr/bin/riscv64-linux-gnu-objdump",
path = _TOOLCHAIN_BIN + "/riscv64-poky-linux-objdump",
),
tool_path(
name = "strip",
path = "/usr/bin/riscv64-linux-gnu-strip",
path = _TOOLCHAIN_BIN + "/riscv64-poky-linux-strip",
),
]

features = [
feature(
name = "default_compile_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
flags = [
"--sysroot=" + _SDK_TARGET,
"-O2",
"-pipe",
],
),
],
),
],
),
feature(
name = "default_linker_flags",
enabled = True,
Expand All @@ -64,16 +87,10 @@ def _impl(ctx):
flag_groups = [
flag_group(
flags = [
"-L/usr/riscv64-linux-gnu/lib",
"-Wl,-rpath=/usr/riscv64-linux-gnu/lib",
"-Wl,--start-group",
"-lprometheus-cpp-push",
"-lprometheus-cpp-core",
"-lcurl",
"-lssl",
"-lcrypto",
"-lz",
"-Wl,--end-group",
"--sysroot=" + _SDK_TARGET,
"-L" + _SDK_TARGET + "/usr/lib",
"-Wl,-rpath=" + _SDK_TARGET + "/usr/lib",
"-lstdc++",
],
),
],
Expand All @@ -90,9 +107,6 @@ def _impl(ctx):
flag_group(
flags = [
"-std=c++17",
"-isystem/usr/riscv64-linux-gnu/include/c++/11",
"-isystem/usr/riscv64-linux-gnu/include/c++/11/riscv64-linux-gnu",
"-isystem/usr/lib/gcc-cross/riscv64-linux-gnu/11/include",
],
),
],
Expand All @@ -105,27 +119,24 @@ def _impl(ctx):
ctx = ctx,
features = features,
cxx_builtin_include_directories = [
"/usr/riscv64-linux-gnu/include/c++/11",
"/usr/riscv64-linux-gnu/include/c++/11/riscv64-linux-gnu",
"/usr/lib/gcc-cross/riscv64-linux-gnu/11/include",
"/usr/lib/gcc-cross/riscv64-linux-gnu/11/include-fixed",
"/usr/riscv64-linux-gnu/include",
"/usr/include",
"/usr/local/include",
_SDK_HOST + "/usr/lib/riscv64-poky-linux/gcc/riscv64-poky-linux/13.4.0/include",
_SDK_TARGET + "/usr/include/c++/13.4.0",
_SDK_TARGET + "/usr/include/c++/13.4.0/riscv64-poky-linux",
_SDK_TARGET + "/usr/include",
],
toolchain_identifier = "riscv-toolchain",
toolchain_identifier = "riscv-yocto-toolchain",
host_system_name = "local",
target_system_name = "riscv64-linux-gnu",
target_system_name = "riscv64-poky-linux",
target_cpu = "riscv64",
target_libc = "glibc",
compiler = "gcc",
abi_version = "lp64d",
abi_libc_version = "glibc_2.36",
abi_libc_version = "glibc_2.39",
tool_paths = tool_paths,
)

cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
)
Loading