Skip to content
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
6 changes: 4 additions & 2 deletions .github/workflows/nanvix-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
standalone-test-args: "test-functional"
caller-event-name: ${{ github.event_name }}
windows-test: true
docker-image: "ghcr.io/nanvix/toolchain-gcc:sha-34a3641" # yamllint disable-line rule:line-length
docker-image: >-
ghcr.io/nanvix/nanvix-sdk-c-clang@sha256:f61737cb0780e6a2058c6d0bdf8ae5562db18de437173b2bcbbe6973abd3689f
secrets:
GH_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
Expand All @@ -53,7 +54,8 @@ jobs:
standalone-test-args: "test-functional"
caller-event-name: 'schedule'
windows-test: true
docker-image: "ghcr.io/nanvix/toolchain-gcc:sha-34a3641" # yamllint disable-line rule:line-length
docker-image: >-
ghcr.io/nanvix/nanvix-sdk-c-clang@sha256:f61737cb0780e6a2058c6d0bdf8ae5562db18de437173b2bcbbe6973abd3689f
secrets:
GH_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
59 changes: 37 additions & 22 deletions .nanvix/Makefile.nanvix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Some assumptions:
# 1. This makefile is expected to be invoked via z.py.
# 2. Build goals (all, install) require the cross-toolchain at
# 2. Build goals (all, install) require the Nanvix SDK at
# $(NANVIX_TOOLCHAIN); other goals (test-*, clean) are pure host-side.
# 3. Build ALWAYS runs before test and release.

Expand Down Expand Up @@ -67,11 +67,20 @@ ifneq ($(_BUILD),)
$(error Cannot mix build and non-build targets. Build targets: $(_NANVIX_DOCKER_BUILD_GOALS))
endif

ifeq ($(wildcard $(NANVIX_TOOLCHAIN)/bin/i686-nanvix-gcc),)
$(error Nanvix toolchain not found at $(NANVIX_TOOLCHAIN))
ifeq ($(wildcard $(NANVIX_TOOLCHAIN)/nanvix-sdk.json),)
$(error Nanvix SDK not found at $(NANVIX_TOOLCHAIN))
endif
ifeq ($(wildcard $(NANVIX_TOOLCHAIN)/bin/clang),)
$(error Nanvix SDK Clang not found at $(NANVIX_TOOLCHAIN)/bin/clang)
endif
endif

CC := $(NANVIX_TOOLCHAIN)/bin/clang
AR := $(NANVIX_TOOLCHAIN)/bin/llvm-ar
RANLIB := $(NANVIX_TOOLCHAIN)/bin/llvm-ranlib
NM := $(NANVIX_TOOLCHAIN)/bin/llvm-nm
STRIP := $(NANVIX_TOOLCHAIN)/bin/llvm-strip

