Skip to content

Update update_libcxx.py to handle recent changes #24392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions system/lib/llvm-libc/README.txt

This file was deleted.

31 changes: 31 additions & 0 deletions system/lib/llvm-libc/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
llvm's libc
-----------

These files are from llvm-project based on release 20.1.4.

We maintain a local fork of llvm-project that contains any emscripten
specific patches:

https://github.com/emscripten-core/llvm-project

The current patch is based on the emscripten-libs-20 branch.

We do not use LLVM's libc directly, but libcxx uses a subset of headers from
libc. So we only import these directories that libcxx depend on:
- libc/hdr
- libc/include/llvm-libc-macros
- libc/include/llvm-libc-types
- libc/shared
- libc/src/__support

Update Instructions
-------------------

Run `system/lib/update_libcxx.py path/to/llvm-project`

Modifications
-------------

For a list of changes from upstream see the libc files that are part of:

https://github.com/llvm/llvm-project/compare/llvmorg-20.1.4...emscripten-core:emscripten-libs-20
39 changes: 37 additions & 2 deletions system/lib/update_libcxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@
local_src = os.path.join(local_root, 'src')
local_inc = os.path.join(local_root, 'include')

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

libc_copy_dirs = [
('hdr',),
('include', 'llvm-libc-macros'),
('include', 'llvm-libc-types'),
('shared',),
('src', '__support'),
]

def clean_dir(dirname):
if not os.path.exists(dirname):
return
for f in os.listdir(dirname):
if f in preserve_files:
continue
Expand All @@ -31,12 +41,19 @@ def clean_dir(dirname):


def copy_tree(upstream_dir, local_dir):
if not os.path.exists(local_dir):
os.makedirs(local_dir)
for f in os.listdir(upstream_dir):
full = os.path.join(upstream_dir, f)
if os.path.isdir(full):
shutil.copytree(full, os.path.join(local_dir, f))
elif f not in excludes:
shutil.copy2(full, os.path.join(local_dir, f))
for root, dirs, files in os.walk(local_dir):
for f in files:
if f in excludes:
full = os.path.join(root, f)
os.remove(full)


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

# We don't use frozen c++03 headers for now
shutil.rmtree(os.path.join(local_inc, '__cxx03'))

# libcxx includes headers from LLVM's libc
libc_upstream_dir = os.path.join(llvm_dir, 'libc')
assert os.path.exists(libc_upstream_dir)
libc_local_dir = os.path.join(script_dir, 'llvm-libc')

for dirname in libc_copy_dirs:
local_dir = os.path.join(libc_local_dir, *dirname)
clean_dir(local_dir)

for dirname in libc_copy_dirs:
upstream_dir = os.path.join(libc_upstream_dir, *dirname)
local_dir = os.path.join(libc_local_dir, *dirname)
copy_tree(upstream_dir, local_dir)

shutil.copy2(os.path.join(libc_upstream_dir, 'LICENSE.TXT'), libc_local_dir)

if __name__ == '__main__':
main()