Skip to content

Commit 0e95362

Browse files
committed
Refactor inclusion of compiler libraries
1 parent d49d68d commit 0e95362

10 files changed

Lines changed: 57 additions & 54 deletions

File tree

examples/MODULE.bazel.lock

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/gcc.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def _get_toolchains(tags):
187187
"sdk_version": tag.sdk_version,
188188
"sdp_to_link": tag.sdp_to_link,
189189
"sdp_version": tag.sdp_version,
190+
"tc_compiler_library_search_paths": [],
190191
"tc_cpu": tag.target_cpu,
191192
"tc_extra_c_compile_flags": tag.extra_c_compile_flags,
192193
"tc_extra_compile_flags": tag.extra_compile_flags,
@@ -232,6 +233,8 @@ def _create_and_link_sdp(toolchain_info):
232233
toolchain_info["tc_extra_link_flags"] = matrix["extra_link_flags"]
233234
if "gcc_version" in matrix and not toolchain_info["gcc_version"]:
234235
toolchain_info["gcc_version"] = matrix["gcc_version"]
236+
if "compiler_library_search_paths" in matrix:
237+
toolchain_info["tc_compiler_library_search_paths"] = matrix["compiler_library_search_paths"]
235238

236239
return {
237240
"build_file": matrix["build_file"],
@@ -324,6 +327,7 @@ def _impl(mctx):
324327
license_path = toolchain_info["tc_license_path"],
325328
sdk_version = toolchain_info["sdk_version"],
326329
sdp_version = toolchain_info["sdp_version"],
330+
tc_compiler_library_search_paths = toolchain_info["tc_compiler_library_search_paths"],
327331
tc_cpu = toolchain_info["tc_cpu"],
328332
tc_identifier = toolchain_info["tc_identifier"],
329333
tc_os = toolchain_info["tc_os"],

packages/linux/aarch64/autosd/10.0/autosd.BUILD

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ filegroup(
5050
srcs = ["usr/bin/strip"],
5151
)
5252

53-
filegroup(
54-
name = "ld_library_paths",
55-
srcs = [],
56-
)
57-
5853
# The sysroot for AutoSD is the entire extracted directory
5954
# since it contains usr/ and lib64/ at the root
6055
filegroup(

packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ package(default_visibility = ["//visibility:public"])
1717

1818
filegroup(
1919
name = "all_files",
20-
srcs = glob(["*/**/*"], exclude = ["usr/share/ca-certificates/**","usr/lib/ssl/certs/**", "lib/ssl/certs/**", "etc/ssl/certs/**", "usr/share/man/**", "usr/share/perl/**", "var/lib/**"]),
20+
srcs = glob(
21+
["*/**/*"],
22+
exclude = [
23+
"usr/share/ca-certificates/**",
24+
"usr/lib/ssl/certs/**",
25+
"lib/ssl/certs/**",
26+
"etc/ssl/certs/**",
27+
"usr/share/man/**",
28+
"usr/share/perl/**",
29+
"var/lib/**",
30+
],
31+
),
2132
)
2233

2334
filegroup(
@@ -55,11 +66,6 @@ filegroup(
5566
srcs = ["usr/bin/lisa-elf-enabler"],
5667
)
5768

58-
filegroup(
59-
name = "ld_library_paths",
60-
srcs = ["usr/lib/x86_64-linux-gnu", "lib/x86_64-linux-gnu"],
61-
)
62-
6369
# The sysroot for EBcLfSA is the entire extracted directory
6470
filegroup(
6571
name = "sysroot_dir",

packages/linux/aarch64/gcc/12.2.0/gcc.BUILD

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ filegroup(
5050
srcs = ["bin/aarch64-unknown-linux-gnu-strip"],
5151
)
5252

53-
filegroup(
54-
name = "ld_library_paths",
55-
srcs = [],
56-
)
57-
5853
filegroup(
5954
name = "sysroot_dir",
6055
srcs = ["aarch64-unknown-linux-gnu/sysroot"],
61-
)
56+
)

packages/linux/x86_64/autosd/10.0/autosd.BUILD

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ filegroup(
5050
srcs = ["usr/bin/strip"],
5151
)
5252

53-
filegroup(
54-
name = "ld_library_paths",
55-
srcs = [],
56-
)
57-
5853
# The sysroot for AutoSD is the entire extracted directory
5954
# since it contains usr/ and lib64/ at the root
6055
filegroup(
@@ -67,10 +62,10 @@ filegroup(
6762
filegroup(
6863
name = "cxx_builtin_include_directories",
6964
srcs = [
70-
"usr/lib/gcc/x86_64-redhat-linux/14/include",
7165
"usr/include",
7266
"usr/include/c++/14",
73-
"usr/include/c++/14/x86_64-redhat-linux",
7467
"usr/include/c++/14/backward",
68+
"usr/include/c++/14/x86_64-redhat-linux",
69+
"usr/lib/gcc/x86_64-redhat-linux/14/include",
7570
],
7671
)

packages/linux/x86_64/gcc/12.2.0/gcc.BUILD

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ filegroup(
5050
srcs = ["bin/x86_64-unknown-linux-gnu-strip"],
5151
)
5252

53-
filegroup(
54-
name = "ld_library_paths",
55-
srcs = [],
56-
)
57-
5853
filegroup(
5954
name = "sysroot_dir",
6055
srcs = ["x86_64-unknown-linux-gnu/sysroot"],
61-
)
56+
)

packages/version_matrix.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ VERSION_MATRIX = {
178178
"-static",
179179
"--no-canonical-prefixes",
180180
],
181+
"compiler_library_search_paths": [
182+
"external/%{toolchain_pkg}%/usr/lib/x86_64-linux-gnu",
183+
"external/%{toolchain_pkg}%/lib/x86_64-linux-gnu",
184+
],
181185
"strip_prefix": "fastdev-sdk-ubuntu-ebclfsa-ebcl-qemuarm64",
182186
"sha256": "f44286c28d831dc40acdac08ef49f38a2e9cbb057bea38c25834964693785287",
183187
"url": "https://github.com/Elektrobit/eb_corbos_toolkit/releases/download/v2.0.0-beta1/fastdev-sdk-ubuntu-ebclfsa-ebcl-qemuarm64.tar.gz",

rules/gcc.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ cc_toolchain_config(
5050
cxx_binary = "@{tc_pkg_repo}//:cxx",
5151
gcov_binary = "@{tc_pkg_repo}//:gcov",
5252
strip_binary = "@{tc_pkg_repo}//:strip",
53-
ld_library_path_dirs = "@{tc_pkg_repo}//:ld_library_paths",
5453
sysroot = "@{tc_pkg_repo}//:sysroot_dir",
5554
target_cpu = "{tc_cpu}",
5655
target_os = "{tc_os}",
@@ -157,8 +156,11 @@ def _impl(rctx):
157156
extra_c_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_c_compile_flags))
158157
extra_cxx_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_cxx_compile_flags))
159158
extra_link_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_link_flags))
159+
compiler_library_search_paths = replace_placeholder(rctx.attr.tc_compiler_library_search_paths)
160160

