Skip to content

Commit 0e88b63

Browse files
committed
Add support for libc++
And also add c++ hello world to ci
1 parent 3a73257 commit 0e88b63

File tree

9 files changed

+306
-1
lines changed

9 files changed

+306
-1
lines changed

BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ string_flag(
2727

2828
string_list_flag(
2929
name = "use_runtimes",
30-
build_setting_default = ["musl"],
30+
build_setting_default = [
31+
"musl",
32+
"libcxx",
33+
],
3134
visibility = ["//visibility:public"],
3235
)

MODULE.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ http_archive(
2020
url = "https://github.com/reutermj/toolchains_cc/releases/download/binaries/musl-1.2.5-r10-linux-x86_64.tar.xz",
2121
sha256 = "5c2ba292f20013f34f6553000171f488c38bcd497472fd0586d2374c447423ff",
2222
)
23+
http_archive(
24+
name = "libcxx-19.1.7-linux-x86_64",
25+
url = "https://github.com/reutermj/toolchains_cc/releases/download/binaries/libcxx-19.1.7-linux-x86_64.tar.xz",
26+
sha256 = "6d144468b2b8d0d0a9a50a4aacffaf5ed02d813009dbcbfb5d3c66856a5c9de9",
27+
)

Notes.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Notes on the implementation
2+
3+
4+
## libc++
5+
6+
### Incompatibility between libc++ from the llvm builds and musl
7+
8+
```
9+
error: "<locale.h> is not supported since libc++ has been configured without support for localization."
10+
```
11+
12+
You need to get a version of libc++ specifically compiled for musl. When configuring the libc++ cmake:
13+
14+
```
15+
-DLIBCXX_HAS_MUSL_LIBC=ON
16+
```
17+
18+
reference: https://github.com/dslm4515/CMLFS/issues/69

examples/hello_world/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ cc_binary(
22
name = "hello",
33
srcs = ["main.c"],
44
)
5+
6+
cc_binary(
7+
name = "hello++",
8+
srcs = ["main.cpp"],
9+
)

examples/hello_world/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
3+
int main() {
4+
std::cout << "Hello, World!" << std::endl;
5+
return 0;
6+
}

repo_gen/runtimes.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,72 @@
6565
}
6666
]
6767
}
68+
},
69+
{
70+
"name": "libcxx",
71+
"default-version": "19.1.7",
72+
"versions": [
73+
{
74+
"version": "19.1.7",
75+
"oses": [
76+
{
77+
"name": "linux",
78+
"archs": [
79+
{
80+
"name": "x86_64",
81+
"artifact-name": "libcxx-19.1.7-linux-x86_64.tar.xz",
82+
"sha256": "6d144468b2b8d0d0a9a50a4aacffaf5ed02d813009dbcbfb5d3c66856a5c9de9"
83+
}
84+
]
85+
}
86+
]
87+
}
88+
],
89+
"default-configuration": "shared",
90+
"configurations": {
91+
"all": [
92+
{
93+
"name": "shared",
94+
"actions": [
95+
{
96+
"name": "link_actions",
97+
"args": [
98+
"-L{lib}",
99+
"-lc++",
100+
"-lc++abi",
101+
"-lunwind",
102+
"-llzma"
103+
]
104+
},
105+
{
106+
"name": "link_executable_actions",
107+
"args": [
108+
"-L{lib}"
109+
]
110+
}
111+
]
112+
},
113+
{
114+
"name": "static",
115+
"actions": [
116+
{
117+
"name": "link_actions",
118+
"args": [
119+
"{lib}/libc++.a",
120+
"{lib}/libc++abi.a",
121+
"{lib}/libunwind.a",
122+
"{lib}/liblzma.a"
123+
]
124+
},
125+
{
126+
"name": "link_executable_actions",
127+
"args": [
128+
"-L{lib}"
129+
]
130+
}
131+
]
132+
}
133+
]
134+
}
68135
}
69136
]