# ===========================================================================
# Build Targets
# ===========================================================================
Expand All @@ -81,47 +90,53 @@ all: $(STATICLIB) $(TEST_ELF) install
# Stage built artifacts into the release/test output tree so that
# `./z release` (which packages release_dir()) can find them.
install: $(STATICLIB) $(TEST_ELF)
@mkdir -p $(LIB_OUT) $(INCLUDE_OUT)/libxml2/libxml $(BIN_OUT) $(TEST_OUT)
@mkdir -p $(LIB_OUT)/pkgconfig $(INCLUDE_OUT)/libxml2/libxml $(BIN_OUT) $(TEST_OUT)
cp -f $(STATICLIB) $(LIB_OUT)/
cp -f include/libxml/*.h $(INCLUDE_OUT)/libxml2/libxml/
cp -f $(TEST_ELF) $(TEST_OUT)/
@echo '#!/bin/sh' > $(BIN_OUT)/xml2-config
@echo 'case "$$1" in' >> $(BIN_OUT)/xml2-config
@echo ' --cflags) echo "-I$${NANVIX_HOME:-/mnt/sysroot}/include/libxml2" ;;' >> $(BIN_OUT)/xml2-config
@echo ' --libs) echo "-L$${NANVIX_HOME:-/mnt/sysroot}/lib -lxml2 -lz" ;;' >> $(BIN_OUT)/xml2-config
@echo ' --version) echo "2.12.9" ;;' >> $(BIN_OUT)/xml2-config
@echo 'esac' >> $(BIN_OUT)/xml2-config
@echo '#!/bin/sh' > $(BIN_OUT)/xml2-config
@echo 'prefix=$$(CDPATH= cd -- "$$(dirname -- "$$0")/.." && pwd)' >> $(BIN_OUT)/xml2-config
@echo 'case "$$1" in' >> $(BIN_OUT)/xml2-config
@echo ' --cflags) echo "-I$$prefix/include/libxml2" ;;' >> $(BIN_OUT)/xml2-config
@echo ' --libs) echo "-L$$prefix/lib -lxml2 -lz" ;;' >> $(BIN_OUT)/xml2-config
@echo ' --version) echo "2.12.9" ;;' >> $(BIN_OUT)/xml2-config
@echo 'esac' >> $(BIN_OUT)/xml2-config
Comment on lines +97 to +103
chmod +x $(BIN_OUT)/xml2-config
@echo 'prefix=$${pcfiledir}/../..' > $(LIB_OUT)/pkgconfig/libxml-2.0.pc
@echo 'libdir=$${prefix}/lib' >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc
@echo 'includedir=$${prefix}/include' >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc
Comment on lines +105 to +107
@echo >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc
@echo 'Name: libXML' >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc
@echo 'Version: 2.12.9' >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc
@echo 'Description: libXML library version2.' >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc
@echo 'Libs: -L$${libdir} -lxml2 -lz' >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc
@echo 'Cflags: -I$${includedir}/libxml2' >> $(LIB_OUT)/pkgconfig/libxml-2.0.pc

$(STATICLIB):
sh -c '\
export PATH="$(NANVIX_TOOLCHAIN)/bin:$$PATH" && \
./configure --host=i686-nanvix \
--prefix=/usr/local \
--prefix="$(BUILDROOT_PATH)" \
--enable-static --disable-shared --disable-maintainer-mode \
--without-python --without-threads --without-http --without-ftp \
--without-lzma --without-debug --without-catalog --without-readline \
--without-history --without-modules \
--with-zlib="$(BUILDROOT_PATH)" \
CC="$(CC)" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" STRIP="$(STRIP)" \
CFLAGS="-I$(BUILDROOT_PATH)/include" \
LDFLAGS="-L$(BUILDROOT_PATH)/lib" && \
LDFLAGS="-L$(BUILDROOT_PATH)/lib" \
Z_CFLAGS="-I$(BUILDROOT_PATH)/include" \
Z_LIBS="-L$(BUILDROOT_PATH)/lib -lz" && \
make -j$(NPROC) libxml2.la'

$(TEST_ELF): $(TEST_SRC)
@test -f $(STATICLIB) || { echo " FAIL: $(STATICLIB) not found; run 'build' first"; exit 1; }
$(NANVIX_TOOLCHAIN)/bin/i686-nanvix-gcc \
$(CC) \
-Iinclude -Iinclude/libxml \
$(TEST_SRC) \
-L.libs -L$(BUILDROOT_PATH)/lib -L$(SYSROOT_PATH)/lib \
-T$(SYSROOT_PATH)/lib/user.ld -static -Wl,-z,noexecstack \
-Wl,--allow-multiple-definition \
-L.libs -L$(BUILDROOT_PATH)/lib \
-Wl,-z,noexecstack \
-lxml2 -lz \
-Wl,--start-group \
$(SYSROOT_PATH)/lib/libnvx_crt0.a \
$(SYSROOT_PATH)/lib/libposix.a \
$(NANVIX_TOOLCHAIN)/i686-nanvix/lib/libc.a \
$(NANVIX_TOOLCHAIN)/i686-nanvix/lib/libm.a \
-Wl,--end-group \
-o $@

# ===========================================================================
Expand Down
4 changes: 2 additions & 2 deletions .nanvix/nanvix.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "libxml2"
version = "2.12.9"
nanvix-version = "0.17.84"
nanvix-version = "0.20.0"

[builds]
[builds.matrix]
platforms = ["hyperlight", "microvm"]
platforms = ["microvm"]
modes = ["standalone"]
memory = ["256mb"]

Expand Down
37 changes: 32 additions & 5 deletions .nanvix/z.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@

IS_WINDOWS = sys.platform == "win32"

#: Docker image for cross-compiling Nanvix targets.
NANVIX_DOCKER_IMAGE = (
"ghcr.io/nanvix/nanvix-sdk-c-clang"
"@sha256:f61737cb0780e6a2058c6d0bdf8ae5562db18de437173b2bcbbe6973abd3689f"
)

_MAKE_VAR_HOME = "NANVIX_HOME"
_MAKE_VAR_BUILDROOT = "NANVIX_BUILDROOT"
_MAKE_VAR_TOOLCHAIN = "NANVIX_TOOLCHAIN"
Expand All @@ -50,6 +56,19 @@
class Libxml2Build(ZScript):
"""Build script for nanvix/libxml2."""

# Build-time headers, libraries, startup objects, and linker scripts come
# from the SDK and buildroot. The downloaded sysroot is runtime-only.
SYSROOT_REQUIRED_FILES = (
"bin/nanvixd.elf",
"bin/kernel.elf",
"bin/mkramfs.elf",
)
SYSROOT_REQUIRED_FILES_WINDOWS = (
"bin/nanvixd.exe",
"bin/kernel.elf",
"bin/mkramfs.exe",
)

# Files produced by the cross-compile step that must be copied back
# from the container's build directory into the host workspace. The
# zutils Docker wrapper builds in a container-local scratch dir for
Expand All @@ -61,6 +80,10 @@ class Libxml2Build(ZScript):
# (see _staged_output_files()).
_BUILD_OUTPUTS: tuple[str, ...] = ("test_libxml2.elf",)

def docker_image(self) -> str:
"""Return the default Docker image for cross-compilation."""
return NANVIX_DOCKER_IMAGE

def _staged_output_files(self) -> list[str]:
"""Return install-staged artifact paths (relative to repo_root())
so Windows tar-copy mode also copies them back to the host.
Expand All @@ -74,6 +97,7 @@ def _staged_output_files(self) -> list[str]:
)
),
str((bin_out() / "xml2-config").relative_to(root)),
str((lib_out() / "pkgconfig" / "libxml-2.0.pc").relative_to(root)),
str((test_out() / "test_libxml2.elf").relative_to(root)),
]

Expand All @@ -99,12 +123,15 @@ def _make_args(self, *targets: str) -> list[str]:
def translate(p: Path):
return self.docker.translate_path(p) if self.docker else p

# Buildroot contains dependency libraries (zlib).
# Buildroot contains build-time dependency headers and libraries.
buildroot_dir = buildroot()
if buildroot_dir.is_dir():
buildroot_p = translate(buildroot_dir)
else:
buildroot_p = sysroot_p
if not buildroot_dir.is_dir():
log.fatal(
"Nanvix buildroot not found.",
code=EXIT_MISSING_DEP,
hint="Run `./z setup` first to install build dependencies.",
)
buildroot_p = translate(buildroot_dir)

args = [
"make",
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ This code is released under the MIT License, see the Copyright file.
libxml2 can be built with GNU Autotools, CMake, or several other build
systems in platform-specific subdirectories.

### Nanvix

The Nanvix port uses Clang/LLVM SDK `v0.20.0-sdk.1`, pinned to
`ghcr.io/nanvix/nanvix-sdk-c-clang@sha256:f61737cb0780e6a2058c6d0bdf8ae5562db18de437173b2bcbbe6973abd3689f`.
Run `./z setup`, `./z build`, and `./z test` to build and exercise the
microvm standalone target. The SDK supplies libc, compiler runtime, startup
objects, and linker scripts; the downloaded Nanvix sysroot supplies runtime
binaries only. zlib headers and `libz.a` are consumed from
`.nanvix/buildroot`.

Nanvix runtime `v0.20.0` supports only the microvm target at 256 MB for this
port; there are no Hyperlight or 128 MB runtime assets for this release.

### Autotools (for POSIX systems like Linux, BSD, macOS)

If you build from a Git tree, you have to install Autotools and start
Expand Down Expand Up @@ -160,4 +173,3 @@ tests if possible.
- Igor Zlatkovic for the Windows port
- Aleksey Sanin
- Nick Wellnhofer