Skip to content

Commit 8615d82

Browse files
authored
[librt] Move librt submodule files to dedicated subdirectories (#20629)
Now all .c and .h files for `librt.base64` live under `mypyc/lib-rt/base64`, for example. This makes the structure easier to follow, since now the files for each submodule are in a dedicated directory. I'm planning to add some additional submodules soon, some of which have multiple files, so I think it makes sense to restructure now. The extra ops files are still in the top-level `mypyc/lib-rt` directory, since they are linked to mypyc-compiled libraries instead of `librt` proper. We can revisit this later; I'm not sure what's the best approach. I did this with claude code.
1 parent 61b3b5d commit 8615d82

File tree

12 files changed

+14
-14
lines changed

12 files changed

+14
-14
lines changed

mypy/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
This module contains high-level logic for fixed format serialization.
33
4-
Lower-level parts are implemented in C in mypyc/lib-rt/librt_internal.c
4+
Lower-level parts are implemented in C in mypyc/lib-rt/internal/librt_internal.c
55
Short summary of low-level functionality:
66
* integers are automatically serialized as 1, 2, or 4 bytes, or arbitrary length.
77
* str/bytes are serialized as size (1, 2, or 4 bytes) followed by bytes buffer.

mypyc/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ class ModDesc(NamedTuple):
5353

5454

5555
LIBRT_MODULES = [
56-
ModDesc("librt.internal", ["librt_internal.c"], [], []),
57-
ModDesc("librt.strings", ["librt_strings.c"], [], []),
56+
ModDesc("librt.internal", ["internal/librt_internal.c"], [], ["internal"]),
57+
ModDesc("librt.strings", ["strings/librt_strings.c"], [], ["strings"]),
5858
ModDesc(
5959
"librt.base64",
6060
[
61-
"librt_base64.c",
61+
"base64/librt_base64.c",
6262
"base64/lib.c",
6363
"base64/codec_choose.c",
6464
"base64/tables/tables.c",

mypyc/codegen/emitmodule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,11 @@ def generate_c_for_modules(self) -> list[tuple[str, str]]:
625625
ext_declarations.emit_line("#include <Python.h>")
626626
ext_declarations.emit_line("#include <CPy.h>")
627627
if self.compiler_options.depends_on_librt_internal:
628-
ext_declarations.emit_line("#include <librt_internal.h>")
628+
ext_declarations.emit_line("#include <internal/librt_internal.h>")
629629
if any(LIBRT_BASE64 in mod.dependencies for mod in self.modules.values()):
630-
ext_declarations.emit_line("#include <librt_base64.h>")
630+
ext_declarations.emit_line("#include <base64/librt_base64.h>")
631631
if any(LIBRT_STRINGS in mod.dependencies for mod in self.modules.values()):
632-
ext_declarations.emit_line("#include <librt_strings.h>")
632+
ext_declarations.emit_line("#include <strings/librt_strings.h>")
633633
# Include headers for conditional source files
634634
source_deps = collect_source_dependencies(self.modules)
635635
for source_dep in sorted(source_deps, key=lambda d: d.path):

mypyc/lib-rt/byteswriter_extra_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdint.h>
77
#include <Python.h>
88

9-
#include "librt_strings.h"
9+
#include "strings/librt_strings.h"
1010

1111
static inline CPyTagged
1212
CPyBytesWriter_Len(PyObject *obj) {

mypyc/lib-rt/setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,33 +89,33 @@ def run(self) -> None:
8989
Extension(
9090
"librt.internal",
9191
[
92-
"librt_internal.c",
92+
"internal/librt_internal.c",
9393
"init.c",
9494
"int_ops.c",
9595
"exc_ops.c",
9696
"pythonsupport.c",
9797
"getargsfast.c",
9898
],
99-
include_dirs=["."],
99+
include_dirs=[".", "internal"],
100100
extra_compile_args=cflags,
101101
),
102102
Extension(
103103
"librt.strings",
104104
[
105-
"librt_strings.c",
105+
"strings/librt_strings.c",
106106
"init.c",
107107
"int_ops.c",
108108
"exc_ops.c",
109109
"pythonsupport.c",
110110
"getargsfast.c",
111111
],
112-
include_dirs=["."],
112+
include_dirs=[".", "strings"],
113113
extra_compile_args=cflags,
114114
),
115115
Extension(
116116
"librt.base64",
117117
[
118-
"librt_base64.c",
118+
"base64/librt_base64.c",
119119
"base64/lib.c",
120120
"base64/codec_choose.c",
121121
"base64/tables/tables.c",

0 commit comments

Comments
 (0)