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
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Vendored Unix shell / autotools scripts must keep LF line endings so
# the build runs inside the Linux toolchain container regardless of a
# contributor's git `core.autocrlf` setting. Windows checkouts with
# autocrlf=true otherwise rewrite these to CRLF, which dash rejects
# ("Syntax error: newline unexpected" inside case/esac).
configure text eol=lf
config.guess text eol=lf
config.sub text eol=lf
install-sh text eol=lf
depcomp text eol=lf
missing text eol=lf
compile text eol=lf
ar-lib text eol=lf
ltmain.sh text eol=lf
test-driver text eol=lf
*.sh text eol=lf
build-aux/* text eol=lf
33 changes: 28 additions & 5 deletions .nanvix/z.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _configure_env_overrides(self) -> dict[str, str]:
"RANLIB": f"{bin_}/i686-nanvix-ranlib",
"STRIP": f"{bin_}/i686-nanvix-strip",
"NM": f"{bin_}/i686-nanvix-nm",
"CFLAGS": f"-O2 -D_GNU_SOURCE -I{sysroot}/include",
"CFLAGS": f"-O2 -fPIC -D_GNU_SOURCE -I{sysroot}/include",
"CPPFLAGS": f"-D_GNU_SOURCE -I{sysroot}/include",
"LDFLAGS": (
f"-static -T{sysroot}/lib/user.ld -L{sysroot}/lib "
Expand Down Expand Up @@ -316,13 +316,33 @@ def build(self) -> None:
tests_targets = " ".join(_UPSTREAM_TEST_NAMES)

# Single shell script: configure -> make -> install ->
# tests-build -> copy test ELFs out to the mounted workspace.
# liblzma.so -> tests-build -> copy test ELFs out to the mounted
# workspace.
#
# liblzma.so is linked from the (now PIC) static archive via
# --whole-archive so every liblzma entry point becomes part of
# the .so's .dynsym. DT_SONAME=liblzma.so so consumers that link
# against it emit a proper DT_NEEDED entry. libc / libm symbols
# (memcpy, memset, malloc, ...) are left UND via -nostdlib and
# bind at dlopen time against the host executable's .dynsym,
# the same model already used by other Nanvix shared libraries
# such as libffi.so / libssl.so.
cc = overrides["CC"]
script = "\n".join(
[
"set -e",
configure_cmd,
Comment on lines 333 to 334
f"make -j{nproc}",
f"make install DESTDIR={shlex.quote(str(stage_container))}",
# Build liblzma.so from the (PIC) liblzma.a libtool produced.
# libtool's shared-library detection does not know about
# i686-nanvix (hence --disable-shared in configure opts),
# so we link the .so ourselves and stage it next to .a.
f"{shlex.quote(cc)} -shared -fPIC -nostdlib "
f" -Wl,-soname,liblzma.so -Wl,-z,noexecstack"
f" -Wl,--whole-archive src/liblzma/.libs/liblzma.a"
f" -Wl,--no-whole-archive"
f" -o {shlex.quote(str(stage_container))}/sysroot/lib/liblzma.so",
(
"make -C tests "
f"LDFLAGS={shlex.quote(tests_ldflags)} "
Expand Down Expand Up @@ -390,19 +410,21 @@ def _stage_artefacts(self) -> None:
)

# Clear any prior staged outputs but keep _install/ in place.
for name in ("liblzma.a", "include", "lib"):
for name in ("liblzma.a", "liblzma.so", "include", "lib"):
target = build_dir / name
if target.is_dir():
shutil.rmtree(target)
elif target.exists():
target.unlink()

# liblzma.a → build/liblzma.a (and also build/lib/liblzma.a for
# the release packaging step in a later commit).
# liblzma.a / liblzma.so → build/liblzma.{a,so} and also
# build/lib/liblzma.{a,so} for the release packaging step.
lib_dir = build_dir / "lib"
lib_dir.mkdir(parents=True, exist_ok=True)
shutil.copy2(src_root / "lib" / "liblzma.a", lib_dir / "liblzma.a")
shutil.copy2(src_root / "lib" / "liblzma.a", build_dir / "liblzma.a")
shutil.copy2(src_root / "lib" / "liblzma.so", lib_dir / "liblzma.so")
shutil.copy2(src_root / "lib" / "liblzma.so", build_dir / "liblzma.so")

# liblzma.pc → build/lib/pkgconfig/liblzma.pc
pc_src = src_root / "lib" / "pkgconfig" / "liblzma.pc"
Expand Down Expand Up @@ -445,6 +467,7 @@ def _stage_release_outputs(self) -> None:
tst_o.mkdir(parents=True, exist_ok=True)

shutil.copy2(lib_dir / "liblzma.a", lib_o / "liblzma.a")
shutil.copy2(lib_dir / "liblzma.so", lib_o / "liblzma.so")
shutil.copy2(
lib_dir / "pkgconfig" / "liblzma.pc",
lib_o / "pkgconfig" / "liblzma.pc",
Expand Down
Loading