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/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/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)) 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)