Skip to content

Commit f642ff5

Browse files
Add autosd10 support (#23)
* Allow providing extra C/C++ flags As well as allowing to have a %{toolchain_pkg}% placeholder in the flags that would be replaced with the canonical name of the toolchain. * Enable header path normalization feature Needed for toolchains like autosd. * Pass include_directories from the toolchain So that a toolchain can define it own include directories. * Various linker flags tweaks Mostly adding a sysroot if provided as well as tweaking the default flags handling so that a toolchain can override the linking flags. Given that the default ones are not compatible with autosd. * Allow toolchains to define their own build/link flags In versions_matrix for now, no idea if we could that better... * packages: Add AutoSD 10 support
1 parent dac1529 commit f642ff5

9 files changed

Lines changed: 339 additions & 17 deletions

File tree

examples/MODULE.bazel

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,17 @@ gcc.toolchain(
139139
# use_system_toolchain = True,
140140
# )
141141

142-
# TODO: Not yet supported
143142
# *******************************************************************************
144-
# Setting AutoSD GCC (CPU:x86_64|OS:Linux|V:unknown|ES:autosd)
143+
# Setting AutoSD 10 GCC (CPU:x86_64|OS:Linux|V:autosd-10.0|ES:autosd)
145144
# *******************************************************************************
146-
# gcc.toolchain(
147-
# name = "score_autosd_9_toolchain",
148-
# target_cpu = "x86_64",
149-
# target_os = "linux",
150-
# runtime_ecosystem = "autosd",
151-
# version = "9",
152-
# use_system_toolchain = True,
153-
# )
145+
gcc.toolchain(
146+
name = "score_autosd_10_toolchain",
147+
target_cpu = "x86_64",
148+
target_os = "linux",
149+
runtime_ecosystem = "autosd",
150+
version = "autosd-10.0",
151+
use_default_package = True,
152+
)
154153

155154
use_repo(
156155
gcc,
@@ -159,4 +158,5 @@ use_repo(
159158
"my_toolchain",
160159
"score_qcc_toolchain",
161160
"score_qcc_arm_toolchain",
161+
"score_autosd_10_toolchain",
162162
)

extensions/gcc.bzl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ _attrs_tc = {
115115
default = [],
116116
doc = "List of additional flags to be passed to compiler.",
117117
),
118+
"extra_c_compile_flags": attr.string_list(
119+
mandatory = False,
120+
default = [],
121+
doc = "List of additional flags to be passed to C compiler.",
122+
),
123+
"extra_cxx_compile_flags": attr.string_list(
124+
mandatory = False,
125+
default = [],
126+
doc = "List of additional flags to be passed to C++ compiler.",
127+
),
118128
"extra_link_flags": attr.string_list(
119129
mandatory = False,
120130
default = [],
@@ -163,6 +173,8 @@ def _get_toolchains(tags):
163173
"use_default_package": tag.use_default_package,
164174
"use_system_toolchain": tag.use_system_toolchain,
165175
"tc_extra_compile_flags": tag.extra_compile_flags,
176+
"tc_extra_c_compile_flags": tag.extra_c_compile_flags,
177+
"tc_extra_cxx_compile_flags": tag.extra_cxx_compile_flags,
166178
"tc_extra_link_flags": tag.extra_link_flags,
167179
"sdp_version": tag.sdp_version,
168180
"tc_license_info_variable": tag.license_info_variable,
@@ -192,6 +204,14 @@ def _create_and_link_sdp(toolchain_info):
192204
)
193205
matrix = VERSION_MATRIX[matrix_key]
194206
toolchain_info["sdp_to_link"] = pkg_name
207+
208+
if "extra_c_compile_flags" in matrix and not toolchain_info["tc_extra_c_compile_flags"]:
209+
toolchain_info["tc_extra_c_compile_flags"] = matrix["extra_c_compile_flags"]
210+
if "extra_cxx_compile_flags" in matrix and not toolchain_info["tc_extra_cxx_compile_flags"]:
211+
toolchain_info["tc_extra_cxx_compile_flags"] = matrix["extra_cxx_compile_flags"]
212+
if "extra_link_flags" in matrix and not toolchain_info["tc_extra_link_flags"]:
213+
toolchain_info["tc_extra_link_flags"] = matrix["extra_link_flags"]
214+
195215
return {
196216
"name": pkg_name,
197217
"url": matrix["url"],
@@ -250,6 +270,8 @@ def _impl(mctx):
250270
gcc_toolchain(
251271
name = toolchain_info["name"],
252272
extra_compile_flags = toolchain_info["tc_extra_compile_flags"],
273+
extra_c_compile_flags = toolchain_info["tc_extra_c_compile_flags"],
274+
extra_cxx_compile_flags = toolchain_info["tc_extra_cxx_compile_flags"],
253275
extra_link_flags = toolchain_info["tc_extra_link_flags"],
254276
license_info_variable = toolchain_info["tc_license_info_variable"],
255277
license_info_value = toolchain_info["tc_license_info_url"],
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
exports_files([
15+
"autosd.BUILD",
16+
])
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
"""Build file for AutoSD 10 GCC toolchain package"""
15+
16+
package(default_visibility = ["//visibility:public"])
17+
18+
filegroup(
19+
name = "all_files",
20+
srcs = glob(["*/**/*"]),
21+
)
22+
23+
filegroup(
24+
name = "bin",
25+
srcs = ["usr/bin"],
26+
)
27+
28+
filegroup(
29+
name = "ar",
30+
srcs = ["usr/bin/ar"],
31+
)
32+
33+
filegroup(
34+
name = "cc",
35+
srcs = ["usr/bin/gcc"],
36+
)
37+
38+
filegroup(
39+
name = "gcov",
40+
srcs = ["usr/bin/gcov"],
41+
)
42+
43+
filegroup(
44+
name = "cxx",
45+
srcs = ["usr/bin/g++"],
46+
)
47+
48+
filegroup(
49+
name = "strip",
50+
srcs = ["usr/bin/strip"],
51+
)
52+
53+
# The sysroot for AutoSD is the entire extracted directory
54+
# since it contains usr/ and lib64/ at the root
55+
filegroup(
56+
name = "sysroot_dir",
57+
srcs = glob([
58+
"usr/**",
59+
"lib64/**",
60+
]),
61+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
exports_files([
15+
"autosd.BUILD",
16+
])
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
"""Build file for AutoSD 10 GCC toolchain package"""
15+
16+
package(default_visibility = ["//visibility:public"])
17+
18+
filegroup(
19+
name = "all_files",
20+
srcs = glob(["*/**/*"]),
21+
)
22+
23+
filegroup(
24+
name = "bin",
25+
srcs = ["usr/bin"],
26+
)
27+
28+
filegroup(
29+
name = "ar",
30+
srcs = ["usr/bin/ar"],
31+
)
32+
33+
filegroup(
34+
name = "cc",
35+
srcs = ["usr/bin/gcc"],
36+
)
37+
38+
filegroup(
39+
name = "gcov",
40+
srcs = ["usr/bin/gcov"],
41+
)
42+
43+
filegroup(
44+
name = "cxx",
45+
srcs = ["usr/bin/g++"],
46+
)
47+
48+
filegroup(
49+
name = "strip",
50+
srcs = ["usr/bin/strip"],
51+
)
52+
53+
# The sysroot for AutoSD is the entire extracted directory
54+
# since it contains usr/ and lib64/ at the root
55+
filegroup(
56+
name = "sysroot_dir",
57+
srcs = ["."],
58+
)
59+
60+
# Builtin include directories for the compiler
61+
# List directory paths directly (like QNX does)
62+
filegroup(
63+
name = "cxx_builtin_include_directories",
64+
srcs = [
65+
"usr/lib/gcc/x86_64-redhat-linux/14/include",
66+
"usr/include",
67+
"usr/include/c++/14",
68+
"usr/include/c++/14/x86_64-redhat-linux",
69+
"usr/include/c++/14/backward",
70+
],
71+
)

packages/version_matrix.bzl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,56 @@ VERSION_MATRIX = {
3939
"strip_prefix": "installation",
4040
"sha256": "f2e0cb21c6baddbcb65f6a70610ce498e7685de8ea2e0f1648f01b327f6bac63",
4141
},
42+
"x86_64-linux-gcc-autosd-10.0": {
43+
"url": "https://github.com/eclipse-score/inc_os_autosd/releases/download/v0.1.0/autosd-toolchain-x86_64.tar.gz",
44+
"build_file": "@score_bazel_cpp_toolchains//packages/linux/x86_64/autosd/10.0:autosd.BUILD",
45+
"strip_prefix": "sysroot",
46+
"sha256": "472e312711efab98022b14f2af288d47e1891674eaf9ab6a0a8dec60cae0ac75",
47+
"extra_c_compile_flags": [
48+
"-nostdinc",
49+
"-isystem", "external/%{toolchain_pkg}%/usr/lib/gcc/x86_64-redhat-linux/14/include",
50+
"-isystem", "external/%{toolchain_pkg}%/usr/include",
51+
],
52+
"extra_cxx_compile_flags": [
53+
"-nostdinc++",
54+
"-isystem", "external/%{toolchain_pkg}%/usr/include/c++/14",
55+
"-isystem", "external/%{toolchain_pkg}%/usr/include/c++/14/x86_64-redhat-linux",
56+
"-isystem", "external/%{toolchain_pkg}%/usr/include/c++/14/backward",
57+
"-nostdinc",
58+
"-isystem", "external/%{toolchain_pkg}%/usr/lib/gcc/x86_64-redhat-linux/14/include",
59+
"-isystem", "external/%{toolchain_pkg}%/usr/include",
60+
],
61+
"extra_link_flags": [
62+
"-lm",
63+
"-ldl",
64+
"-lrt",
65+
"-lstdc++",
66+
],
67+
},
68+
"aarch64-linux-gcc-autosd-10.0": {
69+
"url": "https://github.com/eclipse-score/inc_os_autosd/releases/download/v0.1.0/autosd-toolchain-aarch64.tar.gz",
70+
"build_file": "@score_bazel_cpp_toolchains//packages/linux/aarch64/autosd/10.0:autosd.BUILD",
71+
"strip_prefix": "sysroot",
72+
"sha256": "b5128954339b9ace240de36233f910966c4760f70e4d4f2772033b3cb8d4ae22",
73+
"extra_c_compile_flags": [
74+
"-nostdinc",
75+
"-isystem", "external/%{toolchain_pkg}%/usr/lib/gcc/aarch64-redhat-linux/14/include",
76+
"-isystem", "external/%{toolchain_pkg}%/usr/include",
77+
],
78+
"extra_cxx_compile_flags": [
79+
"-nostdinc++",
80+
"-isystem", "external/%{toolchain_pkg}%/usr/include/c++/14",
81+
"-isystem", "external/%{toolchain_pkg}%/usr/include/c++/14/aarch64-redhat-linux",
82+
"-isystem", "external/%{toolchain_pkg}%/usr/include/c++/14/backward",
83+
"-nostdinc",
84+
"-isystem", "external/%{toolchain_pkg}%/usr/lib/gcc/aarch64-redhat-linux/14/include",
85+
"-isystem", "external/%{toolchain_pkg}%/usr/include",
86+
],
87+
"extra_link_flags": [
88+
"-lm",
89+
"-ldl",
90+
"-lrt",
91+
"-lstdc++",
92+
],
93+
},
4294
}

rules/gcc.bzl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,26 @@ def _impl(rctx):
115115
},
116116
)
117117

118-
extra_compile_flags = get_flag_groups(rctx.attr.extra_compile_flags)
119-
extra_link_flags = get_flag_groups(rctx.attr.extra_link_flags)
118+
# Get canonical repository name for the toolchain package
119+
# In bzlmod, repos created by module extensions follow the pattern: module++extension+repo_name
120+
# Get our own canonical name (e.g., "score_bazel_cpp_toolchains++gcc+score_autosd_10_toolchain")
121+
# and replace our repo name with the package repo name
122+
my_canonical_name = rctx.name
123+
if "++" in my_canonical_name:
124+
parts = my_canonical_name.rsplit("+", 1)
125+
prefix = parts[0] + "+"
126+
canonical_pkg_name = prefix + rctx.attr.tc_pkg_repo
127+
else:
128+
canonical_pkg_name = rctx.attr.tc_pkg_repo
129+
130+
# Replace %{toolchain_pkg}% placeholder in extra flags with canonical name
131+
def replace_placeholder(flags):
132+
return [flag.replace("%{toolchain_pkg}%", canonical_pkg_name) for flag in flags]
133+
134+
extra_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_compile_flags))
135+
extra_c_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_c_compile_flags))
136+
extra_cxx_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_cxx_compile_flags))
137+
extra_link_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_link_flags))
120138

