Skip to content

Commit d0e06d8

Browse files
authored
Update update_libcxx.py to handle recent changes (#24392)
`update_libcxx.py` updates - Now it handles the new `llvm-libc` directory - It excludes unused `ryu_(long_double)constants.h` from libc - It deletes `libcxx/include/__cxx03` for now because we are not using it. - Make `clean_dir` and `copy_tree` handle the case when the local dir does not exist, which can happen when new directories are added - Make `copy_tree` handle removing files in `excludes` when they are in subdirectories (In libc, many `CMakeLists.txt` are in subdirectories) This also adds `readme.txt` to `llvm-libc` directory.
1 parent ad45783 commit d0e06d8

File tree

3 files changed

+68
-10
lines changed

3 files changed

+68
-10
lines changed

system/lib/llvm-libc/README.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

system/lib/llvm-libc/readme.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
llvm's libc
2+
-----------
3+
4+
These files are from llvm-project based on release 20.1.4.
5+
6+
We maintain a local fork of llvm-project that contains any emscripten
7+
specific patches:
8+
9+
https://github.com/emscripten-core/llvm-project
10+
11+
The current patch is based on the emscripten-libs-20 branch.
12+
13+
We do not use LLVM's libc directly, but libcxx uses a subset of headers from
14+
libc. So we only import these directories that libcxx depend on:
15+
- libc/hdr
16+
- libc/include/llvm-libc-macros
17+
- libc/include/llvm-libc-types
18+
- libc/shared
19+
- libc/src/__support
20+
21+
Update Instructions
22+
-------------------
23+
24+
Run `system/lib/update_libcxx.py path/to/llvm-project`
25+
26+
Modifications
27+
-------------
28+
29+
For a list of changes from upstream see the libc files that are part of:
30+
31+
https://github.com/llvm/llvm-project/compare/llvmorg-20.1.4...emscripten-core:emscripten-libs-20

system/lib/update_libcxx.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@
1515
local_src = os.path.join(local_root, 'src')
1616
local_inc = os.path.join(local_root, 'include')
1717

18-
preserve_files = ('readme.txt', 'symbols')
19-
excludes = ('CMakeLists.txt',)
18+
preserve_files = ('readme.txt', '__assertion_handler', '__config_site')
19+
# ryu_constants.h / ryu_long_double_constants.h from libc are not used
20+
excludes = ('CMakeLists.txt', 'ryu_constants.h', 'ryu_long_double_constants.h')
2021

22+
libc_copy_dirs = [
23+
('hdr',),
24+
('include', 'llvm-libc-macros'),
25+
('include', 'llvm-libc-types'),
26+
('shared',),
27+
('src', '__support'),
28+
]
2129

2230
def clean_dir(dirname):
31+
if not os.path.exists(dirname):
32+
return
2333
for f in os.listdir(dirname):
2434
if f in preserve_files:
2535
continue
@@ -31,12 +41,19 @@ def clean_dir(dirname):
3141

3242

3343
def copy_tree(upstream_dir, local_dir):
44+
if not os.path.exists(local_dir):
45+
os.makedirs(local_dir)
3446
for f in os.listdir(upstream_dir):
3547
full = os.path.join(upstream_dir, f)
3648
if os.path.isdir(full):
3749
shutil.copytree(full, os.path.join(local_dir, f))
3850
elif f not in excludes:
3951
shutil.copy2(full, os.path.join(local_dir, f))
52+
for root, dirs, files in os.walk(local_dir):
53+
for f in files:
54+
if f in excludes:
55+
full = os.path.join(root, f)
56+
os.remove(full)
4057

4158

4259
def main():
@@ -60,6 +77,24 @@ def main():
6077
shutil.copy2(os.path.join(libcxx_dir, 'CREDITS.TXT'), local_root)
6178
shutil.copy2(os.path.join(libcxx_dir, 'LICENSE.TXT'), local_root)
6279

80+
# We don't use frozen c++03 headers for now
81+
shutil.rmtree(os.path.join(local_inc, '__cxx03'))
82+
83+
# libcxx includes headers from LLVM's libc
84+
libc_upstream_dir = os.path.join(llvm_dir, 'libc')
85+
assert os.path.exists(libc_upstream_dir)
86+
libc_local_dir = os.path.join(script_dir, 'llvm-libc')
87+
88+
for dirname in libc_copy_dirs:
89+
local_dir = os.path.join(libc_local_dir, *dirname)
90+
clean_dir(local_dir)
91+
92+
for dirname in libc_copy_dirs:
93+
upstream_dir = os.path.join(libc_upstream_dir, *dirname)
94+
local_dir = os.path.join(libc_local_dir, *dirname)
95+
copy_tree(upstream_dir, local_dir)
96+
97+
shutil.copy2(os.path.join(libc_upstream_dir, 'LICENSE.TXT'), libc_local_dir)
6398

6499
if __name__ == '__main__':
65100
main()

0 commit comments

Comments
 (0)