161161
template_dict = {
162+
"%{compiler_library_search_paths_switch}": "True" if len(rctx.attr.tc_compiler_library_search_paths) else "False",
163+
"%{compiler_library_search_paths}": ":".join(["/proc/self/cwd/" + entry for entry in compiler_library_search_paths]),
162164
"%{extra_c_compile_flags_switch}": "True" if len(rctx.attr.extra_c_compile_flags) else "False",
163165
"%{extra_c_compile_flags}": extra_c_compile_flags,
164166
"%{extra_compile_flags_switch}": "True" if len(rctx.attr.extra_compile_flags) else "False",
@@ -230,6 +232,7 @@ gcc_toolchain = repository_rule(
230232
"license_path": attr.string(doc = "Lincese path"),
231233
"sdk_version": attr.string(doc = "SDK version string"),
232234
"sdp_version": attr.string(doc = "SDP version string"),
235+
"tc_compiler_library_search_paths": attr.string_list(doc = "Additional search path which compiler needs."),
233236
"tc_cpu": attr.string(doc = "Target platform CPU."),
234237
"tc_identifier": attr.string(doc = "Constraint to be used for toolchain definition (e.g. gcc_12.2.0)."),
235238
"tc_os": attr.string(doc = "Target platform OS."),

templates/linux/cc_toolchain_config.bzl.template

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ def _impl(ctx):
160160
strip_action,
161161
]
162162

163+
# Set LD_LIBRARY_PATH environment variable for all actions
164+
# This is needed by some toolchains since these libraries are not in `rpath` of compiler binary
165+
# which are needed to run it.
166+
compiler_library_search_paths = "%{compiler_library_search_paths}"
167+
compiler_library_search_paths_feature = feature(
168+
name = "compiler_library_search_paths",
169+
enabled = %{compiler_library_search_paths_switch},
170+
env_sets = [
171+
env_set(
172+
actions = all_actions,
173+
env_entries = [env_entry(key = "LD_LIBRARY_PATH", value = compiler_library_search_paths)] if compiler_library_search_paths != "" else [],
174+
),
175+
],
176+
)
177+
163178
unfiltered_compile_flags_feature = feature(
164179
name = "unfiltered_compile_flags",
165180
enabled = True,
@@ -617,6 +632,7 @@ def _impl(ctx):
617632
# after a command line parameter from a feature at the beginning of the list.
618633

619634
features = [
635+
compiler_library_search_paths_feature,
620636
sanitizer_feature,
621637
asan_feature,
622638
lsan_feature,
@@ -657,26 +673,6 @@ def _impl(ctx):
657673
if ctx.attr.sysroot != None:
658674
sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path
659675

660-
# Get ld_library_paths from attribute if provided and set LD_LIBRARY_PATH environment variable for actions
661-
if hasattr(ctx.attr, "ld_library_path_dirs") and ctx.attr.ld_library_path_dirs and ctx.attr.ld_library_path_dirs[DefaultInfo].files.to_list():
662-
values = ["/proc/self/cwd/" + entry.path for entry in ctx.attr.ld_library_path_dirs[DefaultInfo].files.to_list()]
663-
ld_library_path = ":".join(values)
664-
665-
sdk_env_feature = feature(
666-
name = "sdk_env",
667-
enabled = True,
668-
env_sets = [
669-
env_set(
670-
actions = all_actions,
671-
env_entries = [
672-
env_entry(key = "LD_LIBRARY_PATH", value = ld_library_path),
673-
],
674-
),
675-
],
676-
)
677-
678-
features.append(sdk_env_feature)
679-
680676
return cc_common.create_cc_toolchain_config_info(
681677
ctx = ctx,
682678
abi_version = "%{tc_abi_version}",
@@ -709,6 +705,5 @@ cc_toolchain_config = rule(
709705
"host_dir": attr.label(default = None),
710706
"target_dir": attr.label(default = None),
711707
"cxx_builtin_include_directories": attr.label(allow_files = True, default = None),
712-
"ld_library_path_dirs": attr.label(allow_files = True, default = None),
713708
},
714709
)

0 commit comments

Comments
 (0)