121139

122140
template_dict = {
@@ -126,6 +144,10 @@ def _impl(rctx):
126144
"%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem,
127145
"%{extra_compile_flags_switch}": "True" if len(rctx.attr.extra_compile_flags) else "False",
128146
"%{extra_compile_flags}":extra_compile_flags,
147+
"%{extra_c_compile_flags_switch}": "True" if len(rctx.attr.extra_c_compile_flags) else "False",
148+
"%{extra_c_compile_flags}": extra_c_compile_flags,
149+
"%{extra_cxx_compile_flags_switch}": "True" if len(rctx.attr.extra_cxx_compile_flags) else "False",
150+
"%{extra_cxx_compile_flags}": extra_cxx_compile_flags,
129151
"%{extra_link_flags_switch}": "True" if len(rctx.attr.extra_link_flags) else "False",
130152
"%{extra_link_flags}": extra_link_flags,
131153
}
@@ -175,6 +197,8 @@ gcc_toolchain = repository_rule(
175197
"tc_os": attr.string(doc="Target platform OS."),
176198
"gcc_version": attr.string(doc="GCC version number"),
177199
"extra_compile_flags": attr.string_list(doc="Extra/Additional compile flags."),
200+
"extra_c_compile_flags": attr.string_list(doc="Extra/Additional C-specific compile flags."),
201+
"extra_cxx_compile_flags": attr.string_list(doc="Extra/Additional C++-specific compile flags."),
178202
"extra_link_flags": attr.string_list(doc="Extra/Additional link flags."),
179203
"sdp_version": attr.string(doc="SDP version number"),
180204
"license_path": attr.string(doc="Lincese path"),

0 commit comments

Comments
 (0)