Skip to content

Commit 4dc532e

Browse files
committed
Get glibc building
Currently only shared is building. getting a relocation error when trying to statically link :/ Also had to update the llvm tar to contain the clang headers now that I know they're used for defining toolchain specific stuff.
1 parent 0e88b63 commit 4dc532e

File tree

15 files changed

+451
-5
lines changed

15 files changed

+451
-5
lines changed

.bazelignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
examples
1+
examples
2+
repo_gen

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
bazel-*
1+
bazel-*
2+
examples/hello_world/MODULE.bazel.lock

MODULE.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "ht
1313
http_archive(
1414
name = "llvm-19.1.7-linux-x86_64",
1515
url = "https://github.com/reutermj/toolchains_cc/releases/download/binaries/llvm-19.1.7-linux-x86_64.tar.xz",
16-
sha256 = "ac027eb9f1cde6364d063fe91bd299937eb03b8d906f7ddde639cf65b4872cb3",
16+
sha256 = "2dc7c2d6804eb5cd139f63e03f9e9c1c7ccef2494f71d71995758f5ea58e70c1",
1717
)
1818
http_archive(
1919
name = "musl-1.2.5-linux-x86_64",
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 = "glibc-2.27-linux-x86_64",
25+
url = "https://github.com/reutermj/toolchains_cc/releases/download/binaries/glibc-2.27-linux-x86_64.tar.xz",
26+
sha256 = "94c2e1cf2396b87b4f714995a8c5d2b8f6744219cadb0b81df486092e97b17e4",
27+
)
2328
http_archive(
2429
name = "libcxx-19.1.7-linux-x86_64",
2530
url = "https://github.com/reutermj/toolchains_cc/releases/download/binaries/libcxx-19.1.7-linux-x86_64.tar.xz",

Notes.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Notes on the implementation
22

3+
## Useful links
4+
5+
### Alpine Packages
6+
downloading: https://dl-cdn.alpinelinux.org/alpine/
7+
searching: https://pkgs.alpinelinux.org/packages
8+
Build scripts: https://gitlab.alpinelinux.org/alpine/aports
9+
10+
## TODO
11+
12+
`platform_data` might allow for changing the toolchain for different targets. need to investigate
13+
14+
https://github.com/bazelbuild/rules_platform/blob/main/platform_data/defs.bzl
315

416
## libc++
517

@@ -16,3 +28,13 @@ You need to get a version of libc++ specifically compiled for musl. When configu
1628
```
1729

1830
reference: https://github.com/dslm4515/CMLFS/issues/69
31+
32+
### TODO
33+
34+
figure out why I need to link lzma? I dont think I actually want this to be part of the general musl build flow
35+
36+
## Toolchains
37+
38+
toolchains contain specific definitions for things like `stddef.h`. glibc relies on these to be there but it appears that musl doesnt?
39+
40+
either way, need to look into include path ordering to make sure im getting it in the right order.

repo_gen/generate_repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,5 @@ def generate_build_files(dir, actions):
545545
"link_data",
546546
"objcopy_embed_data",
547547
"strip",
548+
"include",
548549
])

repo_gen/runtimes.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,74 @@
6666
]
6767
}
6868
},
69+
{
70+
"name": "glibc",
71+
"default-version": "2.27",
72+
"versions": [
73+
{
74+
"version": "2.27",
75+
"oses": [
76+
{
77+
"name": "linux",
78+
"archs": [
79+
{
80+
"name": "x86_64",
81+
"artifact-name": "glibc-2.27-linux-x86_64.tar.xz",
82+
"sha256": "94c2e1cf2396b87b4f714995a8c5d2b8f6744219cadb0b81df486092e97b17e4"
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+
"-fuse-ld=lld",
99+
"-lc",
100+
"{lib}/libc_nonshared.a"
101+
]
102+
},
103+
{
104+
"name": "link_executable_actions",
105+
"args": [
106+
"{lib}/crt1.o",
107+
"{lib}/crti.o",
108+
"{lib}/crtn.o"
109+
]
110+
}
111+
]
112+
},
113+
{
114+
"name": "static",
115+
"actions": [
116+
{
117+
"name": "link_actions",
118+
"args": [
119+
"-fuse-ld=lld",
120+
"{lib}/libc.a",
121+
"{lib}/libc_nonshared.a"
122+
]
123+
},
124+
{
125+
"name": "link_executable_actions",
126+
"args": [
127+
"{lib}/crt1.o",
128+
"{lib}/crti.o",
129+
"{lib}/crtn.o"
130+
]
131+
}
132+
]
133+
}
134+
]
135+
}
136+
},
69137
{
70138
"name": "libcxx",
71139
"default-version": "19.1.7",

repo_gen/runtimes/BUILD

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
load("@bazel_skylib//rules/directory:directory.bzl", "directory")
2+
load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
3+
4+
filegroup(
5+
name = "all-files",
6+
srcs = glob(["**"]),
7+
)
8+
9+
directory(
10+
name = "root",
11+
srcs = [":all-files"],
12+
visibility = ["//visibility:public"],
13+
)
14+
15+
subdirectory(
16+
name = "include",
17+
parent = ":root",
18+
path = "include",
19+
visibility = ["//visibility:public"],
20+
)
21+
22+
subdirectory(
23+
name = "lib",
24+
parent = ":root",
25+
path = "lib",
26+
visibility = ["//visibility:public"],
27+
)

repo_gen/toolchain.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{
1313
"name": "x86_64",
1414
"artifact-name": "llvm-19.1.7-linux-x86_64.tar.xz",
15-
"sha256": "ac027eb9f1cde6364d063fe91bd299937eb03b8d906f7ddde639cf65b4872cb3"
15+
"sha256": "2dc7c2d6804eb5cd139f63e03f9e9c1c7ccef2494f71d71995758f5ea58e70c1"
1616
}
1717
]
1818
}

repo_gen/toolchain/BUILD

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
load("@bazel_skylib//rules/directory:directory.bzl", "directory")
2+
load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
filegroup(
7+
name = "all-files",
8+
srcs = glob(["**"]),
9+
)
10+
11+
directory(
12+
name = "root",
13+
srcs = [":all-files"],
14+
visibility = ["//visibility:public"],
15+
)
16+
17+
subdirectory(
18+
name = "include",
19+
parent = ":root",
20+
path = "include",
21+
visibility = ["//visibility:public"],
22+
)
23+
24+
alias(
25+
name = "ar_actions",
26+
actual = ":llvm-ar",
27+
)
28+
29+
alias(
30+
name = "assembly_actions",
31+
actual = ":clang++",
32+
)
33+
34+
alias(
35+
name = "c_compile",
36+
actual = ":clang",
37+
)
38+
39+
alias(
40+
name = "cpp_compile_actions",
41+
actual = ":clang++",
42+
)
43+
44+
alias(
45+
name = "link_actions",
46+
actual = ":clang++",
47+
)
48+
49+
filegroup(
50+
name = "link_data",
51+
srcs = [
52+
":ld.lld",
53+
":ld64.lld",
54+
":lld",
55+
":lld-link",
56+
],
57+
)
58+
59+
alias(
60+
name = "objcopy_embed_data",
61+
actual = ":llvm-objcopy",
62+
)
63+
64+
alias(
65+
name = "strip",
66+
actual = ":llvm-strip",
67+
)

repo_gen/toolchain/BUILD.tpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,28 @@ cc_args_list(
1212
":llvm-c_compile",
1313
":llvm-cpp_compile_actions",
1414
":llvm-link_actions",
15+
":arg-include",
1516
],
1617
"//conditions:default": [],
1718
}}),
1819
visibility = ["//toolchain:__pkg__"],
1920
)
2021

22+
cc_args(
23+
name = "arg-include",
24+
actions = [
25+
"@rules_cc//cc/toolchains/actions:c_compile",
26+
"@rules_cc//cc/toolchains/actions:cpp_compile_actions",
27+
],
28+
args = [
29+
"-isystem",
30+
"{{include}}",
31+
],
32+
data = [
33+
":include",
34+
],
35+
format = {{
36+
"include": ":include",
37+
}},
38+
)
39+

0 commit comments

Comments
 (0)