rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.64k stars 380 forks source link

Fails to build on recent glibc due to regexp.h #993

Closed MagicalTux closed 9 months ago

MagicalTux commented 9 months ago

Trying to compile rust itself and it looks like export LIBGIT2_NO_VENDOR=1 does nothing, the build fails with:

[libgit2-sys 0.15.2+1.6.4] 
[libgit2-sys 0.15.2+1.6.4] error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-unknown-linux-gnu" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-unknown-linux-gnu" "-fdebug-prefix-map=/build/rust-1.72.1/work/rustc-1.72.1-src=/rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3" "-I" "/build/rust-1.72.1/work/rustc-1.72.1-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/libgit2-sys-6f23acf57ee0573c/out/include" "-I" "libgit2/src/libgit2" "-I" "libgit2/src/util" "-I" "libgit2/deps/http-parser" "-I" "libgit2/deps/pcre" "-I" "/build/rust-1.72.1/work/rustc-1.72.1-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/libssh2-sys-ababd43135a20e64/out/include" "-I" "/pkg/main/dev-libs.openssl.core.3.1.2.linux.amd64/include" "-I" "/pkg/main/sys-libs.zlib.core.1.2.13.linux.amd64/include" "-fvisibility=hidden" "-DGIT_REGEX_BUILTIN=1" "-DHAVE_STDINT_H=1" "-DHAVE_MEMMOVE=1" "-DNO_RECURSE=1" "-DNEWLINE=10" "-DPOSIX_MALLOC_THRESHOLD=10" "-DLINK_SIZE=2" "-DPARENS_NEST_LIMIT=250" "-DMATCH_LIMIT=10000000" "-DMATCH_LIMIT_RECURSION=MATCH_LIMIT" "-DMAX_NAME_SIZE=32" "-DMAX_NAME_COUNT=10000" "-DSHA1DC_NO_STANDARD_INCLUDES=1" "-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\"" "-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\"" "-o" "/build/rust-1.72.1/work/rustc-1.72.1-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/libgit2-sys-6f23acf57ee0573c/out/build/libgit2/src/libgit2/blame_git.o" "-c" "libgit2/src/libgit2/blame_git.c" with args "clang" did not execute successfully (status code exit status: 1).
[libgit2-sys 0.15.2+1.6.4] 
[libgit2-sys 0.15.2+1.6.4] 
The following warnings were emitted during compilation:

warning: In file included from libgit2/src/libgit2/blame_git.c:12:
warning: In file included from libgit2/src/libgit2/xdiff/xinclude.h:26:
warning: In file included from libgit2/src/libgit2/xdiff/git-xdiff.h:17:
warning: /pkg/main/sys-libs.glibc.dev.linux.amd64/include/regexp.h:29:2: error: "The GNU C Library no longer implements <regexp.h>."
warning: #error "The GNU C Library no longer implements <regexp.h>."
warning:  ^
warning: /pkg/main/sys-libs.glibc.dev.linux.amd64/include/regexp.h:30:2: error: "Please update your code to use <regex.h> instead (no trailing 'p')."
warning: #error "Please update your code to use <regex.h> instead (no trailing 'p')."
warning:  ^
warning: In file included from libgit2/src/libgit2/blame_git.c:12:
warning: In file included from libgit2/src/libgit2/xdiff/xinclude.h:26:
warning: libgit2/src/libgit2/xdiff/git-xdiff.h:40:8: error: unknown type name 'git_regexp'
warning:         const xdl_regex_t *preg, const char *buf, size_t size,
warning:               ^
warning: libgit2/src/libgit2/xdiff/git-xdiff.h:36:21: note: expanded from macro 'xdl_regex_t'
warning: #define xdl_regex_t git_regexp
warning:                     ^
warning: libgit2/src/libgit2/xdiff/git-xdiff.h:41:17: error: unknown type name 'git_regmatch'
warning:         size_t nmatch, xdl_regmatch_t pmatch[], int eflags)
warning:                        ^
warning: libgit2/src/libgit2/xdiff/git-xdiff.h:37:24: note: expanded from macro 'xdl_regmatch_t'
warning: #define xdl_regmatch_t git_regmatch
warning:                        ^
warning: In file included from libgit2/src/libgit2/blame_git.c:12:
warning: In file included from libgit2/src/libgit2/xdiff/xinclude.h:28:
warning: libgit2/src/libgit2/xdiff/xdiff.h:87:2: error: unknown type name 'git_regexp'
warning:         xdl_regex_t **ignore_regex;
warning:         ^
warning: libgit2/src/libgit2/xdiff/git-xdiff.h:36:21: note: expanded from macro 'xdl_regex_t'
warning: #define xdl_regex_t git_regexp
warning:                     ^
warning: 5 errors generated.

error: failed to run custom build command for `libgit2-sys v0.15.2+1.6.4`

How can this be solved? I'm guessing newer version of libgit2 would help, or alternatively using system libgit2, however it looks like running x.py build somehow always attempts to build libgit2.

ehuss commented 9 months ago

It looks like possibly an issue with the include paths. Is there something adding /pkg/main/sys-libs.glibc.dev.linux.amd64/include to the search path? Can you provide a complete reproduction, including the system you are running on, the environment, the config.toml build settings, etc.?

MagicalTux commented 9 months ago

OK so the issue is that glibc is in normal includes instead of being in system includes. Thanks, this actually helps a lot and confirms this isn't an issue with this package (I'm still not sure why LIBGIT2_NO_VENDOR=1 has no effect but I guess that's something inside rust's build process) so I'll be closing this issue (sorry for this and thank you, I've been trying to get rust to build for more than a year now and I was blanking on this specific issue).