Skip to content

Commit

Permalink
switch to action configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ewfuentes committed Nov 17, 2024
1 parent 6ba9fc8 commit 47522c7
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 52 deletions.
8 changes: 0 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.16/rules_cc-0.0.16.tar.gz"],
sha256 = "bbf1ae2f83305b7053b11e4467d317a7ba3517a12cef608543c1b1c5bf48a4df",
strip_prefix = "rules_cc-0.0.16",
)


http_archive(
name = "platforms",
urls = [
Expand Down
8 changes: 0 additions & 8 deletions third_party/BUILD.opencv
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ SHARED_LIBS = [
"libopencv_rgbd.so",
]

cc_library(
name = "opencv_deps",
linkopts = [
"-lstdc++",
]
)

cmake(
name = "opencv",
generate_args = [
Expand All @@ -40,7 +33,6 @@ cmake(
generate_crosstool_file = False,
lib_source = "@opencv//:all",
includes = ["opencv4"],
deps = [":opencv_deps"],
out_shared_libs = SHARED_LIBS +
[lib + ".407" for lib in SHARED_LIBS],
visibility = ["//visibility:public"],
Expand Down
138 changes: 102 additions & 36 deletions toolchain/gcc_toolchain_config.bzl
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "feature", "flag_group", "flag_set", "tool_path")
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"action_config", "feature", "flag_group", "flag_set", "tool_path", "tool", "variable_with_value")

def _impl(ctx):
gcc_version = ctx.attr.gcc_version
tool_paths = [
tool_path(
name = "gcc",
path = "/usr/bin/gcc-{}".format(gcc_version),
),
tool_path(
name = "ar",
path = "/usr/bin/ar",
),
tool_path(
name = "ld",
path = "/usr/bin/ld.gold",
),
tool_path(
name = "cpp",
path = "/usr/bin/g++-{}".format(gcc_version),
),
tool_path(
name = "gcov",
path = "/bin/false",
),
tool_path(
name = "nm",
path = "/bin/false",
),
tool_path(
name = "objdump",
path = "/bin/false",
),
tool_path(
name = "strip",
path = "/bin/false",
),
]
all_link_actions = [
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.cpp_link_dynamic_library,
Expand All @@ -47,6 +14,52 @@ def _impl(ctx):
ACTION_NAMES.c_compile,
ACTION_NAMES.cpp_compile,
]
action_configs = [
action_config(
action_name = ACTION_NAMES.preprocess_assemble,
tools = [tool(path="/usr/bin/gcc-{}".format(gcc_version))],
),
action_config(
action_name = ACTION_NAMES.assemble,
tools = [tool(path="/usr/bin/gcc-{}".format(gcc_version))],
),
action_config(
action_name = ACTION_NAMES.c_compile,
tools = [tool(path="/usr/bin/gcc-{}".format(gcc_version))],
implies = [
"c_compile_flags"
],
),
action_config(
action_name = ACTION_NAMES.cpp_compile,
tools = [tool(path="/usr/bin/g++-{}".format(gcc_version))],
# implies = [
# "cpp_compile_flags"
# ],
),
action_config(
action_name = ACTION_NAMES.cpp_link_executable,
tools = [tool(path="/usr/bin/g++-{}".format(gcc_version))],
# implies = [
# "default_linker_flags"
# ],
),
action_config(
action_name = ACTION_NAMES.cpp_link_dynamic_library,
tools = [tool(path="/usr/bin/g++-{}".format(gcc_version))],
# implies = [
# "default_linker_flags"
# ],
),
action_config(
action_name = ACTION_NAMES.cpp_link_static_library,
tools = [tool(path="/usr/bin/ar")],
implies = [
"archiver_flags"
],
),
]

features = [
feature(
name = "default_linker_flags",
Expand Down Expand Up @@ -154,11 +167,65 @@ def _impl(ctx):
)
]
),
feature(
name = "archiver_flags",
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
flags = [
"rcsD",
"%{output_execpath}",
],
expand_if_available = "output_execpath",
),
],
),
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
iterate_over = "libraries_to_link",
flag_groups = [
flag_group(
flags = ["%{libraries_to_link.name}"],
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file",
),
),
flag_group(
flags = ["%{libraries_to_link.object_files}"],
iterate_over = "libraries_to_link.object_files",
expand_if_equal = variable_with_value(
name = "libraries_to_link.type",
value = "object_file_group",
),
),
],
expand_if_available = "libraries_to_link",
),
],
),
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
flags = ["%{user_archiver_flags}"],
iterate_over = "user_archiver_flags",
expand_if_available = "user_archiver_flags",
),
],
),
],
)
]

return cc_common.create_cc_toolchain_config_info(
ctx=ctx,
features = features,
action_configs = action_configs,
cxx_builtin_include_directories = [
"/usr/include",
"/usr/include/c++/{}".format(gcc_version),
Expand All @@ -172,7 +239,6 @@ def _impl(ctx):
compiler="gcc",
abi_version="unknown",
abi_libc_version="unknown",
tool_paths = tool_paths
)

gcc_toolchain_config = rule(
Expand Down

0 comments on commit 47522c7

Please sign in to comment.