jamespfennell / xz

xz compression in Go
MIT License
12 stars 3 forks source link

Layout of C files breaks go mod vendor #1

Open mappu opened 11 months ago

mappu commented 11 months ago

Hi! These bindings are great, thank you for your work.

The bindings work correctly in normal go mod use.

However, when using go mod vendor, the src/ subdirectory is not copied to the vendor subdirectory, and all builds fail with:

$ go build
# github.com/jamespfennell/xz/lzma
..\..\..\..\vendor\github.com\jamespfennell\xz\lzma\lzma.go:36:10: fatal error: src/liblzma/api/lzma.h: No such file or directory
   36 | #include "src/liblzma/api/lzma.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

This is because the src subdirectories are not imported as Go packages (and you can't do so because they contain no Go files). This is a known problem for CGO and as per https://github.com/golang/go/issues/26366#issuecomment-405683150 the only fix is to restructure the source code to put C and Go files in the same directory together.

That's probably difficult if you wanted to stay up to date with any new xz-utils/liblzma releases. So, i don't expect any change really, just an FYI for you or anyone else who sees this comment in future.

jamespfennell commented 10 months ago

Thank you for the issue and the extensive and clear description!

If I'm understanding correctly, there's no simple workaround for this? In addition to all the C files being in a src directory, that directory also contains nested sub-directories like liblzma/api. To make this work with go mod vendor we'd need to flatten the whole tree entirely? I guess this would be a bit of work because all of the C #include directives would need to be changed.