Skip to content

Commit 453b1e3

Browse files
Enrique SaurezCopilot
andcommitted
[nanvix] E: Phase 4 — build lxml C extensions as .so
Phase 4 of the .a -> .so migration (see nanvix-todo/cpython-static-to-shared-migration.md section 8). Promotes the 2 lxml C extension modules (_lxml_etree, _lxml_elementpath) from statically linked into python.elf to dlopen-loaded shared objects. Modules moved from *static* to *shared* in Modules/Setup.local generation (.nanvix/docker.py): - _lxml_etree (links liblxml_etree.a + libxslt.a + libexslt.a + libxml2.a + libz.a from the sysroot) - _lxml_elementpath (links liblxml_elementpath.a + libxml2.a + libz.a) Both modules use the same thin-shim approach the static variant used: lxml_etree_builtin.c / lxml_elementpath_builtin.c each register the C extension's PyInit_ entrypoint after pulling in the Cython-generated implementation from liblxml_etree.a / liblxml_elementpath.a in the sysroot. The shim files are unchanged. The lxml/etree.py Python-level shim that re-exports symbols from `_lxml_etree` continues to work as-is, because Python's import system finds .cpython-312.so files in lib-dynload/ exactly like static modules — the import name `_lxml_etree` resolves either way. Same trade-off as Phase 2 and Phase 3: each .so embeds its own copy of the underlying libraries (libxslt, libexslt, libxml2, libz). _lxml_etree.so is 3645 KB primarily because libxslt and libxml2 are sizable. _lxml_elementpath.so is 175 KB because it only needs libxml2. This trade-off is tracked alongside the Phase 2 + Phase 3 bundled libs in nanvix-todo/phase2-3-unbundle-bundled-libs.md as a deferred follow-up optimization PR. Note that libz is already shared with Phase 3's zlib.so today (each carries its own copy); the same applies to libxml2 (only used by lxml; if libxml2 had to be in python.elf for other consumers we'd see the same visibility merge issue as libm, but it has no Rust compiler_builtins shadows so we're safe). Validation on local toolchain (phase0-llfix): - Both .so files produced and installed under lib-dynload/. - nm python.elf no longer shows PyInit__lxml_etree or PyInit__lxml_elementpath. - python.elf size: 11.20 MB (Phase 3) -> 8.48 MB (Phase 4), -2.72 MB. python.elf now meets the migration plan's "<=10 MB stripped" success criterion from Section 10. - Hello + all Phase 1/2/3 import probes + lxml import-and-parse smoke + HTTP server smoke + full regrtest 160/160 PASS in standalone mode. - test_nanvix_lxml (regrtest's lxml-specific test) included in the 160/160 and passes. This completes the migration plan's Phase 4 scope — only Phase 5 (optional dormant module revival for numpy / regex) remains. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3c60ab2 commit 453b1e3

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

.nanvix/docker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,15 @@ def _generate_setup_local_cmd() -> str:
293293
f"'*static*' "
294294
f"'# Nanvix OS interface module (snapshot, host-mount).' "
295295
f"'_nanvix _nanvixmodule.c' "
296-
f"'# lxml C extension modules (statically linked via pre-built archives).' "
297-
f"'_lxml_etree lxml_etree_builtin.c -L{sysroot}/lib -llxml_etree -lxslt -lexslt -lxml2 -lz' "
298-
f"'_lxml_elementpath lxml_elementpath_builtin.c -L{sysroot}/lib -llxml_elementpath -lxml2 -lz' "
299296
f"'' "
300297
f"'# Phase 0 of the .a -> .so migration: array as proof-of-concept shared module.' "
301298
f"'# See nanvix-todo/cpython-static-to-shared-migration.md section 4.' "
302299
f"'*shared*' "
303300
f"'array arraymodule.c' "
301+
f"'# Phase 4: Tier-4 third-party native .a (lxml). Each module is a' "
302+
f"'# thin shim that loads the pre-built per-module .a from sysroot.' "
303+
f"'_lxml_etree lxml_etree_builtin.c -L{sysroot}/lib -llxml_etree -lxslt -lexslt -lxml2 -lz' "
304+
f"'_lxml_elementpath lxml_elementpath_builtin.c -L{sysroot}/lib -llxml_elementpath -lxml2 -lz' "
304305
f"'# Phase 1A: Tier-1 data primitives (pure C, no external deps).' "
305306
f"'# See nanvix-todo/cpython-static-to-shared-migration.md section 5.' "
306307
f"'_bisect _bisectmodule.c' "

0 commit comments

Comments
 (0)