Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix es2k bazel build #125

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 4 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Copyright 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

load("//bazel:rules.bzl", "krnlmon_cc_library")

package(default_visibility = ["//visibility:public"])

load("//bazel:defs.bzl", "TARGET_DEFINES")
Expand All @@ -23,7 +25,7 @@ cc_shared_library(
],
)

cc_library(
krnlmon_cc_library(
name = "krnlmon_main",
srcs = ["krnlmon_main.cc"],
hdrs = ["krnlmon_main.h"],
Expand All @@ -33,10 +35,9 @@ cc_library(
],
)

cc_library(
krnlmon_cc_library(
name = "krnlmon_options",
srcs = ["krnlmon_options.h"],
defines = TARGET_DEFINES,
)

cc_binary(
Expand Down
8 changes: 8 additions & 0 deletions bazel/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ TARGET_DEFINES = select(
},
no_match_error = NO_MATCH_ERROR,
)

LNW_DEFINES = select(
{
"//flags:lnw_v2": ["LNW_V2"],
"//flags:lnw_v3": ["LNW_V3"],
"//conditions:default": [],
},
)
4 changes: 2 additions & 2 deletions bazel/rules/library_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel:defs.bzl", "TARGET_DEFINES")
load("//bazel:defs.bzl", "LNW_DEFINES", "TARGET_DEFINES")

def krnlmon_cc_library(
name,
Expand All @@ -31,7 +31,7 @@ def krnlmon_cc_library(
hdrs = hdrs,
# alwayslink = alwayslink,
copts = copts,
defines = TARGET_DEFINES + defines,
defines = TARGET_DEFINES + LNW_DEFINES + defines,
include_prefix = include_prefix,
includes = includes,
strip_include_prefix = strip_include_prefix,
Expand Down
28 changes: 28 additions & 0 deletions bazel/rules/lnw_version_flag.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# //bazel/rules:lnw_version_flag.bzl

# Copyright 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# Defines a build_setting rule for the Linux Networking version.
# Used to define the //flags:lnw_version command-line flag.

# https://github.com/bazelbuild/examples/tree/HEAD/configurations/basic_build_setting

LinuxNetworkingVersion = provider(doc = "", fields = ["version"])

valid_versions = [2, 3]

def _impl(ctx):
raw_value = ctx.build_setting_value
if raw_value not in valid_versions:
msg = str(ctx.label) + ": lnw_version accepts values {" + \
",".join([str(x) for x in valid_versions]) + \
"} but was set to " + str(raw_value)
fail(msg)

return LinuxNetworkingVersion(version = raw_value)

lnw_version_flag = rule(
implementation = _impl,
build_setting = config.int(flag = True),
)
28 changes: 27 additions & 1 deletion flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
package(default_visibility = ["//visibility:public"])

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//bazel:rules/lnw_version_flag.bzl", "lnw_version_flag")

# Define "--//flags:ovs" command-line flag
bool_flag(
name = "ovs",
build_setting_default = True,
build_setting_default = False,
)

# Enabled by "--//flags:ovs=true"
Expand All @@ -36,3 +37,28 @@ config_setting(
"target": "es2k",
},
)

lnw_version_flag(
name = "lnw_version",
build_setting_default = 3,
)

config_setting(
name = "lnw_v2",
define_values = {
"target": "es2k",
},
flag_values = {
"lnw_version": "2",
},
)

config_setting(
name = "lnw_v3",
define_values = {
"target": "es2k",
},
flag_values = {
"lnw_version": "3",
},
)
2 changes: 1 addition & 1 deletion krnlmon_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define LAG_OPTION 1

#else
#error "Krnlmon only supports DPDK and ES2K"
#error "ASSERT: Unknown TARGET type!"
#endif

#endif // KRNLMON_OPTIONS_H_
4 changes: 2 additions & 2 deletions switchapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ load("//bazel:sde.bzl", "TARGET_SDE")

package(default_visibility = ["//visibility:public"])

PD_ROUTING_DEPS = select(
SWITCH_PD_ROUTING_HDR = select(
{
"//flags:dpdk_target": ["//switchapi/dpdk:switch_pd_routing_hdr"],
"//flags:es2k_target": ["//switchapi/es2k:switch_pd_routing_hdr"],
Expand Down Expand Up @@ -196,7 +196,7 @@ krnlmon_cc_library(
krnlmon_cc_library(
name = "switch_pd_routing",
hdrs = ["switch_pd_routing.h"],
deps = PD_ROUTING_DEPS,
deps = SWITCH_PD_ROUTING_HDR,
)

krnlmon_cc_library(
Expand Down
78 changes: 34 additions & 44 deletions switchapi/es2k/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ load("//bazel:rules.bzl", "krnlmon_cc_library")

package(default_visibility = ["//visibility:public"])

SWITCH_PD_LAG = select({
"//flags:lnw_v2": ["//switchapi/es2k/lnw_v2:switch_pd_lag"],
"//flags:lnw_v3": ["//switchapi/es2k/lnw_v3:switch_pd_lag"],
})

SWITCH_PD_LAG_HDR = select({
"//flags:lnw_v2": ["//switchapi/es2k/lnw_v2:switch_pd_lag_hdr"],
"//flags:lnw_v3": ["//switchapi/es2k/lnw_v3:switch_pd_lag_hdr"],
})

SWITCH_PD_P4_NAME_ROUTING = select({
"//flags:lnw_v2": ["//switchapi/es2k/lnw_v2:switch_pd_p4_name_routing"],
"//flags:lnw_v3": ["//switchapi/es2k/lnw_v3:switch_pd_p4_name_routing"],
})

SWITCH_PD_ROUTING = select({
"//flags:lnw_v2": ["//switchapi/es2k/lnw_v2:switch_pd_routing"],
"//flags:lnw_v3": ["//switchapi/es2k/lnw_v3:switch_pd_routing"],
})

krnlmon_cc_library(
name = "switch_config",
srcs = ["switch_config.c"],
Expand Down Expand Up @@ -55,11 +75,10 @@ krnlmon_cc_library(
"//switchapi:switch_internal",
"//switchapi:switch_l3",
"//switchapi:switch_nhop_int",
"//switchapi:switch_pd_routing",
"//switchapi:switch_rmac_int",
"//switchapi:switch_table",
"//switchapi:switch_types_int",
],
] + SWITCH_PD_ROUTING,
)

krnlmon_cc_library(
Expand All @@ -82,19 +101,18 @@ krnlmon_cc_library(
"//switchapi:switch_internal",
"//switchapi:switch_l3",
"//switchapi:switch_nhop_int",
"//switchapi:switch_pd_routing",
"//switchapi:switch_rmac_int",
"//switchapi:switch_table",
],
] + SWITCH_PD_ROUTING,
)

krnlmon_cc_library(
name = "switch_lag",
srcs = ["switch_lag.c"],
deps = [
":switch_pd_lag",
":switch_pd_lag_hdr",
"//switchapi:switch_lag",
],
] + SWITCH_PD_LAG,
)

krnlmon_cc_library(
Expand All @@ -108,11 +126,16 @@ krnlmon_cc_library(
],
)

krnlmon_cc_library(
name = "switch_pd_lag_hdr",
hdrs = ["switch_pd_lag.h"],
deps = SWITCH_PD_LAG_HDR,
)

krnlmon_cc_library(
name = "switch_nhop",
srcs = ["switch_nhop.c"],
deps = [
":switch_pd_routing",
"//switchapi:switch_device",
"//switchapi:switch_handle_int",
"//switchapi:switch_internal",
Expand All @@ -121,7 +144,7 @@ krnlmon_cc_library(
"//switchapi:switch_nhop_int",
"//switchapi:switch_rif_int",
"//switchapi:switch_table",
],
] + SWITCH_PD_ROUTING,
)

krnlmon_cc_library(
Expand All @@ -141,21 +164,6 @@ krnlmon_cc_library(
],
)

krnlmon_cc_library(
name = "switch_pd_lag",
srcs = ["switch_pd_lag.c"],
hdrs = ["switch_pd_lag.h"],
deps = [
":switch_pd_p4_name_mapping",
":switch_pd_utils",
"//switchapi:switch_device",
"//switchapi:switch_handle",
"//switchapi:switch_internal",
"//switchapi:switch_lag",
"@local_es2k_bin//:sde_hdrs",
],
)

krnlmon_cc_library(
name = "switch_pd_p4_name_mapping",
hdrs = ["switch_pd_p4_name_mapping.h"],
Expand All @@ -164,22 +172,7 @@ krnlmon_cc_library(
krnlmon_cc_library(
name = "switch_pd_routing_hdr",
hdrs = ["switch_pd_routing.h"],
)

krnlmon_cc_library(
name = "switch_pd_routing",
srcs = ["switch_pd_routing.c"],
deps = [
":switch_pd_p4_name_mapping",
":switch_pd_routing_hdr",
":switch_pd_utils",
"//switchapi:switch_base_types",
"//switchapi:switch_handle",
"//switchapi:switch_l3",
"//switchapi:switch_nhop",
"//switchapi:switch_nhop_int",
"//switchapi:switch_rmac_int",
],
deps = SWITCH_PD_P4_NAME_ROUTING,
)

krnlmon_cc_library(
Expand Down Expand Up @@ -229,12 +222,11 @@ krnlmon_cc_library(
name = "switch_rmac",
srcs = ["switch_rmac.c"],
deps = [
":switch_pd_routing",
"//switchapi:switch_device",
"//switchapi:switch_internal",
"//switchapi:switch_rmac",
"//switchapi:switch_table",
],
] + SWITCH_PD_ROUTING,
)

krnlmon_cc_library(
Expand Down Expand Up @@ -297,8 +289,6 @@ cc_library(
":switch_neighbor",
":switch_nhop",
":switch_pd_fdb",
":switch_pd_lag",
":switch_pd_routing",
":switch_pd_tunnel",
":switch_pd_utils",
":switch_rif",
Expand All @@ -307,5 +297,5 @@ cc_library(
":switch_tunnel",
":switch_vrf",
":switchapi_utils",
],
] + SWITCH_PD_LAG + SWITCH_PD_ROUTING,
)
1 change: 1 addition & 0 deletions switchapi/es2k/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target_sources(switchapi_o PRIVATE
switch_neighbor.c
switch_nhop.c
switch_pd_fdb.c
switch_pd_lag.h
switch_pd_p4_name_mapping.h
switch_pd_tunnel.c
switch_pd_utils.c
Expand Down
49 changes: 49 additions & 0 deletions switchapi/es2k/lnw_v2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# //switchapi/es2k/lnw_v2/BUILD.bazel

# Copyright 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

load("//bazel:rules.bzl", "krnlmon_cc_library")

package(default_visibility = ["//visibility:public"])

krnlmon_cc_library(
name = "switch_pd_lag_hdr",
hdrs = ["switch_pd_lag.h"],
)

krnlmon_cc_library(
name = "switch_pd_lag",
srcs = ["switch_pd_lag.c"],
deps = [
":switch_pd_lag_hdr",
"//switchapi:switch_device",
"//switchapi:switch_handle",
"//switchapi:switch_internal",
"//switchapi:switch_lag",
"//switchapi/es2k:switch_pd_utils",
"//switchapi/es2k:switch_pd_p4_name_mapping",
"@local_es2k_bin//:sde_hdrs",
],
)

krnlmon_cc_library(
name = "switch_pd_p4_name_routing",
hdrs = ["switch_pd_p4_name_routing.h"],
)

krnlmon_cc_library(
name = "switch_pd_routing",
srcs = ["switch_pd_routing.c"],
deps = [
"//switchapi:switch_base_types",
"//switchapi:switch_handle",
"//switchapi:switch_l3",
"//switchapi:switch_nhop",
"//switchapi:switch_nhop_int",
"//switchapi:switch_rmac_int",
"//switchapi/es2k:switch_pd_p4_name_mapping",
"//switchapi/es2k:switch_pd_routing_hdr",
"//switchapi/es2k:switch_pd_utils",
],
)
1 change: 0 additions & 1 deletion switchapi/es2k/lnw_v2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
target_sources(switchapi_o PRIVATE
switch_pd_p4_name_routing.h
switch_pd_routing.c
switch_pd_routing.h
switch_pd_lag.c
switch_pd_lag.h
)
Expand Down
3 changes: 2 additions & 1 deletion switchapi/es2k/lnw_v2/switch_pd_lag.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2023 Intel Corporation.
* Copyright 2023-2024 Intel Corporation.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading