py-libzfs icon indicating copy to clipboard operation
py-libzfs copied to clipboard

configure fails to find zfs.h on Ubuntu without --prefix=/usr

Open Hi-Angel opened this issue 5 years ago • 6 comments

This is a basically a copy of #90. OP closed their report due to finding a workaround, however the problem per se remains.

Steps to reproduce

Run the following commands:

sudo apt install --yes --no-install-recommends gcc gcc-multilib libzfslinux-dev 

cd ~
git clone https://github.com/freenas/py-libzfs
cd ~/py-libzfs

./configure

Expected

configure passes successfully.

Actual

checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed

-----------------------------------
   RUNNING TESTS ON zfs.h HEADER
-----------------------------------
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for sys/types.h... (cached) yes
checking for sys/fs/zfs.h... no
configure: error: A working zfs header is required

Hi-Angel avatar Jul 07 '20 08:07 Hi-Angel

Okay, I did a quick stab at fixing this. Beforehand, the solution is to run pkg-config --cflags libzfs to infer CFLAGS.

A workaround mentioned in #90 was to set --prefix. I figured, when it's set, this branch that changes CFLAGS gets executed, so some modifications around it required.

Unfortunately I have no idea why is there even a branch matching libzfs.h specifically, nor I have any guess what the variable $zof means. All of that requires further digging and I'm out of time I could dedicate to this problem. Hopefully it will help someone.

Hi-Angel avatar Jul 07 '20 09:07 Hi-Angel

To future readers: there are further bugs in build system: if you apply the workaround with prefix, make still gonna fail with make: /usr/local/bin/python2.7: Command not found. But what's notable in this output is that apparently the bindings this project provides are for old and unmaintained python 2. So using py-libzfs is not future proof.

I've heard 0.8.x ZFS versins provide some python bindings of their own, so I think this is the way forward. For older versions apparently one have to fallback to parsing zfs commands output manually.

Hi-Angel avatar Jul 07 '20 09:07 Hi-Angel

@Hi-Angel FWIW, this is just a bug, I just tested it on Py 3.7 and it appears to work fine after modifying the Makefile to point at a py 3 venv. Probably rather than a configure script and a Makefile, the project could use setuptools-ish processes for building the extensions, just a matter of missing roundtuits likely.

mcdonc avatar Aug 10 '20 05:08 mcdonc

But what's notable in this output is that apparently the bindings this project provides are for old and unmaintained python 2. So using py-libzfs is not future proof.

You can build py-libzfs for whatever Python version you like. We are targeting 3.8 at the moment, but you can use make PYTHON=python3.7 for example to build for Python 3.7, or whatever version you have installed. Defaulting to 2.7 is probably just an oversight.

Unfortunately I have no idea why is there even a branch matching libzfs.h specifically, nor I have any guess what the variable $zof means. All of that requires further digging and I'm out of time I could dedicate to this problem. Hopefully it will help someone.

The reason for this complexity is twofold: partly that libzfs is not supposed to be a public interface in ZFS, it's an internal private library that has an unstable and unclean API; and on top of that there are several different ZFS implementations on different platforms that put headers in different places, require different build flags, and have different function signatures within libzfs. $zof is referring to https://github.com/zfsonfreebsd/ZoF

ghost avatar Aug 12 '20 14:08 ghost

I see, thanks

there are several different ZFS implementations on different platforms that put headers in different places, require different build flags

Doesn't pkg-config cover this?

Hi-Angel avatar Aug 12 '20 14:08 Hi-Angel

No, there are a few configurations where ZFS isn't a package at all, it's part of the FreeBSD base system. There is no pkg-config in that case.

ghost avatar Aug 12 '20 15:08 ghost