runtimes/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list")
1010
cc_args_list(
1111
name = "args",
1212
args = [
13+
"//runtimes/libcxx:args",
1314
"//runtimes/musl:args",
1415
],
1516
visibility = ["//:__pkg__"],

runtimes/libcxx/19.1.7/BUILD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package(default_visibility = ["//:__subpackages__"])
2+
3+
alias(
4+
name = "include",
5+
actual = select({
6+
"//constraint:linux_x86_64": "@libcxx-19.1.7-linux-x86_64//:include",
7+
}),
8+
)
9+
10+
alias(
11+
name = "lib",
12+
actual = select({
13+
"//constraint:linux_x86_64": "@libcxx-19.1.7-linux-x86_64//:lib",
14+
}),
15+
)

runtimes/libcxx/BUILD

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
load("@bazel_skylib//lib:selects.bzl", "selects")
2+
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
3+
load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list")
4+
5+
cc_args_list(
6+
name = "args",
7+
args =
8+
select({
9+
":libcxx": [
10+
":arg-include",
11+
":arg-lib",
12+
":link_actions",
13+
":link_executable_actions",
14+
],
15+
"//conditions:default": [],
16+
}),
17+
visibility = ["//runtimes:__pkg__"],
18+
)
19+
20+
cc_args(
21+
name = "arg-include",
22+
actions = [
23+
"@rules_cc//cc/toolchains/actions:c_compile",
24+
"@rules_cc//cc/toolchains/actions:cpp_compile_actions",
25+
],
26+
args = [
27+
"-isystem",
28+
"{include}",
29+
],
30+
data = [
31+
":include",
32+
],
33+
format = {
34+
"include": ":include",
35+
},
36+
)
37+
38+
cc_args(
39+
name = "arg-lib",
40+
actions = [
41+
"@rules_cc//cc/toolchains/actions:link_actions",
42+
],
43+
args = [
44+
"-L{lib}",
45+
],
46+
data = [
47+
":lib",
48+
],
49+
format = {
50+
"lib": ":lib",
51+
},
52+
)
53+
54+
cc_args(
55+
name = "link_actions",
56+
actions = [
57+
"@rules_cc//cc/toolchains/actions:link_actions",
58+
],
59+
args = select({
60+
":libcxx-shared": [
61+
"-L{lib}",
62+
"-lc++",
63+
"-lc++abi",
64+
"-lunwind",
65+
"-llzma",
66+
],
67+
":libcxx-static": [
68+
"{lib}/libc++.a",
69+
"{lib}/libc++abi.a",
70+
"{lib}/libunwind.a",
71+
"{lib}/liblzma.a",
72+
],
73+
}),
74+
data = [
75+
":lib",
76+
],
77+
format = {
78+
"lib": ":lib",
79+
},
80+
)
81+
82+
cc_args(
83+
name = "link_executable_actions",
84+
actions = [
85+
"@rules_cc//cc/toolchains/actions:link_executable_actions",
86+
],
87+
args = select({
88+
":libcxx-shared": [
89+
"-L{lib}",
90+
],
91+
":libcxx-static": [
92+
"-L{lib}",
93+
],
94+
}),
95+
data = [
96+
":lib",
97+
],
98+
format = {
99+
"lib": ":lib",
100+
},
101+
)
102+
103+
alias(
104+
name = "include",
105+
actual = select({
106+
":libcxx-latest": "//runtimes/libcxx/19.1.7:include",
107+
":libcxx-19.1.7": "//runtimes/libcxx/19.1.7:include",
108+
}),
109+
)
110+
111+
alias(
112+
name = "lib",
113+
actual = select({
114+
":libcxx-latest": "//runtimes/libcxx/19.1.7:lib",
115+
":libcxx-19.1.7": "//runtimes/libcxx/19.1.7:lib",
116+
}),
117+
)
118+
119+
selects.config_setting_group(
120+
name = "libcxx",
121+
match_any = [
122+
":libcxx-latest",
123+
":libcxx-19.1.7",
124+
],
125+
)
126+
127+
selects.config_setting_group(
128+
name = "libcxx-shared",
129+
match_any = [
130+
":libcxx-shared-latest",
131+
":libcxx-shared-19.1.7",
132+
],
133+
)
134+
135+
selects.config_setting_group(
136+
name = "libcxx-static",
137+
match_any = [
138+
":libcxx-static-latest",
139+
":libcxx-static-19.1.7",
140+
],
141+
)
142+
143+
selects.config_setting_group(
144+
name = "libcxx-latest",
145+
match_any = [
146+
":libcxx-shared-latest",
147+
":libcxx-static-latest",
148+
],
149+
)
150+
151+
config_setting(
152+
name = "libcxx-shared-latest",
153+
flag_values = {
154+
"//:use_runtimes": "libcxx",
155+
},
156+
)
157+
158+
config_setting(
159+
name = "libcxx-static-latest",
160+
flag_values = {
161+
"//:use_runtimes": "libcxx-static",
162+
},
163+
)
164+
165+
selects.config_setting_group(
166+
name = "libcxx-19.1.7",
167+
match_any = [
168+
":libcxx-shared-19.1.7",
169+
":libcxx-static-19.1.7",
170+
],
171+
)
172+
173+
config_setting(
174+
name = "libcxx-shared-19.1.7",
175+
flag_values = {
176+
"//:use_runtimes": "libcxx-19.1.7",
177+
},
178+
)
179+
180+
config_setting(
181+
name = "libcxx-static-19.1.7",
182+
flag_values = {
183+
"//:use_runtimes": "libcxx-static-19.1.7",
184+
},
185+
)

0 commit comments

Comments
 (0)