Skip to content
Open
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
33 changes: 15 additions & 18 deletions .nanvix/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from _loader import load_sibling

config = load_sibling("config", __file__)
setup_local_mod = load_sibling("setup_local", __file__)


def _workspace_id(workspace: Path) -> str:
Expand Down Expand Up @@ -282,27 +283,23 @@ def clean_volume(workspace: Path) -> None:


def _generate_setup_local_cmd() -> str:
"""Shell command to generate Modules/Setup.local inside the container."""
"""Shell command to generate Modules/Setup.local inside the container.

Rendered from .nanvix/setup_local.py (single source of truth shared
with the host build path .nanvix/lxml.py::generate_setup_local).
The rendered file body is emitted via a single ``printf '%s\\n' ...``
invocation with each line single-quoted for the container shell.
"""
sysroot = config.DOCKER_SYSROOT_PATH
ws = config.DOCKER_WORKSPACE_PATH
return (
f"printf '%s\\n' "
f"'# Auto-generated by .nanvix/docker.py -- do not edit manually.' "
f"'' "
f"'# Statically-linked extension modules for Nanvix builds.' "
f"'*static*' "
f"'# Nanvix OS interface module (snapshot, host-mount).' "
f"'_nanvix _nanvixmodule.c' "
f"'# lxml C extension modules (statically linked via pre-built archives).' "
f"'_lxml_etree lxml_etree_builtin.c -L{sysroot}/lib -llxml_etree -lxslt -lexslt -lxml2 -lz' "
f"'_lxml_elementpath lxml_elementpath_builtin.c -L{sysroot}/lib -llxml_elementpath -lxml2 -lz' "
f"'' "
f"'# Phase 0 of the .a -> .so migration: array as proof-of-concept shared module.' "
f"'# See nanvix-todo/cpython-static-to-shared-migration.md section 4.' "
f"'*shared*' "
f"'array arraymodule.c' "
f"> {ws}/Modules/Setup.local"
rendered = setup_local_mod.render_setup_local(
sysroot=str(sysroot),
header_comment="Auto-generated by .nanvix/docker.py -- do not edit manually.",
)
quoted = " ".join(
"'" + line.replace("'", "'\"'\"'") + "'" for line in rendered.split("\n")
)
return f"printf '%s\\n' {quoted} > {ws}/Modules/Setup.local"


def _inner_make_cmd(
Expand Down
32 changes: 10 additions & 22 deletions .nanvix/lxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,22 @@
from _loader import load_sibling

config = load_sibling("config", __file__)

_SETUP_LOCAL_TEMPLATE = """\
# Auto-generated by .nanvix/lxml.py -- do not edit manually.

# Statically-linked extension modules for Nanvix builds.
*static*
# Nanvix OS interface module (snapshot, host-mount).
_nanvix _nanvixmodule.c
# lxml C extension modules (statically linked via pre-built archives).
_lxml_etree lxml_etree_builtin.c -L{sysroot}/lib -llxml_etree -lxslt -lexslt -lxml2 -lz
_lxml_elementpath lxml_elementpath_builtin.c -L{sysroot}/lib -llxml_elementpath -lxml2 -lz

# Phase 0 of the .a -> .so migration: array as proof-of-concept shared module.
# See nanvix-todo/cpython-static-to-shared-migration.md section 4.
# Listed BEFORE Setup.stdlib's static declaration so makesetup's
# "first rule wins" semantics make this shared variant take precedence.
*shared*
array arraymodule.c
"""
setup_local_mod = load_sibling("setup_local", __file__)


def generate_setup_local(repo_root: Path, sysroot: Path) -> None:
"""Generate Modules/Setup.local with statically-linked module definitions.
"""Generate Modules/Setup.local from .nanvix/setup_local.py.

Includes both the _nanvix OS interface module and lxml C extensions.
Single source of truth shared with the Docker build path
(.nanvix/docker.py::_generate_setup_local_cmd). The {sysroot}
placeholder in entry tokens is substituted with the host build's
sysroot path here.
"""
setup_local = repo_root / "Modules" / "Setup.local"
content = _SETUP_LOCAL_TEMPLATE.format(sysroot=sysroot)
content = setup_local_mod.render_setup_local(
sysroot=str(sysroot),
header_comment="Auto-generated by .nanvix/lxml.py -- do not edit manually.",
)
setup_local.write_text(content, encoding="utf-8")
print(f"[lxml] Generated {setup_local}")

Expand Down
Loading