From 4ccfb1d2269c23945d58e3a499057bbf0091cbe9 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 12 Nov 2026 09:30:53 +0100 Subject: [PATCH 1/2] Drop the unused libnsl dependency from the bundled Xerces The bundled libxerces-c needs libnsl.so.2 but imports none of its symbols. Ubuntu 24.04 doesn't install libnsl2 by default, so import failed there until users installed it. The build now removes that DT_NEEDED entry with patchelf, and CI no longer installs libnsl2, so the tests prove the wheel works without it. Fixes #59 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build_package.yml | 5 ----- .github/workflows/full_test.yml | 7 ------- .github/workflows/test_mikeio.yml | 6 ------ CHANGELOG.md | 4 ++++ buildUtil/build.py | 11 +++++++++-- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml index d5f3956..1c1546a 100644 --- a/.github/workflows/build_package.yml +++ b/.github/workflows/build_package.yml @@ -25,11 +25,6 @@ jobs: with: version: "0.7.21" - - name: Install libnsl2 - run: | - sudo apt-get update - sudo apt-get install -y libnsl2 - - name: Build package run: uv build --wheel diff --git a/.github/workflows/full_test.yml b/.github/workflows/full_test.yml index 3f397aa..7b0d86b 100644 --- a/.github/workflows/full_test.yml +++ b/.github/workflows/full_test.yml @@ -30,13 +30,6 @@ jobs: with: python-version: ${{ matrix.python-version }} - # this is installed by default on Ubuntu 22.04 - - name: Install libnsl2 (Linux only) - if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y libnsl2 - - name: Install the project run: uv sync diff --git a/.github/workflows/test_mikeio.yml b/.github/workflows/test_mikeio.yml index 957972c..e9718ee 100644 --- a/.github/workflows/test_mikeio.yml +++ b/.github/workflows/test_mikeio.yml @@ -40,12 +40,6 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install libnsl2 (Linux only) - if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y libnsl2 - - name: Install MIKE IO working-directory: mikeio run: uv sync --group test --no-dev diff --git a/CHANGELOG.md b/CHANGELOG.md index 69eaeed..dc31765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- On Linux, mikecore no longer needs `libnsl2` installed, which Ubuntu 24.04 + doesn't install by default. The bundled Xerces library was linked against it + without using it + ([#59](https://github.com/DHI/mikecore-python/issues/59)). - `DfsuFile` opens dfsu files from MIKE 2027 with a submesh type, such as 3D files and locally refined meshes, which raised "not a valid dfsu file". Files from later MIKE versions with more custom block values also open. diff --git a/buildUtil/build.py b/buildUtil/build.py index 5341ca7..15be87d 100644 --- a/buildUtil/build.py +++ b/buildUtil/build.py @@ -98,6 +98,10 @@ def read_packages_config(filepath: str | Path) -> tuple[str, list[tuple[str, str # patching their imports would invalidate DHI's signature (ADR 0002). LIB_TAG = "-mikecore-python" +# Linked but unused: Xerces imports no symbols from libnsl, and Ubuntu 24.04 +# doesn't install it by default (#59). +UNUSED_NEEDED = ["libnsl.so.2"] + def tagged(name: str) -> str: """libintlc.so.5 -> libintlc-mikecore-python.so.5""" @@ -105,8 +109,9 @@ def tagged(name: str) -> str: def isolate_linux_libs(bin_folder: str | Path): - """Unique names (#45), and DT_RPATH rather than DT_RUNPATH so - LD_LIBRARY_PATH can't override $ORIGIN.""" + """Unique names (#45), DT_RPATH rather than DT_RUNPATH so + LD_LIBRARY_PATH can't override $ORIGIN, and no unused system + dependencies (#59).""" patchelf_path = shutil.which("patchelf") libs = list(Path(bin_folder).glob("*.so*")) renames = {so.name: tagged(so.name) for so in libs} @@ -123,6 +128,8 @@ def isolate_linux_libs(bin_folder: str | Path): ] for old, new in renames.items(): args += ["--replace-needed", old, new] + for name in UNUSED_NEEDED: + args += ["--remove-needed", name] subprocess.run(args + [str(so.absolute())], check=True) so.replace(so.with_name(new_name)) From 397ef14dac15f73cede3230922628758b1c48f89 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 12 Nov 2026 09:46:33 +0100 Subject: [PATCH 2/2] Skip the installation-bin test when libnsl2 is missing The test stands in for a MIKE installation with the unpatched NuGet libraries, whose Xerces still needs libnsl.so.2. Without libnsl2 it can't load, as on ubuntu-latest now that CI no longer installs it. The README says such an installation may need libnsl2 on Ubuntu 24.04. Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +++-- tests/test_installation_bin.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c1ad00..2718b23 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,9 @@ installed. With another library in the process that loads MIKE Core To share one set instead, set `MIKECORE_PYTHON_BIN` to the installation's `bin` folder (on Windows, the 64-bit `bin\x64`) before mikecore is first imported. On -Linux, you may also need that folder on `LD_LIBRARY_PATH`. mikecore is only -tested with its bundled libraries. +Linux, you may also need that folder on `LD_LIBRARY_PATH`, and on Ubuntu 24.04 +the installation's libraries may need `sudo apt install libnsl2`. mikecore is +only tested with its bundled libraries. Either way, mikecore's EUM items and units match the bundled version. With MIKE Core from a newer version, EUM lookups can raise `ValueError` diff --git a/tests/test_installation_bin.py b/tests/test_installation_bin.py index 40a641a..26489de 100644 --- a/tests/test_installation_bin.py +++ b/tests/test_installation_bin.py @@ -1,3 +1,4 @@ +import ctypes import os import shutil import subprocess @@ -47,11 +48,23 @@ def installation_bin(tmp_path: Path) -> Path: natives = list(PACKAGES.glob(f"*/runtimes/{RUNTIME}/native")) if not natives: pytest.skip("needs the NuGet packages that building a checkout downloads") + if os.name != "nt" and not loadable("libnsl.so.2"): + # The bundled copy has this dependency removed (#59); an + # installation's Xerces still has it. + pytest.skip("the installation's Xerces needs libnsl2") for native in natives: shutil.copytree(native, tmp_path, dirs_exist_ok=True) return tmp_path +def loadable(library: str) -> bool: + try: + ctypes.CDLL(library) + except OSError: + return False + return True + + def test_installation_libraries_read_like_the_bundled_ones(installation_bin): mikebin, *results = run_read(installation_bin)